[CMake] How to override flags for a single target

Tony Bridges nabridges at gmail.com
Sun Mar 7 18:02:04 EST 2010


Hello all,

I'm hopeful that someone can point me in the correct direction to solve a
problem I'm having setting up arguments into the resource compiler.

I am attempting to add a custom rule to a CMakeLists.txt file to allow me to
set a specific flag for one file in the SOURCES list.  I'm assuming the
correct approach here is to create a custom command and specify the
particular flag I want on the command line, but I can't make it work.

project (cm_BBS)
...
set (SOURCES ... BBS.rc)
...
add_custom_command( OUTPUT ${PROJECT_BINARY_DIR}/cm_BBS.res
                    DEPENDS BBS.rc
                     COMMAND ${CMAKE_RC_COMPILER} ${CMAKE_CXX_FLAGS}
-D__USER__=\"$(username)\"
)


to replace the behavior of the generated rule from the SOURCES line.
cmake completely ignores this and uses the default rule.

When I attempt removing the RC file from the SOURCES list, then no rule is
generated.
And I'm unclear on how to add a dependency that is not a top level
dependency to the project using add_dependencies.  add_executable takes
SOURCES; do these automatically bind to their generated outputs ? If so,
that might be the key.

The only solution other that comes to mind is to move this source file into
a separate directory and mod the CXX_FLAGS in isolation, but that's really a
hack and would mess up my perforce merges.

Can someone tell me the right way to approach this ?

As a side note, there's an interesting observation here.  When I check the
generated output for the resource compiler, the output file is cm_BBS.res,
even though the input file is BBS.rc, so the resource compiler generation
seems to be picking up the project name rather than the actual source file
name.  ( I tried it both ways in the custom rule; neither worked.)

ALl this is necessary because, I cannot affect the CMAKE_RC_FLAGS
independently from the CMAKE_CXX_FLAGS.  What works for the compiler (wrt
quotes) breaks the RC.  Setting CMAKE_RC_FLAGS, which is all I really need
to do, has no impact at all on the build; it is ignored.  issue #10119.
Also, note that the generated CmakeCache.txt file labels the CMAKE_RC_FLAGS
as a Fortran field, so the generated comment is misplaced.

If anyone can offer me the benefit of their experience here, I'd greatly
appreciate it.

My configuration : generating for VS 2005 from cmake 2.8, generated from the
2.8.0 source distro, with the MIDL quoting patch applied.

cheers
/t
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100307/39fc5e2d/attachment.htm>


More information about the CMake mailing list