Skip to content

Commit

Permalink
Set default build type to RelWithDebInfo (CMake)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivmai committed Aug 19, 2022
1 parent 516bd61 commit 0b677ae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0b677ae

Please sign in to comment.