Search code examples
cmakeqt-creator

Make CMake generate only Release and Debug configurations


Is it possible to make CMake generate only Release and Debug configurations and make Release configuration to be RelWithDebInfo?

The problem is that QT Creator understands only Release and Debug and do not understand RelWithDebInfo, see https://forum.qt.io/topic/144983/qt-6-5-signs-debug-package for more information.

enter image description here


Solution

  • To generate debug symbols in clang, call it with the -g option.

    The most simple solution would be to add a line to your top-level CMakeLists.txt:

    add_compile_options(-g)
    

    Add_compile_options will unconditionally set the option for all targets in this directory and those below. It will do so for all configurations (it should already be set in debug and will do no harm if set twice).

    To have more control for which targets and configurations to generate debug info, use target_compile_options with a generator expression like the following:

    target_compile_options(mytarget PRIVATE $<$<CONFIG:Release>:-g>)
    

    This will work with GCC and clang but not with other compilers that use different options (most notably MSVC).