Instead of manipulating the CMAKE_CXX_FLAGS
strings directly (which could be done more nicely using string(APPEND CMAKE_CXX_FLAGS_DEBUG " -g3")
btw), you can use add_compiler_options
:
add_compile_options(
"-Wall" "-Wpedantic" "-Wextra" "-fexceptions"
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb>"
)
This would add the specified warnings to all build types, but only the given debugging flags to the DEBUG
build. Note that compile options are stored as a CMake list, which is just a string separating its elements by semicolons ;
.