CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Tests CMakeLists.txt
  2. include(FetchContent)
  3. # Fetch GoogleTest
  4. FetchContent_Declare(
  5. googletest
  6. GIT_REPOSITORY https://github.com/google/googletest.git
  7. GIT_TAG v1.14.0
  8. )
  9. # For Windows: Prevent overriding the parent project's compiler/linker settings
  10. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  11. FetchContent_MakeAvailable(googletest)
  12. # Enable testing
  13. enable_testing()
  14. # Collect all test source files
  15. set(TEST_SOURCES
  16. test_math.cpp
  17. test_core.cpp
  18. test_shapes.cpp
  19. test_physics_system.cpp
  20. test_collision.cpp
  21. test_constraints.cpp
  22. test_character.cpp
  23. test_vehicle.cpp
  24. test_skeleton.cpp
  25. )
  26. # Create test executable
  27. add_executable(joltc_tests ${TEST_SOURCES})
  28. # Ensure console subsystem on Windows (required for gtest_main)
  29. if(MSVC)
  30. target_link_options(joltc_tests PRIVATE /SUBSYSTEM:CONSOLE)
  31. endif()
  32. target_link_libraries(joltc_tests
  33. PRIVATE
  34. ${TARGET_NAME}
  35. GTest::gtest
  36. GTest::gtest_main
  37. )
  38. target_include_directories(joltc_tests
  39. PRIVATE
  40. ${CMAKE_SOURCE_DIR}/include
  41. )
  42. # Add tests to CTest (skip discovery for cross-compilation or when target arch differs from host)
  43. include(GoogleTest)
  44. # Detect cross-compilation scenarios where test discovery won't work
  45. set(SKIP_TEST_DISCOVERY FALSE)
  46. if(CMAKE_CROSSCOMPILING)
  47. set(SKIP_TEST_DISCOVERY TRUE)
  48. elseif(MSVC AND CMAKE_GENERATOR_PLATFORM)
  49. # Visual Studio: check if target platform differs from host
  50. if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
  51. set(SKIP_TEST_DISCOVERY TRUE)
  52. endif()
  53. endif()
  54. if(SKIP_TEST_DISCOVERY)
  55. # For cross-compilation, just add the test executable without discovery
  56. add_test(NAME joltc_tests COMMAND joltc_tests)
  57. else()
  58. gtest_discover_tests(joltc_tests)
  59. endif()