From 232ec62c75a08f58dafd4c1d3bed2a077db48e18 Mon Sep 17 00:00:00 2001 From: Edward Hennis Date: Fri, 27 Jan 2017 11:38:48 -0500 Subject: [PATCH] CMake -Dassert=true properly enables asserts in Release: * CMake defaults CMAKE_CXX_FLAGS_RELEASE, etc. to include defining NDEBUG, regardless of other options set elsewhere, for most or all generators. This change explicitly removes that flag from the relevant variables. * Also move the project command earlier, since it wipes out some local changes. --- Builds/CMake/CMakeFuncs.cmake | 14 +++++++++----- CMakeLists.txt | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Builds/CMake/CMakeFuncs.cmake b/Builds/CMake/CMakeFuncs.cmake index 1e61d7080..764aa2e3a 100644 --- a/Builds/CMake/CMakeFuncs.cmake +++ b/Builds/CMake/CMakeFuncs.cmake @@ -147,11 +147,6 @@ macro(setup_build_cache) set(CMAKE_CONFIGURATION_TYPES DebugClassic ReleaseClassic) - if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set(CMAKE_BUILD_TYPE DebugClassic) - elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") - set(CMAKE_BUILD_TYPE ReleaseClassic) - endif() endif() set(CMAKE_CONFIGURATION_TYPES @@ -502,6 +497,15 @@ macro(setup_build_boilerplate) APPEND PROPERTY COMPILE_DEFINITIONS $<$,$,$>:NDEBUG>) + else() + # CMAKE_CXX_FLAGS_RELEASE is created by CMake for most / all generators + # with defaults including /DNDEBUG or -DNDEBUG, and that value is stored + # in the cache. Override that locally so that the cache value will be + # avaiable if "assert" is ever changed. + STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASECLASSIC "${CMAKE_CXX_FLAGS_RELEASECLASSIC}") + STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_RELEASECLASSIC "${CMAKE_C_FLAGS_RELEASECLASSIC}") endif() if (NOT WIN32) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6735f521..d5817b4e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,10 @@ cmake_minimum_required(VERSION 3.1.0) +# The project command can override some computed values. +# Don't put any code above this line. +project(rippled) + if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") set(dir "build") set(cmd "cmake") @@ -96,8 +100,6 @@ endif() setup_build_cache() -project(rippled) - if(nonunity) get_cmake_property(allvars VARIABLES) string(REGEX MATCHALL "[^;]*(DEBUG|RELEASE)[^;]*" matchvars "${allvars}")