Skip to content

Commit

Permalink
Use CMAKE_BUILD_TYPE instead of BUILD_DEBUG
Browse files Browse the repository at this point in the history
Use CMAKE_BUILD_TYPE instead of BUILD_DEBUG, as CMAKE_BUILD_TYPE is the
standard CMake variable and offers additional build types like
RelWithDebInfo. Previously the additional build types were impossible to
use, as they were simply overridden. Also some CMake GUI integrations
will ask the user for the build type and use it as the value of the
CMAKE_BUILD_TYPE variable.

This option is defined before the project directive, as CMake will
otherwise define it to some toolchain specific value [1].

[1] https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
  • Loading branch information
Sven Püschel authored and jwiegley committed Oct 19, 2024
1 parent a1891fa commit cd683ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_TYPE: Debug

jobs:
build:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ${{matrix.config.cmake_args}} -DBUILD_DEBUG=ON -DPython_FIND_VERSION_MAJOR=${{matrix.config.PY_MAJOR}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ${{matrix.config.cmake_args}} -DPython_FIND_VERSION_MAJOR=${{matrix.config.PY_MAJOR}}
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}

Expand Down
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ set(Required_Gpgmepp_Version 1.13.1)

cmake_minimum_required(VERSION ${Required_CMake_Version})

option(CMAKE_BUILD_TYPE "CMake Build type" "Release")
if (BUILD_DEBUG)
message(DEPRECATION "BUILD_DEBUG is deprecated! Set CMAKE_BUILD_TYPE to Debug instead!")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "CMake Build type" FORCE)
unset(BUILD_DEBUG CACHE)
endif()

PROJECT(ledger)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/doc")
Expand Down Expand Up @@ -40,11 +47,9 @@ option(BUILD_LIBRARY "Build and install Ledger as a library" ON)
option(BUILD_DOCS "Build and install documentation" OFF)
option(BUILD_WEB_DOCS "Build version of documentation suitable for viewing online" OFF)

if (BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG_MODE 1)
else()
set(CMAKE_BUILD_TYPE Release)
set(DEBUG_MODE 0)
endif()

Expand Down
8 changes: 4 additions & 4 deletions acprep
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,16 @@ class PrepareBuild(CommandLineApp):
pass

def setup_flavor_debug(self):
self.configure_args.append('-DBUILD_DEBUG=1')
self.configure_args.append('-DCMAKE_BUILD_TYPE=Debug')

def setup_flavor_opt(self):
self.configure_args.append('-DBUILD_DEBUG=0')
self.configure_args.append('-DCMAKE_BUILD_TYPE=Release')
self.configure_args.append('-DNO_ASSERTS=1')

def setup_flavor_gcov(self):
# NO_ASSERTS is set so that branch coverage ignores the never-taken
# else branch inside assert statements.
self.configure_args.append('-DBUILD_DEBUG=1')
self.configure_args.append('-DCMAKE_BUILD_TYPE=Debug')
self.configure_args.append('-DNO_ASSERTS=1')
self.configure_args.append('-DCLANG_GCOV=1')

Expand All @@ -905,7 +905,7 @@ class PrepareBuild(CommandLineApp):
self.LDFLAGS.append('-lgcov')

def setup_flavor_gprof(self):
self.configure_args.append('-DBUILD_DEBUG=1')
self.configure_args.append('-DCMAKE_BUILD_TYPE=Debug')

self.CXXFLAGS.append('-pg')
self.LDFLAGS.append('-pg')
Expand Down

0 comments on commit cd683ae

Please sign in to comment.