[CMake] How to override flags for a single target

J Decker d3ck0r at gmail.com
Sun Mar 7 18:57:15 EST 2010


>
> 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.

http://www.vtk.org/Wiki/CMake_FAQ#How_can_I_add_a_dependency_to_a_source_file_which_is_generated_in_a_subdirectory.3F

 ADD_CUSTOM_TARGET( generate_foo DEPENDS ${PROJECT_BINARY_DIR}/cm_BBS.res)
ADD_DEPENDENCIES( ${PROJECT_NAME} generate_foo )

?

sorry I should read more sometimes... and sorry I'm just guessing

>
> 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
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list