From 39b376706562b45544d9ea7cc5278bedd46c68c6 Mon Sep 17 00:00:00 2001 From: Bram de Greve Date: Sat, 26 Aug 2023 14:28:23 +0200 Subject: [PATCH] Add debug symbols to Release builds By default, CMake Release builds are built without debug symbols. The idea is that you use RelWithDebInfo if you want them. However, RelWithDebInfo generates less optimized code, only inlining __inline code. More specifically, RelWithDebInfo builds use the /Ob1 option, and Release builds use /Ob2 [1,2]. In the end, we want to use Release for production code, but we also need debug symbols for post-mortem analysis. [1] https://github.com/conan-io/conan-center-index/issues/1982#issuecomment-1156754295 [2] https://gitlab.kitware.com/cmake/cmake/-/blob/d7741457861816d50114801abc84d1d78afdc754/Modules/Platform/Windows-MSVC.cmake#L486-490 --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 470ce645..324b06ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,15 @@ else() endif() +# Always build Release with debug symbols as well +if(MSVC) + add_compile_options("$<$:/Zi>") + add_link_options("$<$:/DEBUG>") +else() + add_compile_options("$<$:-g>") +endif() + + add_subdirectory(lass) if(TARGET Lass::lass_python) add_subdirectory(pylass)