From 44ac2e8a8d24963067b7f2bc9d834ae57b790ddd Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Wed, 6 Dec 2023 23:49:42 +0100 Subject: [PATCH] CMake: Allow asserts to be enabled for release builds. Asserts historically only have been on in debug builds, however running the tests in a debug configuration takes a while especially if Cycles is enabled. This adds WITH_ASSERT_RELEASE to enable asserts in release configurations. It is enabled for "make developer" , and will also be used for CI. Co-authored-by: Brecht Van Lommel Pull Request: https://projects.blender.org/blender/blender/pulls/115071 --- CMakeLists.txt | 28 +++++++++++++------ .../cmake/config/blender_developer.cmake | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60468d5a7a4..487ac956203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,17 +53,11 @@ endif() # quiet output for Makefiles, 'make -s' helps too # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF) -# global compile definitions since add_definitions() adds for all. +# Global compile definitions since add_definitions() adds for all. +# _DEBUG is a Visual Studio define, enabled for all platforms. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS - # Visual Studio define for debug, enable on all platforms. $<$:_DEBUG> - # Standard C define to disable asserts. - $<$:NDEBUG> - $<$:NDEBUG> - $<$:NDEBUG> ) - - # ----------------------------------------------------------------------------- # Set policy @@ -101,7 +95,6 @@ endif() include(build_files/cmake/macros.cmake) - # ----------------------------------------------------------------------------- # Initialize Project @@ -735,6 +728,9 @@ mark_as_advanced(WITH_CXX_GUARDEDALLOC) option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON) mark_as_advanced(WITH_ASSERT_ABORT) +option(WITH_ASSERT_RELEASE "Build with asserts enabled even for non-debug configurations" OFF) +mark_as_advanced(WITH_ASSERT_RELEASE) + if((UNIX AND NOT APPLE) OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+")) option(WITH_CLANG_TIDY "\ Use Clang Tidy to analyze the source code \ @@ -2167,6 +2163,20 @@ if(WITH_ASSERT_ABORT) add_definitions(-DWITH_ASSERT_ABORT) endif() +# NDEBUG is the standard C define to disable asserts. +if(WITH_ASSERT_RELEASE) + # CMake seemingly be setting the NDEBUG flag on its own already on some configurations + # therefore we need to remove the flags if they happen to be set. + remove_cc_flag("-DNDEBUG") # GCC/CLang + remove_cc_flag("/DNDEBUG") # MSVC +else() + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS + $<$:NDEBUG> + $<$:NDEBUG> + $<$:NDEBUG> + ) +endif() + # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}") # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}") diff --git a/build_files/cmake/config/blender_developer.cmake b/build_files/cmake/config/blender_developer.cmake index 95a64124750..0cfcf3286f8 100644 --- a/build_files/cmake/config/blender_developer.cmake +++ b/build_files/cmake/config/blender_developer.cmake @@ -9,6 +9,7 @@ # set(WITH_ASSERT_ABORT ON CACHE BOOL "" FORCE) +set(WITH_ASSERT_RELEASE ON CACHE BOOL "" FORCE) set(WITH_BUILDINFO OFF CACHE BOOL "" FORCE) # Sadly ASAN is more often broken than working with MSVC do not enable it in the # developer profile for now.