CMakeLists.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
  2. # Enable assertions in JoltPhysics
  3. option(USE_ASSERTS "Enable asserts" OFF)
  4. # When turning this option on, the library will be compiled using doubles for positions. This allows for much bigger worlds.
  5. option(DOUBLE_PRECISION "Use double precision math" OFF)
  6. # Number of bits to use in ObjectLayer. Can be 16 or 32.
  7. option(OBJECT_LAYER_BITS "Number of bits in ObjectLayer" 16)
  8. include(CMakeDependentOption)
  9. # Ability to toggle between the static and DLL versions of the MSVC runtime library
  10. # Windows Store only supports the DLL version
  11. cmake_dependent_option(USE_STATIC_MSVC_RUNTIME_LIBRARY "Use the static MSVC runtime library" ON "MSVC;NOT WINDOWS_STORE" OFF)
  12. if (USE_STATIC_MSVC_RUNTIME_LIBRARY)
  13. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  14. endif()
  15. # Only do this when we're at the top level, see: https://gitlab.kitware.com/cmake/cmake/-/issues/24181
  16. if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  17. set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
  18. endif()
  19. project(JoltC VERSION 0.1
  20. DESCRIPTION "C Wrapper for Jolt Physics"
  21. LANGUAGES C CXX)
  22. add_library(joltc STATIC
  23. # C Interface
  24. JoltC/JoltC.h
  25. JoltC/Enums.h
  26. JoltC/Functions.h
  27. JoltC/Generated.h
  28. # C++ Implementation
  29. JoltCImpl/Test.cpp
  30. JoltCImpl/JoltC.cpp
  31. JoltCImpl/Generated.h
  32. )
  33. target_compile_features(joltc PUBLIC cxx_std_17)
  34. target_include_directories(joltc PUBLIC . JoltPhysics)
  35. target_link_libraries(joltc PUBLIC Jolt)
  36. install(TARGETS joltc DESTINATION lib)
  37. if(MSVC)
  38. target_compile_options(joltc PRIVATE /W4)
  39. # Enable debug symbols
  40. target_compile_options(joltc PRIVATE /Zi)
  41. # Ignore 'unreferenced function with internal linkage'
  42. target_compile_options(joltc PRIVATE /wd4505)
  43. else()
  44. target_compile_options(joltc PRIVATE -Wall -Wextra -Wpedantic -fno-rtti)
  45. endif()
  46. if (DOUBLE_PRECISION)
  47. target_compile_definitions(joltc PUBLIC JPC_DOUBLE_PRECISION)
  48. endif()
  49. if (OBJECT_LAYER_BITS)
  50. target_compile_definitions(joltc PUBLIC JPC_OBJECT_LAYER_BITS=${OBJECT_LAYER_BITS})
  51. endif()
  52. if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  53. add_executable(HelloWorld
  54. HelloWorld/main.cpp
  55. )
  56. # cxx_std_20 gives us designated initializers, bringing us closer to Actual C.
  57. target_compile_features(HelloWorld PRIVATE cxx_std_20)
  58. # Eventually we should switch back to Actual C:
  59. # set_property(TARGET HelloWorld PROPERTY C_STANDARD 23)
  60. target_include_directories(HelloWorld PUBLIC .)
  61. target_link_libraries(HelloWorld PUBLIC joltc)
  62. endif()
  63. add_subdirectory(JoltPhysics/Build)