[CMake] Settings different flags in sub projects

David Zemon david at zemon.name
Mon Aug 4 19:10:38 EDT 2014


Glenn, thanks for the tip. Those two options are new to me.

It's not very clear to me how the add_compile_options function works. 
Complexity might be added when I mention that I've also defined 4 new 
custom languages (all essentially identical to C). When 
add_compile_options is executed, will it add the flags to all languages 
(that would be desirable in my case)? What about assembly (that would be 
undesirable but I don't think detrimental)?

If I use the "header guard" concept, could I just tack that 
add_compile_options line onto my ToolChain file? That would save trouble 
for users of my library so that they don't have to define all the basics 
in every one of their projects.

Can I assume that set_property(DIRECTORY "..." PROPERTY COMPILE_OPTIONS 
"...") affects the same variables as add_compile_options?

Thank you,
David

On 08/04/2014 05:09 PM, Glenn Coombs wrote:
> Something like this should work:
>
> add_compile_options(-std=c99)
>
> set_property(DIRECTORY "/root/p1" PROPERTY COMPILE_OPTIONS "-Os")
> set_property(DIRECTORY "/root/p2" PROPERTY COMPILE_OPTIONS "-O1")
>
>
> or you just use the add_compile_options command in all 3 CMakeLists.txt files.  The CMakeLists.txt files in root/p1 and root/p2 will inherit the compile options set in the parent root/CMakeLists.txt file.
>
>
> --
> Glenn
>
>
> On 3 August 2014 23:46, David Zemon <david at zemon.name 
> <mailto:david at zemon.name>> 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.
>
>     David
>
>     --
>
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Please keep messages on-topic and check the CMake FAQ at:
>     http://www.cmake.org/Wiki/CMake_FAQ
>
>     Kitware offers various services to support the CMake community.
>     For more information on each offering, please visit:
>
>     CMake Support: http://cmake.org/cmake/help/support.html
>     CMake Consulting: http://cmake.org/cmake/help/consulting.html
>     CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>
>     Follow this link to subscribe/unsubscribe:
>     http://public.kitware.com/mailman/listinfo/cmake
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140804/9b0fefe0/attachment-0001.html>


More information about the CMake mailing list