Преглед на файлове

Adds a flag to enable assertion in non debug builds. (#1075)

Andrea Catania преди 1 година
родител
ревизия
1ac33c3e7c
променени са 3 файла, в които са добавени 9 реда и са изтрити 0 реда
  1. 3 0
      Build/CMakeLists.txt
  2. 1 0
      Build/README.md
  3. 5 0
      Jolt/Jolt.cmake

+ 3 - 0
Build/CMakeLists.txt

@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
 
 project(JoltPhysics CXX)
 
+# When turning this option on, the library will be compiled using assertions. By default asserts are enabled in Debug build.
+option(USE_ASSERTS "Enable asserts" OFF)
+
 # When turning this option on, the library will be compiled using doubles for positions. This allows for much bigger worlds.
 option(DOUBLE_PRECISION "Use double precision math" OFF)
 

+ 1 - 0
Build/README.md

@@ -29,6 +29,7 @@ There are a number of user configurable defines that turn on/off certain feature
 		<li>JPH_DISABLE_CUSTOM_ALLOCATOR - Disables the ability to override the memory allocator.</li>
 		<li>JPH_FLOATING_POINT_EXCEPTIONS_ENABLED - Turns on division by zero and invalid floating point exception support in order to detect bugs (Windows only).</li>
 		<li>JPH_CROSS_PLATFORM_DETERMINISTIC - Turns on behavior to attempt cross platform determinism. If this is set, JPH_USE_FMADD is ignored.</li>
+		<li>JPH_ENABLE_ASSERTS - Compiles the library so that it rises an assert in case of failures. The library ignores these failures otherwise.</li>
 		<li>JPH_DOUBLE_PRECISION - Compiles the library so that all positions are stored in doubles instead of floats. This makes larger worlds possible.</li>
 	</ul>
 </details>

+ 5 - 0
Jolt/Jolt.cmake

@@ -507,6 +507,11 @@ if (DISABLE_CUSTOM_ALLOCATOR)
 	target_compile_definitions(Jolt PUBLIC JPH_DISABLE_CUSTOM_ALLOCATOR)
 endif()
 
+# Setting enable asserts flag
+if (USE_ASSERTS)
+	target_compile_definitions(Jolt PUBLIC JPH_ENABLE_ASSERTS)
+endif()
+
 # Setting double precision flag
 if (DOUBLE_PRECISION)
 	target_compile_definitions(Jolt PUBLIC JPH_DOUBLE_PRECISION)