CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #
  2. # Tests configuration
  3. #
  4. include(FetchContent)
  5. set(THREADS_PREFER_PTHREAD_FLAG ON)
  6. find_package(Threads REQUIRED)
  7. if(ENTT_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. if(MSVC)
  34. target_compile_options(
  35. ${TARGET_NAME}
  36. PRIVATE
  37. /EHsc /W1 /wd4996 /w14800
  38. $<$<CONFIG:Debug>:/Od>
  39. $<$<CONFIG:Release>:/O2>
  40. )
  41. else()
  42. target_compile_options(
  43. ${TARGET_NAME}
  44. PRIVATE
  45. -pedantic -fvisibility=hidden -Wall -Wshadow -Wno-deprecated-declarations
  46. $<$<CONFIG:Debug>:-O0 -g>
  47. $<$<CONFIG:Release>:-O2>
  48. )
  49. endif()
  50. target_compile_definitions(
  51. ${TARGET_NAME}
  52. PRIVATE
  53. _ENABLE_EXTENDED_ALIGNED_STORAGE
  54. NOMINMAX
  55. ${ARGN}
  56. )
  57. if(ENTT_BUILD_UINT64)
  58. target_compile_definitions(
  59. ${TARGET_NAME}
  60. PRIVATE
  61. ENTT_ID_TYPE=std::uint64_t
  62. )
  63. endif()
  64. endfunction()
  65. add_library(odr OBJECT odr.cpp)
  66. SETUP_TARGET(odr)
  67. function(SETUP_BASIC_TEST TEST_NAME TEST_SOURCES)
  68. add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCES})
  69. target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  70. SETUP_TARGET(${TEST_NAME} ${ARGN})
  71. add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
  72. endfunction()
  73. function(SETUP_LIB_TEST TEST_NAME)
  74. add_library(_${TEST_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/lib.cpp)
  75. SETUP_TARGET(_${TEST_NAME} ENTT_API_EXPORT)
  76. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp ENTT_API_IMPORT)
  77. target_link_libraries(lib_${TEST_NAME} PRIVATE _${TEST_NAME})
  78. endfunction()
  79. function(SETUP_PLUGIN_TEST TEST_NAME)
  80. add_library(_${TEST_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/plugin.cpp)
  81. SETUP_TARGET(_${TEST_NAME} ${ARGVN})
  82. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp PLUGIN="$<TARGET_FILE:_${TEST_NAME}>" ${ARGVN})
  83. target_include_directories(_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  84. target_include_directories(lib_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  85. target_link_libraries(lib_${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS})
  86. endfunction()
  87. # Test benchmark
  88. if(ENTT_BUILD_BENCHMARK)
  89. SETUP_BASIC_TEST(benchmark benchmark/benchmark.cpp)
  90. endif()
  91. # Test example
  92. if(ENTT_BUILD_EXAMPLE)
  93. SETUP_BASIC_TEST(custom_identifier example/custom_identifier.cpp)
  94. SETUP_BASIC_TEST(signal_less example/signal_less.cpp)
  95. endif()
  96. # Test lib
  97. if(ENTT_BUILD_LIB)
  98. FetchContent_Declare(
  99. cr
  100. GIT_REPOSITORY https://github.com/fungos/cr.git
  101. GIT_TAG master
  102. GIT_SHALLOW 1
  103. )
  104. FetchContent_GetProperties(cr)
  105. if(NOT cr_POPULATED)
  106. FetchContent_Populate(cr)
  107. set(cr_INCLUDE_DIR ${cr_SOURCE_DIR})
  108. endif()
  109. SETUP_LIB_TEST(dispatcher)
  110. SETUP_LIB_TEST(emitter)
  111. SETUP_LIB_TEST(meta)
  112. SETUP_LIB_TEST(registry)
  113. SETUP_PLUGIN_TEST(dispatcher_plugin)
  114. SETUP_PLUGIN_TEST(emitter_plugin)
  115. SETUP_PLUGIN_TEST(meta_plugin)
  116. SETUP_PLUGIN_TEST(registry_plugin)
  117. SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP)
  118. endif()
  119. # Test snapshot
  120. if(ENTT_BUILD_SNAPSHOT)
  121. FetchContent_Declare(
  122. cereal
  123. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  124. GIT_TAG v1.2.2
  125. GIT_SHALLOW 1
  126. )
  127. FetchContent_GetProperties(cereal)
  128. if(NOT cereal_POPULATED)
  129. FetchContent_Populate(cereal)
  130. set(cereal_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)
  131. endif()
  132. SETUP_BASIC_TEST(cereal snapshot/snapshot.cpp)
  133. target_include_directories(cereal PRIVATE ${cereal_INCLUDE_DIR})
  134. endif()
  135. # Test core
  136. SETUP_BASIC_TEST(algorithm entt/core/algorithm.cpp)
  137. SETUP_BASIC_TEST(any entt/core/any.cpp)
  138. SETUP_BASIC_TEST(family entt/core/family.cpp)
  139. SETUP_BASIC_TEST(hashed_string entt/core/hashed_string.cpp)
  140. SETUP_BASIC_TEST(ident entt/core/ident.cpp)
  141. SETUP_BASIC_TEST(monostate entt/core/monostate.cpp)
  142. SETUP_BASIC_TEST(type_info entt/core/type_info.cpp)
  143. SETUP_BASIC_TEST(type_traits entt/core/type_traits.cpp)
  144. SETUP_BASIC_TEST(utility entt/core/utility.cpp)
  145. # Test entity
  146. SETUP_BASIC_TEST(entity entt/entity/entity.cpp)
  147. SETUP_BASIC_TEST(group entt/entity/group.cpp)
  148. SETUP_BASIC_TEST(handle entt/entity/handle.cpp)
  149. SETUP_BASIC_TEST(helper entt/entity/helper.cpp)
  150. SETUP_BASIC_TEST(observer entt/entity/observer.cpp)
  151. SETUP_BASIC_TEST(poly_storage entt/entity/poly_storage.cpp)
  152. SETUP_BASIC_TEST(organizer entt/entity/organizer.cpp)
  153. SETUP_BASIC_TEST(registry entt/entity/registry.cpp)
  154. SETUP_BASIC_TEST(registry_no_eto entt/entity/registry_no_eto.cpp ENTT_NO_ETO)
  155. SETUP_BASIC_TEST(runtime_view entt/entity/runtime_view.cpp)
  156. SETUP_BASIC_TEST(snapshot entt/entity/snapshot.cpp)
  157. SETUP_BASIC_TEST(sparse_set entt/entity/sparse_set.cpp)
  158. SETUP_BASIC_TEST(storage entt/entity/storage.cpp)
  159. SETUP_BASIC_TEST(view entt/entity/view.cpp)
  160. # Test locator
  161. SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
  162. # Test meta
  163. SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
  164. SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp)
  165. SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp)
  166. SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp)
  167. SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp)
  168. SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp)
  169. SETUP_BASIC_TEST(meta_dtor entt/meta/meta_dtor.cpp)
  170. SETUP_BASIC_TEST(meta_func entt/meta/meta_func.cpp)
  171. SETUP_BASIC_TEST(meta_handle entt/meta/meta_handle.cpp)
  172. SETUP_BASIC_TEST(meta_pointer entt/meta/meta_pointer.cpp)
  173. SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp)
  174. SETUP_BASIC_TEST(meta_range entt/meta/meta_range.cpp)
  175. SETUP_BASIC_TEST(meta_template entt/meta/meta_template.cpp)
  176. SETUP_BASIC_TEST(meta_type entt/meta/meta_type.cpp)
  177. # Test poly
  178. SETUP_BASIC_TEST(poly_deduced entt/poly/poly_deduced.cpp)
  179. SETUP_BASIC_TEST(poly_defined entt/poly/poly_defined.cpp)
  180. # Test process
  181. SETUP_BASIC_TEST(process entt/process/process.cpp)
  182. SETUP_BASIC_TEST(scheduler entt/process/scheduler.cpp)
  183. # Test resource
  184. SETUP_BASIC_TEST(resource entt/resource/resource.cpp)
  185. # Test signal
  186. SETUP_BASIC_TEST(delegate entt/signal/delegate.cpp)
  187. SETUP_BASIC_TEST(dispatcher entt/signal/dispatcher.cpp)
  188. SETUP_BASIC_TEST(emitter entt/signal/emitter.cpp)
  189. SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)