0

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

Alexey Starinsky
  • 3,699
  • 3
  • 21
  • 57

1 Answers1

0

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).

Friedrich
  • 2,011
  • 2
  • 17
  • 19
  • looks like I also need to replace `-O3` with `-O2`, see https://stackoverflow.com/questions/48754619/what-are-cmake-build-type-debug-release-relwithdebinfo-and-minsizerel – Alexey Starinsky May 09 '23 at 11:15
  • 1
    It depends on what you want to accomplish. If you want to have debug information, `-g` is enough. If you also want to have less optimization, then you need to change to `-O2`. Looking at differences between `-O2` and `-O3` in the [clang doc](https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-o0), I wouldn't bother. – Friedrich May 09 '23 at 11:27