CMAKECFLAGSDEBUG
CMAKE_C_FLAGS_DEBUG is a CMake cache variable used to specify additional compiler options for the C compiler when building in the Debug configuration. It is the per-configuration counterpart to CMAKE_C_FLAGS, and there are analogous variables for C++ such as CMAKE_CXX_FLAGS_DEBUG. These variables allow you to tailor flags for debugging without altering other configurations.
In practice, the behavior depends on the generator being used. For single-configuration generators (such as Makefiles
How to use it. You can modify or extend the existing flags in your CMakeLists.txt, for example:
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
list(APPEND CMAKE_C_FLAGS_DEBUG "-g")
This approach appends debugging flags to the existing set. Alternatively, you can apply per-target options using
target_compile_options(mytarget PRIVATE $<$<CONFIG:Debug>:-g>)
or combine with other per-config flags as appropriate.
Notes and caveats. On some toolchains (notably some Windows/MSVC setups), the conventional Unix-style flags in CMAKE_C_FLAGS_DEBUG