CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
  2. project(JoltPhysics CXX)
  3. # When turning this option on, the library will be compiled using assertions. By default asserts are enabled in Debug build.
  4. option(USE_ASSERTS "Enable asserts" OFF)
  5. # When turning this option on, the library will be compiled using doubles for positions. This allows for much bigger worlds.
  6. option(DOUBLE_PRECISION "Use double precision math" OFF)
  7. # When turning this option on, the library will be compiled with debug symbols
  8. option(GENERATE_DEBUG_SYMBOLS "Generate debug symbols" ON)
  9. # Which type of debug symbols to generate, e.g. using source-map when compiling with emscripten makes compilation a lot faster
  10. set(JPH_DEBUG_SYMBOL_FORMAT "" CACHE STRING "Which type of debug symbols to generate")
  11. # When turning this option on, the library will override the default CMAKE_CXX_FLAGS_DEBUG/RELEASE values, otherwise they will use the platform defaults
  12. option(OVERRIDE_CXX_FLAGS "Override CMAKE_CXX_FLAGS_DEBUG/RELEASE" ON)
  13. # When turning this option on, the library will be compiled in such a way to attempt to keep the simulation deterministic across platforms
  14. option(CROSS_PLATFORM_DETERMINISTIC "Cross platform deterministic" OFF)
  15. # When turning this option on, the library will be compiled for ARM (aarch64-linux-gnu), requires compiling with clang
  16. option(CROSS_COMPILE_ARM "Cross compile to aarch64-linux-gnu" OFF)
  17. # When turning this option on, Jolt will be compiled as a shared library and public symbols will be exported.
  18. option(BUILD_SHARED_LIBS "Compile Jolt as a shared library" OFF)
  19. # When turning this option on, the library will be compiled with interprocedural optimizations enabled, also known as link-time optimizations or link-time code generation.
  20. # Note that if you turn this on you need to use SET_INTERPROCEDURAL_OPTIMIZATION() or set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) to enable LTO specifically for your own project as well.
  21. # If you don't do this you may get an error: /usr/bin/ld: libJolt.a: error adding symbols: file format not recognized
  22. option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimizations" ON)
  23. # When turning this on, in Debug and Release mode, the library will emit extra code to ensure that the 4th component of a 3-vector is kept the same as the 3rd component
  24. # and will enable floating point exceptions during simulation to detect divisions by zero.
  25. # Note that this currently only works using MSVC. Clang turns Float2 into a SIMD vector sometimes causing floating point exceptions (the option is ignored).
  26. option(FLOATING_POINT_EXCEPTIONS_ENABLED "Enable floating point exceptions" ON)
  27. # When turning this on, the library will be compiled with C++ exceptions enabled.
  28. # This adds some overhead and Jolt doesn't use exceptions so by default it is off.
  29. option(CPP_EXCEPTIONS_ENABLED "Enable C++ exceptions" OFF)
  30. # When turning this on, the library will be compiled with C++ RTTI enabled.
  31. # This adds some overhead and Jolt doesn't use RTTI so by default it is off.
  32. option(CPP_RTTI_ENABLED "Enable C++ RTTI" OFF)
  33. # Number of bits to use in ObjectLayer. Can be 16 or 32.
  34. option(OBJECT_LAYER_BITS "Number of bits in ObjectLayer" 16)
  35. # Select X86 processor features to use (if everything is off it will be SSE2 compatible)
  36. option(USE_SSE4_1 "Enable SSE4.1" ON)
  37. option(USE_SSE4_2 "Enable SSE4.2" ON)
  38. option(USE_AVX "Enable AVX" ON)
  39. option(USE_AVX2 "Enable AVX2" ON)
  40. option(USE_AVX512 "Enable AVX512" OFF)
  41. option(USE_LZCNT "Enable LZCNT" ON)
  42. option(USE_TZCNT "Enable TZCNT" ON)
  43. option(USE_F16C "Enable F16C" ON)
  44. option(USE_FMADD "Enable FMADD" ON)
  45. # Enable SIMD for the WASM build. Note that this is currently off by default since not all browsers support this.
  46. # See: https://caniuse.com/?search=WebAssembly%20SIMD (Safari got support in March 2023 and was the last major browser to get support).
  47. option(USE_WASM_SIMD "Enable SIMD for WASM" OFF)
  48. # Enable all warnings
  49. option(ENABLE_ALL_WARNINGS "Enable all warnings and warnings as errors" ON)
  50. # Setting to periodically trace broadphase stats to help determine if the broadphase layer configuration is optimal
  51. option(TRACK_BROADPHASE_STATS "Track Broadphase Stats" OFF)
  52. # Setting to periodically trace narrowphase stats to help determine which collision queries could be optimized
  53. option(TRACK_NARROWPHASE_STATS "Track Narrowphase Stats" OFF)
  54. # Enable the debug renderer in the Debug and Release builds. Note that DEBUG_RENDERER_IN_DISTRIBUTION will override this setting.
  55. option(DEBUG_RENDERER_IN_DEBUG_AND_RELEASE "Enable debug renderer in Debug and Release builds" ON)
  56. # Setting to enable the debug renderer in all builds.
  57. # Note that enabling this reduces the performance of the library even if you're not drawing anything.
  58. option(DEBUG_RENDERER_IN_DISTRIBUTION "Enable debug renderer in all builds" OFF)
  59. # Enable the profiler in Debug and Release builds. Note that PROFILER_IN_DISTRIBUTION will override this setting.
  60. option(PROFILER_IN_DEBUG_AND_RELEASE "Enable the profiler in Debug and Release builds" ON)
  61. # Enable the profiler in all builds.
  62. # Note that enabling this reduces the performance of the library.
  63. option(PROFILER_IN_DISTRIBUTION "Enable the profiler in all builds" OFF)
  64. # Setting this option will force the library to use malloc/free instead of allowing the user to override the memory allocator
  65. option(DISABLE_CUSTOM_ALLOCATOR "Disable support for a custom memory allocator" OFF)
  66. # Setting this option will force the library to use the STL vector instead of the custom Array class
  67. option(USE_STD_VECTOR "Use std::vector instead of own Array class" OFF)
  68. # Setting this option will compile the ObjectStream class and RTTI attribute information
  69. option(ENABLE_OBJECT_STREAM "Compile the ObjectStream class and RTTI attribute information" ON)
  70. # Enable installation
  71. option(ENABLE_INSTALL "Generate installation target" ON)
  72. include(CMakeDependentOption)
  73. # Ability to toggle between the static and DLL versions of the MSVC runtime library
  74. # Windows Store only supports the DLL version
  75. cmake_dependent_option(USE_STATIC_MSVC_RUNTIME_LIBRARY "Use the static MSVC runtime library" ON "MSVC;NOT WINDOWS_STORE" OFF)
  76. # Determine which configurations exist
  77. if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # Only do this when we're at the top level, see: https://gitlab.kitware.com/cmake/cmake/-/issues/24181
  78. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  79. set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution")
  80. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  81. set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseASAN;ReleaseUBSAN;ReleaseTSAN;ReleaseCoverage;Distribution")
  82. endif()
  83. endif()
  84. if (MSVC)
  85. # Fill in the path to the asan libraries
  86. set(CLANG_LIB_PATH "\"$(VSInstallDir)\\VC\\Tools\\Llvm\\x64\\lib\\clang\\${CMAKE_CXX_COMPILER_VERSION}\\lib\\windows\"")
  87. # 64 bit architecture
  88. set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64")
  89. # Set runtime library
  90. if (USE_STATIC_MSVC_RUNTIME_LIBRARY)
  91. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  92. endif()
  93. # Set general compiler flags
  94. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus /Gm- /MP /nologo /diagnostics:classic /FC /fp:except- /Zc:inline")
  95. # Enable warnings
  96. if (ENABLE_ALL_WARNINGS)
  97. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall /WX")
  98. endif()
  99. # Optionally generate debug symbols
  100. if (GENERATE_DEBUG_SYMBOLS)
  101. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
  102. endif()
  103. if (NOT CPP_RTTI_ENABLED)
  104. # Set compiler flag for disabling RTTI
  105. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
  106. else()
  107. # Set compiler flag for enabling RTTI
  108. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR")
  109. endif()
  110. if (NOT CPP_EXCEPTIONS_ENABLED)
  111. # Remove any existing compiler flag that enables exceptions
  112. string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  113. # Disable warning about STL and compiler-generated types using noexcept when exceptions are disabled
  114. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4577")
  115. else()
  116. # Enable exceptions
  117. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
  118. endif()
  119. # Set compiler flags for various configurations
  120. if (OVERRIDE_CXX_FLAGS)
  121. set(CMAKE_CXX_FLAGS_DEBUG "/GS /Od /Ob0 /RTC1")
  122. set(CMAKE_CXX_FLAGS_RELEASE "/GS- /Gy /O2 /Oi /Ot")
  123. endif()
  124. set(CMAKE_CXX_FLAGS_DISTRIBUTION "${CMAKE_CXX_FLAGS_RELEASE}")
  125. set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address /Od")
  126. set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion,float-divide-by-zero,local-bounds -fno-sanitize-recover=all")
  127. set(CMAKE_CXX_FLAGS_RELEASETSAN "${CMAKE_CXX_FLAGS_RELEASE} -fsanitize=thread")
  128. set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-fprofile-instr-generate -fcoverage-mapping")
  129. # Set linker flags
  130. set(CMAKE_EXE_LINKER_FLAGS "/SUBSYSTEM:WINDOWS /ignore:4221")
  131. if (GENERATE_DEBUG_SYMBOLS)
  132. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
  133. endif()
  134. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  135. if (CROSS_PLATFORM_DETERMINISTIC)
  136. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise")
  137. else()
  138. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast") # Clang doesn't use fast math because it cannot be turned off inside a single compilation unit
  139. endif()
  140. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  141. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilenames")
  142. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") # Clang emits warnings about unused arguments such as /MP and /GL
  143. set(CMAKE_EXE_LINKER_FLAGS_RELEASEASAN "/SUBSYSTEM:CONSOLE /LIBPATH:${CLANG_LIB_PATH} clang_rt.asan-x86_64.lib -wholearchive:clang_rt.asan-x86_64.lib clang_rt.asan_cxx-x86_64.lib -wholearchive:clang_rt.asan_cxx-x86_64.lib")
  144. set(CMAKE_EXE_LINKER_FLAGS_RELEASEUBSAN "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
  145. set(CMAKE_EXE_LINKER_FLAGS_RELEASETSAN "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
  146. set(CMAKE_EXE_LINKER_FLAGS_RELEASECOVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
  147. endif()
  148. else()
  149. # Enable warnings
  150. if (ENABLE_ALL_WARNINGS)
  151. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
  152. endif()
  153. # Optionally generate debug symbols
  154. if (GENERATE_DEBUG_SYMBOLS)
  155. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g${JPH_DEBUG_SYMBOL_FORMAT}")
  156. endif()
  157. if (NOT CPP_RTTI_ENABLED)
  158. # Set compiler flag for disabling RTTI
  159. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
  160. else()
  161. # Set compiler flag for enabling RTTI
  162. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
  163. endif()
  164. if (NOT CPP_EXCEPTIONS_ENABLED)
  165. # Set compiler flag for disabling exception-handling
  166. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
  167. else()
  168. # Set compiler flag for enabling exception-handling
  169. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
  170. endif()
  171. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  172. # Also disable -Wstringop-overflow or it will generate false positives that can't be disabled from code when link-time optimizations are enabled
  173. # Also turn off automatic fused multiply add contractions, there doesn't seem to be a way to do this selectively through the macro JPH_PRECISE_MATH_OFF
  174. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow -ffp-contract=off")
  175. else()
  176. # Do not use -ffast-math since it cannot be turned off in a single compilation unit under clang, see Core.h
  177. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffp-model=precise")
  178. # On clang 14 and later we can turn off float contraction through a pragma, older versions and deterministic versions need it off always, see Core.h
  179. if (CMAKE_CXX_COMPILER_VERSION LESS 14 OR CROSS_PLATFORM_DETERMINISTIC)
  180. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffp-contract=off")
  181. endif()
  182. # Cross compiler flags
  183. if (CROSS_COMPILE_ARM)
  184. set(CMAKE_CXX_FLAGS "--target=aarch64-linux-gnu ${CMAKE_CXX_FLAGS}")
  185. endif()
  186. endif()
  187. # See https://github.com/jrouwe/JoltPhysics/issues/922. When compiling with DOUBLE_PRECISION=YES and CMAKE_OSX_DEPLOYMENT_TARGET=10.12 clang triggers a warning that we silence here.
  188. if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  189. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-allocation")
  190. endif()
  191. # Set compiler flags for various configurations
  192. if (OVERRIDE_CXX_FLAGS)
  193. set(CMAKE_CXX_FLAGS_DEBUG "")
  194. set(CMAKE_CXX_FLAGS_RELEASE "-O3")
  195. endif()
  196. set(CMAKE_CXX_FLAGS_DISTRIBUTION "${CMAKE_CXX_FLAGS_RELEASE}")
  197. set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address")
  198. set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion,float-divide-by-zero,local-bounds -fno-sanitize-recover=all")
  199. set(CMAKE_CXX_FLAGS_RELEASETSAN "${CMAKE_CXX_FLAGS_RELEASE} -fsanitize=thread")
  200. set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-O0 -DJPH_NO_FORCE_INLINE -fprofile-instr-generate -fcoverage-mapping")
  201. endif()
  202. # Set linker flags
  203. set(CMAKE_EXE_LINKER_FLAGS_DISTRIBUTION "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
  204. # Enable link time optimization in Release and Distribution mode if requested and available
  205. function(SET_INTERPROCEDURAL_OPTIMIZATION)
  206. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF PARENT_SCOPE)
  207. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DISTRIBUTION OFF PARENT_SCOPE)
  208. # On ARM, whole program optimization triggers an internal compiler error during code gen, so we don't turn it on
  209. # When compiling as a shared lib with MinGW, turning on LTO causes errors of the form 'ld.exe: cannot export symbol X wrong type (4 vs 3)'
  210. if (INTERPROCEDURAL_OPTIMIZATION AND NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64") AND NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM") AND NOT (MINGW AND BUILD_SHARED_LIBS))
  211. include(CheckIPOSupported)
  212. check_ipo_supported(RESULT IS_IPO_SUPPORTED OUTPUT IPO_CHECK_OUTPUT)
  213. if (IS_IPO_SUPPORTED)
  214. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON PARENT_SCOPE)
  215. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DISTRIBUTION ON PARENT_SCOPE)
  216. else()
  217. message("Warning: Interprocedural optimizations are not supported for this target, turn off the option INTERPROCEDURAL_OPTIMIZATION to disable this warning")
  218. endif()
  219. endif()
  220. endfunction()
  221. SET_INTERPROCEDURAL_OPTIMIZATION()
  222. # Set repository root
  223. set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../)
  224. # Make Jolt Library
  225. include(${PHYSICS_REPO_ROOT}/Jolt/Jolt.cmake)
  226. if (XCODE)
  227. # Ensure that we enable SSE4.2 for the x86_64 build, XCode builds multiple architectures
  228. set_property(TARGET Jolt PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt")
  229. endif()
  230. # Install Jolt library and includes
  231. if (ENABLE_INSTALL)
  232. include(GNUInstallDirs)
  233. install(TARGETS Jolt
  234. EXPORT JoltExport
  235. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  236. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  237. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  238. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  239. foreach(SRC_FILE ${JOLT_PHYSICS_SRC_FILES})
  240. string(REPLACE ${PHYSICS_REPO_ROOT} "" RELATIVE_SRC_FILE ${SRC_FILE})
  241. get_filename_component(DESTINATION_PATH ${RELATIVE_SRC_FILE} DIRECTORY)
  242. if (NOT RELATIVE_SRC_FILE MATCHES "\.cpp")
  243. cmake_path(SET DST_FILE NORMALIZE "${CMAKE_INSTALL_INCLUDEDIR}/${DESTINATION_PATH}")
  244. install(FILES ${SRC_FILE} DESTINATION ${DST_FILE})
  245. endif()
  246. endforeach()
  247. # Export Jolt library
  248. export(TARGETS Jolt
  249. NAMESPACE Jolt::
  250. FILE JoltConfig.cmake)
  251. install(EXPORT JoltExport
  252. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Jolt/
  253. NAMESPACE Jolt::
  254. FILE JoltConfig.cmake)
  255. endif()
  256. # Check if we're the root CMakeLists.txt, if not we are included by another CMake file and we should disable everything except for the main library
  257. if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  258. # Ability to turn ON/OFF individual applications
  259. option(TARGET_UNIT_TESTS "Build Unit Tests" ON)
  260. option(TARGET_HELLO_WORLD "Build Hello World" ON)
  261. option(TARGET_PERFORMANCE_TEST "Build Performance Test" ON)
  262. option(TARGET_SAMPLES "Build Samples" ON)
  263. option(TARGET_VIEWER "Build JoltViewer" ON)
  264. if (TARGET_UNIT_TESTS)
  265. # Create UnitTests executable
  266. include(${PHYSICS_REPO_ROOT}/UnitTests/UnitTests.cmake)
  267. add_executable(UnitTests ${UNIT_TESTS_SRC_FILES})
  268. target_include_directories(UnitTests PUBLIC ${UNIT_TESTS_ROOT})
  269. target_link_libraries(UnitTests LINK_PUBLIC Jolt)
  270. # Code coverage doesn't work when using precompiled headers
  271. if (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" AND MSVC)
  272. # The Ninja Multi-Config generator errors out when selectively disabling precompiled headers for certain configurations.
  273. # See: https://github.com/jrouwe/JoltPhysics/issues/1211
  274. target_precompile_headers(UnitTests PRIVATE "${JOLT_PHYSICS_ROOT}/Jolt.h")
  275. else()
  276. target_precompile_headers(UnitTests PRIVATE "$<$<NOT:$<CONFIG:ReleaseCoverage>>:${JOLT_PHYSICS_ROOT}/Jolt.h>")
  277. endif()
  278. if (MSVC)
  279. target_link_options(UnitTests PUBLIC "/SUBSYSTEM:CONSOLE")
  280. endif()
  281. if (IOS)
  282. # Set the bundle information
  283. set_property(TARGET UnitTests PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/iOS/UnitTestsInfo.plist")
  284. set_property(TARGET UnitTests PROPERTY XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.joltphysics.unittests")
  285. endif()
  286. if (XCODE)
  287. # Ensure that we enable SSE4.2 for the x86_64 build, XCode builds multiple architectures
  288. set_property(TARGET UnitTests PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt")
  289. endif()
  290. # Register unit tests as a test so that it can be run with:
  291. # ctest --output-on-failure
  292. enable_testing()
  293. add_test(UnitTests UnitTests)
  294. endif()
  295. if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
  296. if (TARGET_HELLO_WORLD)
  297. # Example 'Hello World' application
  298. include(${PHYSICS_REPO_ROOT}/HelloWorld/HelloWorld.cmake)
  299. add_executable(HelloWorld ${HELLO_WORLD_SRC_FILES})
  300. target_include_directories(HelloWorld PUBLIC ${HELLO_WORLD_ROOT})
  301. target_link_libraries(HelloWorld LINK_PUBLIC Jolt)
  302. if (MSVC)
  303. target_link_options(HelloWorld PUBLIC "/SUBSYSTEM:CONSOLE")
  304. endif()
  305. endif()
  306. if (TARGET_PERFORMANCE_TEST)
  307. # Performance Test application
  308. include(${PHYSICS_REPO_ROOT}/PerformanceTest/PerformanceTest.cmake)
  309. add_executable(PerformanceTest ${PERFORMANCE_TEST_SRC_FILES})
  310. target_include_directories(PerformanceTest PUBLIC ${PERFORMANCE_TEST_ROOT})
  311. target_link_libraries(PerformanceTest LINK_PUBLIC Jolt)
  312. if (MSVC)
  313. target_link_options(PerformanceTest PUBLIC "/SUBSYSTEM:CONSOLE")
  314. endif()
  315. if (EMSCRIPTEN)
  316. # Embed the assets for the RagdollScene
  317. target_link_options(PerformanceTest PUBLIC "SHELL:--preload-file ${PHYSICS_REPO_ROOT}/Assets/Human.tof@/Assets/Human.tof")
  318. target_link_options(PerformanceTest PUBLIC "SHELL:--preload-file ${PHYSICS_REPO_ROOT}/Assets/Human/dead_pose1.tof@/Assets/Human/dead_pose1.tof")
  319. target_link_options(PerformanceTest PUBLIC "SHELL:--preload-file ${PHYSICS_REPO_ROOT}/Assets/terrain2.bof@/Assets/terrain2.bof")
  320. endif()
  321. set_property(TARGET PerformanceTest PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")
  322. # Copy the assets folder
  323. add_custom_command(TARGET PerformanceTest PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${PHYSICS_REPO_ROOT}/Assets/ $<TARGET_FILE_DIR:PerformanceTest>/Assets/)
  324. endif()
  325. endif()
  326. if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")) # ARM 32-bit is missing dinput8.lib
  327. # Windows only targets
  328. if (TARGET_SAMPLES OR TARGET_VIEWER)
  329. include(${PHYSICS_REPO_ROOT}/TestFramework/TestFramework.cmake)
  330. endif()
  331. if (TARGET_SAMPLES)
  332. include(${PHYSICS_REPO_ROOT}/Samples/Samples.cmake)
  333. endif()
  334. if (TARGET_VIEWER)
  335. include(${PHYSICS_REPO_ROOT}/JoltViewer/JoltViewer.cmake)
  336. endif()
  337. endif()
  338. endif()