问题
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
回答1:
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".
来源:https://stackoverflow.com/questions/50512905/cmake-how-to-clear-target-compile-options