CMakeLists.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. endfunction()
  58. add_library(odr OBJECT odr.cpp)
  59. SETUP_TARGET(odr)
  60. function(SETUP_BASIC_TEST TEST_NAME TEST_SOURCES)
  61. add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCES})
  62. target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  63. SETUP_TARGET(${TEST_NAME} ${ARGN})
  64. add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
  65. endfunction()
  66. function(SETUP_LIB_TEST TEST_NAME)
  67. add_library(_${TEST_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/lib.cpp)
  68. SETUP_TARGET(_${TEST_NAME} ENTT_API_EXPORT)
  69. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp ENTT_API_IMPORT)
  70. target_link_libraries(lib_${TEST_NAME} PRIVATE _${TEST_NAME})
  71. endfunction()
  72. function(SETUP_PLUGIN_TEST TEST_NAME)
  73. add_library(_${TEST_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/plugin.cpp)
  74. SETUP_TARGET(_${TEST_NAME} ${ARGVN})
  75. SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp PLUGIN="$<TARGET_FILE:_${TEST_NAME}>" ${ARGVN})
  76. target_include_directories(_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  77. target_include_directories(lib_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR})
  78. target_link_libraries(lib_${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS})
  79. endfunction()
  80. # Test benchmark
  81. if(ENTT_BUILD_BENCHMARK)
  82. SETUP_BASIC_TEST(benchmark benchmark/benchmark.cpp)
  83. endif()
  84. # Test example
  85. if(ENTT_BUILD_EXAMPLE)
  86. SETUP_BASIC_TEST(custom_identifier example/custom_identifier.cpp)
  87. SETUP_BASIC_TEST(signal_less example/signal_less.cpp)
  88. endif()
  89. # Test lib
  90. if(ENTT_BUILD_LIB)
  91. FetchContent_Declare(
  92. cr
  93. GIT_REPOSITORY https://github.com/fungos/cr.git
  94. GIT_TAG master
  95. GIT_SHALLOW 1
  96. )
  97. FetchContent_GetProperties(cr)
  98. if(NOT cr_POPULATED)
  99. FetchContent_Populate(cr)
  100. set(cr_INCLUDE_DIR ${cr_SOURCE_DIR})
  101. endif()
  102. SETUP_LIB_TEST(dispatcher)
  103. SETUP_LIB_TEST(emitter)
  104. SETUP_LIB_TEST(meta)
  105. SETUP_LIB_TEST(registry)
  106. SETUP_PLUGIN_TEST(dispatcher_plugin)
  107. SETUP_PLUGIN_TEST(emitter_plugin)
  108. SETUP_PLUGIN_TEST(meta_plugin)
  109. SETUP_PLUGIN_TEST(registry_plugin)
  110. SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP)
  111. endif()
  112. # Test snapshot
  113. if(ENTT_BUILD_SNAPSHOT)
  114. FetchContent_Declare(
  115. cereal
  116. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  117. GIT_TAG v1.2.2
  118. GIT_SHALLOW 1
  119. )
  120. FetchContent_GetProperties(cereal)
  121. if(NOT cereal_POPULATED)
  122. FetchContent_Populate(cereal)
  123. set(cereal_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)
  124. endif()
  125. SETUP_BASIC_TEST(cereal snapshot/snapshot.cpp)
  126. target_include_directories(cereal PRIVATE ${cereal_INCLUDE_DIR})
  127. endif()
  128. # Test core
  129. SETUP_BASIC_TEST(algorithm entt/core/algorithm.cpp)
  130. SETUP_BASIC_TEST(any entt/core/any.cpp)
  131. SETUP_BASIC_TEST(family entt/core/family.cpp)
  132. SETUP_BASIC_TEST(hashed_string entt/core/hashed_string.cpp)
  133. SETUP_BASIC_TEST(ident entt/core/ident.cpp)
  134. SETUP_BASIC_TEST(monostate entt/core/monostate.cpp)
  135. SETUP_BASIC_TEST(type_info entt/core/type_info.cpp)
  136. SETUP_BASIC_TEST(type_traits entt/core/type_traits.cpp)
  137. SETUP_BASIC_TEST(utility entt/core/utility.cpp)
  138. # Test entity
  139. SETUP_BASIC_TEST(entity entt/entity/entity.cpp)
  140. SETUP_BASIC_TEST(group entt/entity/group.cpp)
  141. SETUP_BASIC_TEST(handle entt/entity/handle.cpp)
  142. SETUP_BASIC_TEST(helper entt/entity/helper.cpp)
  143. SETUP_BASIC_TEST(observer entt/entity/observer.cpp)
  144. SETUP_BASIC_TEST(poly_storage entt/entity/poly_storage.cpp)
  145. SETUP_BASIC_TEST(organizer entt/entity/organizer.cpp)
  146. SETUP_BASIC_TEST(registry entt/entity/registry.cpp)
  147. SETUP_BASIC_TEST(registry_no_eto entt/entity/registry_no_eto.cpp ENTT_NO_ETO)
  148. SETUP_BASIC_TEST(runtime_view entt/entity/runtime_view.cpp)
  149. SETUP_BASIC_TEST(snapshot entt/entity/snapshot.cpp)
  150. SETUP_BASIC_TEST(sparse_set entt/entity/sparse_set.cpp)
  151. SETUP_BASIC_TEST(storage entt/entity/storage.cpp)
  152. SETUP_BASIC_TEST(view entt/entity/view.cpp)
  153. # Test locator
  154. SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
  155. # Test meta
  156. SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
  157. SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp)
  158. SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp)
  159. SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp)
  160. SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp)
  161. SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp)
  162. SETUP_BASIC_TEST(meta_dtor entt/meta/meta_dtor.cpp)
  163. SETUP_BASIC_TEST(meta_func entt/meta/meta_func.cpp)
  164. SETUP_BASIC_TEST(meta_handle entt/meta/meta_handle.cpp)
  165. SETUP_BASIC_TEST(meta_pointer entt/meta/meta_pointer.cpp)
  166. SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp)
  167. SETUP_BASIC_TEST(meta_range entt/meta/meta_range.cpp)
  168. SETUP_BASIC_TEST(meta_template entt/meta/meta_template.cpp)
  169. SETUP_BASIC_TEST(meta_type entt/meta/meta_type.cpp)
  170. # Test poly
  171. SETUP_BASIC_TEST(poly_deduced entt/poly/poly_deduced.cpp)
  172. SETUP_BASIC_TEST(poly_defined entt/poly/poly_defined.cpp)
  173. # Test process
  174. SETUP_BASIC_TEST(process entt/process/process.cpp)
  175. SETUP_BASIC_TEST(scheduler entt/process/scheduler.cpp)
  176. # Test resource
  177. SETUP_BASIC_TEST(resource entt/resource/resource.cpp)
  178. # Test signal
  179. SETUP_BASIC_TEST(delegate entt/signal/delegate.cpp)
  180. SETUP_BASIC_TEST(dispatcher entt/signal/dispatcher.cpp)
  181. SETUP_BASIC_TEST(emitter entt/signal/emitter.cpp)
  182. SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)