Skip to content

Commit a10dbb7

Browse files
Add Release build assertions CMake option
The option is off for release builds by default, but enabled for tests. The intention is to enable this option for "debug" testing, but with release build.
1 parent 212c367 commit a10dbb7

File tree

10 files changed

+24
-7
lines changed

10 files changed

+24
-7
lines changed

lib/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ set(cpp_lib_name "mmsolverlibs_cpp")
6767
set(rust_lib_name "mmsolverlibs_rust")
6868

6969
include(MMCommonUtils)
70-
mm_common_set_global_compile_options()
70+
option(MMSOLVER_BUILD_RELEASE_ASSERTIONS "Enable Assertions to be called in Release mode." OFF)
71+
mm_common_set_global_compile_options(MMSOLVER_BUILD_RELEASE_ASSERTIONS)
7172

7273
include(MMRustUtils)
7374
set(rust_linktime_file "NOT-FOUND")

lib/cppbind/mmimage/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ set(test_source_files
3030
)
3131

3232
include(MMCommonUtils)
33-
mm_common_set_global_compile_options()
33+
option(MMSOLVER_BUILD_RELEASE_ASSERTIONS "Enable Assertions to be called in Release mode." ON)
34+
mm_common_set_global_compile_options(MMSOLVER_BUILD_RELEASE_ASSERTIONS)
3435

3536
# Add test executable using the C++ bindings.
3637
message(STATUS "target_test_exe_name: ${target_test_exe_name}")

lib/cppbind/mmlens/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ set(test_source_files
3939
)
4040

4141
include(MMCommonUtils)
42-
mm_common_set_global_compile_options()
42+
option(MMSOLVER_BUILD_RELEASE_ASSERTIONS "Enable Assertions to be called in Release mode." ON)
43+
mm_common_set_global_compile_options(MMSOLVER_BUILD_RELEASE_ASSERTIONS)
4344

4445
# Add test executable using the C++ bindings.
4546
add_executable(${target_test_exe_name} ${test_source_files})

lib/cppbind/mmscenegraph/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ set(test_source_files
2828
)
2929

3030
include(MMCommonUtils)
31-
mm_common_set_global_compile_options()
31+
option(MMSOLVER_BUILD_RELEASE_ASSERTIONS "Enable Assertions to be called in Release mode." ON)
32+
mm_common_set_global_compile_options(MMSOLVER_BUILD_RELEASE_ASSERTIONS)
3233

3334
# Add test executable using the C++ bindings.
3435
add_executable(${target_test_exe_name} ${test_source_files})

scripts/internal/build_mmSolverLibs_linux.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ BUILD_DIR_BASE="${PROJECT_ROOT}/../"
4444

4545
# What type of build? "Release" or "Debug"?
4646
BUILD_TYPE="Release"
47+
MMSOLVER_BUILD_RELEASE_ASSERTIONS=0
4748

4849
RELEASE_FLAG=""
4950
BUILD_TYPE_DIR="debug"
@@ -133,6 +134,7 @@ ${CMAKE_EXE} \
133134
-DCMAKE_MODULE_PATH=${OPENCOLORIO_CMAKE_FIND_MODULES_DIR} \
134135
-DCMAKE_VERBOSE_MAKEFILE=${MMSOLVER_BUILD_VERBOSE} \
135136
-DMMSOLVER_VFX_PLATFORM=${VFX_PLATFORM} \
137+
-DMMSOLVER_BUILD_RELEASE_ASSERTIONS=${MMSOLVER_BUILD_RELEASE_ASSERTIONS} \
136138
-DMMSOLVERLIBS_CXXBRIDGE_EXE=${MMSOLVERLIBS_CXXBRIDGE_EXE} \
137139
-DMMSOLVERLIBS_BUILD_TESTS=${MMSOLVERLIBS_BUILD_TESTS} \
138140
-DMMSOLVERLIBS_LIB_DIR=${MMSOLVERLIBS_LIB_DIR} \

scripts/internal/build_mmSolverLibs_windows64.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SET BUILD_DIR_BASE=%PROJECT_ROOT%\..
3535

3636
:: What type of build? "Release" or "Debug"?
3737
SET BUILD_TYPE=Release
38+
SET MMSOLVER_BUILD_RELEASE_ASSERTIONS=0
3839

