diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ # Copyright (c) 2017 The Bitcoin developers cmake_minimum_required(VERSION 3.12) + +set(CMAKE_USER_MAKE_RULES_OVERRIDE + "${CMAKE_SOURCE_DIR}/cmake/modules/OverrideInitFlags.cmake" +) + project(bitcoin-abc VERSION 0.20.9 DESCRIPTION "Bitcoin ABC is a full node implementation of the Bitcoin Cash protocol." diff --git a/cmake/modules/OverrideInitFlags.cmake b/cmake/modules/OverrideInitFlags.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/OverrideInitFlags.cmake @@ -0,0 +1,15 @@ +# This will set the initial value for the C/CXX flags. +# It is included at the time a project language is enabled. + +# This mimics the autotools behavior by setting the CFLAGS to '-g -O2`, which +# are not well suited for debugging. +# FIXME: update CFLAGS with better debug oriented optimization flags +set(CMAKE_C_FLAGS_DEBUG_INIT "-g -O2") +set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os") +set(CMAKE_C_FLAGS_RELEASE_INIT "-O3") +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -O2") + +set(CMAKE_CXX_FLAGS_DEBUG_INIT "-O0") +set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-g -O2") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,22 +40,7 @@ endif() endif() -# Cmake uses the CMAKE_BUILD_TYPE variable to select the build configuration. -# By default it supports more configurations that needed for Bitcoin ABC, and -# all the releases types set NDEBUG which is unwanted as it disables the assert -# completely. -# Remove the -DNDEBUG flag from the CFLAGS/CXXFLAGS in all the configurations include(AddCompilerFlags) -remove_compiler_flags(-DNDEBUG) - -# Overrides the flags for the Debug build type -# This mimics the autotools behavior by setting the CFLAGS to '-g -O2`, which -# are not well suited for debugging. -# FIXME: update CFLAGS with better debug oriented optimization flags -set(CMAKE_C_FLAGS_DEBUG "-g -O2") - -# Disable all optimizations -set(CMAKE_CXX_FLAGS_DEBUG -O0) # Prefer -g3, defaults to -g if unavailable add_cxx_compiler_flag_with_fallback(CMAKE_CXX_FLAGS_DEBUG -g3 -g)