[CMake] Remove compilation flags for a given target

Mateusz Loskot mateusz at loskot.net
Thu Apr 4 12:00:43 EDT 2019


On Thu, 4 Apr 2019 at 14:47, Benjamin Orgogozo <borgogozo at antidot.net> wrote:
>
> If I'm right (I'm far from being a cmake expert) there are two ways to
> define "global" compilation flags:
> 1- set the CXX_COMPILE_FLAGS variable;
> 2- use add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-WMyFavouriteWarning).

The list should rather be, in preference/priority order

1. https://cmake.org/cmake/help/latest/command/target_compile_options.html
2. add_compile_options

And, if you really, really need
3. append to CMAKE_CXX_FLAGS

> Since I don't want to *add* a compilation flags but remove one, I would
> like to retrieve the properties of the target
> (get_target_property(my_compilation_flags TARGET COMPILE_FLAGS)), and
> then modify those and use it to set the properties of the target.
>
> Two questions for me remain:
> 1- How do I get *all* the compilation flags used for a target?
> get_target_property doesn't return flags is CXX_COMPILE_FLAGS nor those
> added by add_compile_options.

Are you certain you've got the variable name right?
https://cmake.org/cmake/help/latest/search.html?q=CXX_COMPILE_FLAGS

> 2- How do I *replace* compilation flags and don't *add* compilation
> flags? Both target_compile_options and set_target_properties seems to
> *add* flags and don't replace.

See  https://cmake.org/pipermail/cmake/2018-December/068716.html

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the CMake mailing list