CMake: how to clear target compile options

让人想犯罪 __ 提交于 2020-07-19 04:37:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!