CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #
  2. # Tests configuration
  3. #
  4. include(FetchContent)
  5. set(THREADS_PREFER_PTHREAD_FLAG ON)
  6. find_package(Threads REQUIRED)
  7. if(FIND_GTEST_PACKAGE)
  8. find_package(GTest REQUIRED)
  9. else()
  10. FetchContent_Declare(
  11. googletest
  12. GIT_REPOSITORY https://github.com/google/googletest.git
  13. GIT_TAG master
  14. GIT_SHALLOW 1
  15. )
  16. FetchContent_GetProperties(googletest)
  17. if(NOT googletest_POPULATED)
  18. FetchContent_Populate(googletest)
  19. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  20. add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
  21. endif()
  22. add_library(GTest::Main ALIAS gtest_main)
  23. target_compile_features(gtest PUBLIC cxx_std_17)
  24. target_compile_features(gtest_main PUBLIC cxx_std_17)
  25. target_compile_features(gmock PUBLIC cxx_std_17)
  26. target_compile_features(gmock_main PUBLIC cxx_std_17)
  27. endif()
  28. include_directories($<TARGET_PROPERTY:EnTT,INTERFACE_INCLUDE_DIRECTORIES>)
  29. add_compile_options($<TARGET_PROPERTY:EnTT,INTERFACE_COMPILE_OPTIONS>)
  30. function(SETUP_TARGET TARGET_NAME)
  31. set_target_properties(${TARGET_NAME} PROPERTIES CXX_EXTENSIONS OFF)
  32. target_link_libraries(${TARGET_NAME} PRIVATE EnTT)
  33. target_compile_options(
  34. ${TARGET_NAME}
  35. PRIVATE
  36. $<$<NOT:$<PLATFORM_ID:Windows>>:-pedantic -fvisibility=hidden -Wall -Wshadow -Wno-deprecated-declarations>
  37. $<$<PLATFORM_ID:Windows>:/EHsc /W1 /wd4996 /w14800>
  38. )
  39. target_compile_options(
  40. ${TARGET_NAME}
  41. PRIVATE
  42. $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-O0 -g>
  43. $<$<AND:$<CONFIG:Release>,$<NOT:$<PLATFORM_ID:Windows>>>:-O2>
  44. $<$<AND:$<CONFIG:Debug>,$<PLATFORM_ID:Windows>>:/Od>
  45. $<$<AND:$<CONFIG:Release>,$<PLATFORM_ID:Windows>>:/O2>
  46. )
  47. target_compile_definitions(${TARGET_NAME} PRIVATE ENTT_STANDALONE ${ARGN})
  48. endfunction()
  49. add_library(odr OBJECT odr.cpp)
  50. SETUP_TARGET(odr)
  51. function(SETUP_BASIC_TEST TEST_NAME TEST_SOURCES)
  52. add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCES})
  53. target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  54. SETUP_TARGET(${TEST_NAME} ${ARGN})
  55. add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
  56. endfunction()
  57. function(SETUP_LIB_TEST TEST_NAME)
  58. add_library(_${TEST_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/lib.cpp)
  59. SETUP_TARGET(_${TEST_NAME} ENTT_API_EXPORT)
  60. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp ENTT_API_IMPORT)
  61. target_link_libraries(lib_${TEST_NAME} PRIVATE _${TEST_NAME})
  62. endfunction()
  63. function(SETUP_PLUGIN_TEST TEST_NAME)
  64. add_library(_${TEST_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/plugin.cpp)
  65. SETUP_TARGET(_${TEST_NAME} NOMINMAX ${ARGVN})
  66. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp NOMINMAX PLUGIN="$<TARGET_FILE:_${TEST_NAME}>" ${ARGVN})
  67. target_include_directories(_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  68. target_include_directories(lib_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  69. target_link_libraries(lib_${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS})
  70. endfunction()
  71. # Test benchmark
  72. if(BUILD_BENCHMARK)
  73. SETUP_BASIC_TEST(benchmark benchmark/benchmark.cpp)
  74. endif()
  75. # Test example
  76. if(BUILD_EXAMPLE)
  77. SETUP_BASIC_TEST(custom_identifier example/custom_identifier.cpp)
  78. endif()
  79. # Test lib
  80. if(BUILD_LIB)
  81. FetchContent_Declare(
  82. cr
  83. GIT_REPOSITORY https://github.com/fungos/cr.git
  84. GIT_TAG master
  85. GIT_SHALLOW 1
  86. )
  87. FetchContent_GetProperties(cr)
  88. if(NOT cr_POPULATED)
  89. FetchContent_Populate(cr)
  90. set(cr_INCLUDE_DIR ${cr_SOURCE_DIR})
  91. endif()
  92. SETUP_LIB_TEST(dispatcher)
  93. SETUP_LIB_TEST(emitter)
  94. SETUP_LIB_TEST(meta)
  95. SETUP_LIB_TEST(registry)
  96. SETUP_PLUGIN_TEST(dispatcher_plugin)
  97. SETUP_PLUGIN_TEST(emitter_plugin)
  98. SETUP_PLUGIN_TEST(meta_plugin)
  99. SETUP_PLUGIN_TEST(registry_plugin)
  100. SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP)
  101. endif()
  102. # Test snapshot
  103. if(BUILD_SNAPSHOT)
  104. FetchContent_Declare(
  105. cereal
  106. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  107. GIT_TAG v1.2.2
  108. GIT_SHALLOW 1
  109. )
  110. FetchContent_GetProperties(cereal)
  111. if(NOT cereal_POPULATED)
  112. FetchContent_Populate(cereal)
  113. set(cereal_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)
  114. endif()
  115. SETUP_BASIC_TEST(cereal snapshot/snapshot.cpp)
  116. target_include_directories(cereal PRIVATE ${cereal_INCLUDE_DIR})
  117. endif()
  118. # Test core
  119. SETUP_BASIC_TEST(algorithm entt/core/algorithm.cpp)
  120. SETUP_BASIC_TEST(family entt/core/family.cpp)
  121. SETUP_BASIC_TEST(hashed_string entt/core/hashed_string.cpp)
  122. SETUP_BASIC_TEST(ident entt/core/ident.cpp)
  123. SETUP_BASIC_TEST(monostate entt/core/monostate.cpp)
  124. SETUP_BASIC_TEST(type_info entt/core/type_info.cpp)
  125. SETUP_BASIC_TEST(type_traits entt/core/type_traits.cpp)
  126. SETUP_BASIC_TEST(utility entt/core/utility.cpp)
  127. # Test entity
  128. SETUP_BASIC_TEST(entity entt/entity/entity.cpp)
  129. SETUP_BASIC_TEST(group entt/entity/group.cpp)
  130. SETUP_BASIC_TEST(handle entt/entity/handle.cpp)
  131. SETUP_BASIC_TEST(helper entt/entity/helper.cpp)
  132. SETUP_BASIC_TEST(observer entt/entity/observer.cpp)
  133. SETUP_BASIC_TEST(organizer entt/entity/organizer.cpp)
  134. SETUP_BASIC_TEST(registry entt/entity/registry.cpp)
  135. SETUP_BASIC_TEST(registry_no_eto entt/entity/registry_no_eto.cpp ENTT_NO_ETO)
  136. SETUP_BASIC_TEST(runtime_view entt/entity/runtime_view.cpp)
  137. SETUP_BASIC_TEST(snapshot entt/entity/snapshot.cpp)
  138. SETUP_BASIC_TEST(sparse_set entt/entity/sparse_set.cpp)
  139. SETUP_BASIC_TEST(storage entt/entity/storage.cpp)
  140. SETUP_BASIC_TEST(view entt/entity/view.cpp)
  141. # Test locator
  142. SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
  143. # Test meta
  144. SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
  145. SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp)
  146. SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp)
  147. SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp)
  148. SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp)
  149. SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp)
  150. SETUP_BASIC_TEST(meta_func entt/meta/meta_func.cpp)
  151. SETUP_BASIC_TEST(meta_pointer entt/meta/meta_pointer.cpp)
  152. SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp)
  153. SETUP_BASIC_TEST(meta_range entt/meta/meta_range.cpp)
  154. SETUP_BASIC_TEST(meta_type entt/meta/meta_type.cpp)
  155. # Test process
  156. SETUP_BASIC_TEST(process entt/process/process.cpp)
  157. SETUP_BASIC_TEST(scheduler entt/process/scheduler.cpp)
  158. # Test resource
  159. SETUP_BASIC_TEST(resource entt/resource/resource.cpp)
  160. # Test signal
  161. SETUP_BASIC_TEST(delegate entt/signal/delegate.cpp)
  162. SETUP_BASIC_TEST(dispatcher entt/signal/dispatcher.cpp)
  163. SETUP_BASIC_TEST(emitter entt/signal/emitter.cpp)
  164. SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)