From 0b677ae93c4084eefae60d77f7b89432abbaae07 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 19 Aug 2022 10:17:20 +0300 Subject: Set default build type to RelWithDebInfo (CMake) This enforces -O2 -g options passed to the compiler (in case of the gcc or clang compiler), matching that of the configure-based build. * CMakeLists.txt [!CMAKE_BUILD_TYPE && !CMAKE_CONFIGURATION_TYPES] (CMAKE_BUILD_TYPE): Set to RelWithDebInfo; set property (listing all possible values). * CMakeLists.txt [enable_assertions]: Add -UNDEBUG compile option; add comment. --- CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 938847e..d782280 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,15 @@ option(enable_docs "Build and install documentation" ON) option(enable_gpl "Build atomic_ops_gpl library" ON) option(install_headers "Install header and pkg-config metadata files" ON) +# Override the default build type to RelWithDebInfo (this instructs cmake to +# pass -O2 -g -DNDEBUG options to the compiler). +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE + STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY + STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel") +endif() + # Convert VER_INFO values to [SO]VERSION ones. if (BUILD_SHARED_LIBS) # atomic_ops: @@ -94,7 +103,10 @@ else() add_definitions("-DAO_NO_PTHREADS") endif() -if (NOT enable_assertions) +if (enable_assertions) + # In case NDEBUG macro is defined e.g. by cmake -DCMAKE_BUILD_TYPE=Release. + add_compile_options("-UNDEBUG") +else() # Define to disable assertion checking. add_definitions("-DNDEBUG") endif() -- cgit v1.2.1