In a CMake C++ project which uses CMAKE_CXX_FLAGS
, how can I change or remove flags coming from CMAKE_CXX_FLAGS
for a specific target?
I've tried the following, which doesn't remove the flags from CMAKE_CXX_FLAGS
:
# Set somewhere else in the project
set(CMAKE_CXX_FLAGS "--bad-flag")
add_executable(main
main.cpp
)
# Not actually removing the bad flag
target_compile_options(main PRIVATE "")
set_target_properties(main PROPERTIES
COMPILE_FLAGS ""
COMPILE_OPTIONS ""
)
This question is related, but doesn't answer my question: Does set_target_properties in CMake override CMAKE_CXX_FLAGS?