[CMake] How to set different compiler flags for two projects in one solution

Tyler Roscoe tyler at cryptio.net
Tue Jun 23 12:54:13 EDT 2009


Make sure to reply to the list!

On Tue, Jun 23, 2009 at 08:24:52AM +0200, ariasgore at gmx.de wrote:
> what I was talking about is that if I have project 1 and 2 and I need
> to set additional compiler_flags for project 2 I can do that with
> set_target_properties, thats fine. But if the additional flags are not
> compatible with the flags defined in CMAKE_CXX_FLAGS then I need to
> strip the flag in the CMAKE_CXX_FLAGS variable. Doing this with the
> set_target_properties on project 2 is my desired result.  BUT since I
> removed a global flag in CMAKE_CXX_FLAGS, all other projects (e.g.
> project 1) has also to be modified manually with set_target_projects.
> 
> If I have 20 projects where only one requires one flag stripped and
> another added I still need to touch all other projects manually and
> add the globally stripped flag.

Can you do something like this:

set (CMAKE_CXX_FLAGS_ORIG CMAKE_CXX_FLAGS)
string (REPLACE "foo" "bar" ${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
add_library (baz ${src_files})
set (CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_ORIG)

?

tyler


More information about the CMake mailing list