[CMake] Remove compilation flags for a given target

Benjamin Orgogozo borgogozo at antidot.net
Thu Apr 4 08:31:11 EDT 2019


Hello,

in our code base we would like to add a warning compilation flags.
Nevertheless, this flag prevents us from compiling a few targets so we
would like to remove this flag for the given targets.

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

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

Everything is tested under linux and cmake 3.13.3.

Thanks for you help, any pointer to a ressource that might contain
useful information for this problem would be really appreciated.

Regards,

-- 
 Benjamin Orgogozo


More information about the CMake mailing list