简体   繁体   中英

CMake: how to clear target compile options

In my project I have defined some general compile options using CMAKE_CXX_FLAGS globally. Some other options, that in common case should be applied to all targets, are specified using add_compile_options() in my main CMakeLists file.

For example I want the flag -Wconversion be applied to all targets. But I have one external library that produces to many warnings with this option enabled. So I want to disable option only for this particular lib:

get_target_property(EXTLIB_COMPILE_FLAGS ext_lib COMPILE_OPTIONS )
list(REMOVE_ITEM EXTLIB_COMPILE_FLAGS -Wconversion)
set_target_properties(ext_lib PROPERTIES COMPILE_OPTIONS ${EXTLIB_COMPILE_FLAGS } )

But right now only -Wconversion was setted using add_compile_options() . And target does not have any own additional flags. So, after removing the only entry from the list I will get an empty list. Call to set_target_properties() fails with error:

set_target_properties called with incorrect number of arguments.

Is any way to clear some of target properties completly? I'm using CMake 3.11

Turning my comment into an answer

Just add quotes:

set_target_properties(ext_lib PROPERTIES COMPILE_OPTIONS "${EXTLIB_COMPILE_FLAGS}")

Now - if EXTLIB_COMPILE_FLAGS variable is empty - you end-up having an empty string and just not an "missing argument".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM