[CMake] Settings different flags in sub projects

Magnus Therning magnus at therning.org
Mon Aug 4 00:16:46 EDT 2014


On Sun, Aug 03, 2014 at 05:46:40PM -0500, David Zemon wrote:
> Hello,
> 
> For the simple case of three directories and two projects - /root, /root/p1,
> and /root/p2 - I would like to set some common flags for both projects and
> then other flags should be independent. For instance, p1 should be compiled
> with "-std=c99 -Os" and p2 should be compiled with "-std=c99 -O1". The first
> flag, -std=c99, is common to all projects and the second, -Os, might be
> changed from project to project. How do I do this?
> 
> I thought I could create MyRulesOverride.cmake with the content:
> 
>    set(CMAKE_C_FLAGS_INIT "-std=c99")
> 
> And that would be the end of it, but apparently not. The CMakeLists.txt
> files in each project have a line such as " set(CMAKE_C_FLAGS "-Os")" which
> is apparently overwriting the cached value from CMakeCInformation.cmake. I
> can't write a line like "set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")" because
> then the result is "-std=c99 -std=c99 -Os" for the second project.
> 
> Any help would be greatly appreciated.

I haven't tested this, but would you have to *add* to the flag?  AFAIU
setting always over writes the previous value.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus

The results point out the fragility of programmer expertise: advanced
programmers have strong expectations about what programs should look like,
and when those expectations are violated--in seemingly innocuous
ways--their performance drops drastically.
     -- Elliot Soloway and Kate Ehrlich
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140804/ad971710/attachment.sig>


More information about the CMake mailing list