3940
SET RELEASE_FLAG=
4041
SET BUILD_TYPE_DIR=debug
@@ -158,6 +159,7 @@ CHDIR "%BUILD_DIR%"
158159
-DCMAKE_MODULE_PATH=%OPENCOLORIO_CMAKE_FIND_MODULES_DIR% ^
159160
-DCMAKE_VERBOSE_MAKEFILE=%MMSOLVER_BUILD_VERBOSE% ^
160161
-DMMSOLVER_VFX_PLATFORM=%VFX_PLATFORM% ^
162+
-DMMSOLVER_BUILD_RELEASE_ASSERTIONS=%MMSOLVER_BUILD_RELEASE_ASSERTIONS% ^
161163
-DMMSOLVERLIBS_CXXBRIDGE_EXE=%MMSOLVERLIBS_CXXBRIDGE_EXE% ^
162164
-DMMSOLVERLIBS_BUILD_TESTS=%MMSOLVERLIBS_BUILD_TESTS% ^
163165
-DMMSOLVERLIBS_LIB_DIR=%MMSOLVERLIBS_LIB_DIR% ^

scripts/internal/build_mmSolver_linux.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ BUILD_DIR_BASE="${PROJECT_ROOT}/../"
5959

6060
# What type of build? "Release" or "Debug"?
6161
BUILD_TYPE=Release
62+
MMSOLVER_BUILD_RELEASE_ASSERTIONS=0
6263

6364
# Build options, to allow faster compilation times. (not to be used by
6465
# users wanting to build this project.)
@@ -140,6 +141,7 @@ ${CMAKE_EXE} \
140141
-DCMAKE_VERBOSE_MAKEFILE=${MMSOLVER_BUILD_VERBOSE} \
141142
-DOPENGL_INCLUDE_DIR=${OPENGL_INCLUDE_DIR} \
142143
-DMMSOLVER_VFX_PLATFORM=${VFX_PLATFORM} \
144+
-DMMSOLVER_BUILD_RELEASE_ASSERTIONS=${MMSOLVER_BUILD_RELEASE_ASSERTIONS} \
143145
-DMMSOLVER_BUILD_PLUGIN=${MMSOLVER_BUILD_PLUGIN} \
144146
-DMMSOLVER_BUILD_TOOLS=${MMSOLVER_BUILD_TOOLS} \
145147
-DMMSOLVER_BUILD_PYTHON=${MMSOLVER_BUILD_PYTHON} \

scripts/internal/build_mmSolver_windows64.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ SET BUILD_PACKAGE=1
5959

6060
:: What type of build? "Release" or "Debug"?
6161
SET BUILD_TYPE=Release
62+
SET MMSOLVER_BUILD_RELEASE_ASSERTIONS=0
6263

6364
:: Build options, to allow faster compilation times. (not to be used by
6465
:: users wanting to build this project.)
@@ -158,6 +159,7 @@ CHDIR "%BUILD_DIR%"
158159
-DCMAKE_MODULE_PATH=%OPENCOLORIO_CMAKE_FIND_MODULES_DIR% ^
159160
-DCMAKE_VERBOSE_MAKEFILE=%MMSOLVER_BUILD_VERBOSE% ^
160161
-DMMSOLVER_VFX_PLATFORM=%VFX_PLATFORM% ^
162+
-DMMSOLVER_BUILD_RELEASE_ASSERTIONS=%MMSOLVER_BUILD_RELEASE_ASSERTIONS% ^
161163
-DMMSOLVER_BUILD_PLUGIN=%MMSOLVER_BUILD_PLUGIN% ^
162164
-DMMSOLVER_BUILD_TOOLS=%MMSOLVER_BUILD_TOOLS% ^
163165
-DMMSOLVER_BUILD_PYTHON=%MMSOLVER_BUILD_PYTHON% ^

share/cmake/modules/MMCommonUtils.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,14 @@ function(mm_common_linux_gcc_set_global_compile_options)
226226
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=skylake") # Use AVX2 instructions
227227
endfunction()
228228

229-
function(mm_common_set_global_compile_options)
229+
function(mm_common_set_global_compile_options enable_release_mode_assertions)
230230

231231
if(CMAKE_BUILD_TYPE EQUAL "Release")
232-
add_compile_definitions(NDEBUG)
232+
# If 'NDEBUG' is enabled, it will disable 'assert'ions.
233+
# https://en.cppreference.com/w/cpp/error/assert
234+
if(NOT enable_release_mode_assertions)
235+
add_compile_definitions(NDEBUG)
236+
endif ()
233237
elseif (CMAKE_BUILD_TYPE EQUAL "Debug")
234238
add_compile_definitions(_DEBUG)
235239
endif ()

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ endif ()
179179
# plug-in. See 'MMSolverUtils' CMake module for more information.
180180
include(MMCommonUtils)
181181
mm_common_set_global_treat_warnings_as_errors()
182-
mm_common_set_global_compile_options()
182+
option(MMSOLVER_BUILD_RELEASE_ASSERTIONS "Enable Assertions to be called in Release mode." OFF)
183+
mm_common_set_global_compile_options(MMSOLVER_BUILD_RELEASE_ASSERTIONS)
183184

184185
# MM Solver standalone libraries.
185186
find_package(mmsolverlibs_cpp REQUIRED)

0 commit comments

Comments
 (0)