CMakeLists.txt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #
  2. # Tests configuration
  3. #
  4. include(FetchContent)
  5. include(CheckCXXSourceCompiles)
  6. check_cxx_source_compiles("
  7. #include<version>
  8. int main() { return 0; }
  9. " ENTT_HAS_HEADER_VERSION)
  10. set(THREADS_PREFER_PTHREAD_FLAG ON)
  11. find_package(Threads REQUIRED)
  12. if(ENTT_FIND_GTEST_PACKAGE)
  13. find_package(GTest REQUIRED)
  14. else()
  15. FetchContent_Declare(
  16. googletest
  17. GIT_REPOSITORY https://github.com/google/googletest.git
  18. GIT_TAG main
  19. GIT_SHALLOW 1
  20. )
  21. FetchContent_GetProperties(googletest)
  22. if(NOT googletest_POPULATED)
  23. FetchContent_Populate(googletest)
  24. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  25. add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
  26. endif()
  27. add_library(GTest::Main ALIAS gtest_main)
  28. target_compile_features(gtest PUBLIC cxx_std_17)
  29. target_compile_features(gtest_main PUBLIC cxx_std_17)
  30. target_compile_features(gmock PUBLIC cxx_std_17)
  31. target_compile_features(gmock_main PUBLIC cxx_std_17)
  32. endif()
  33. include_directories($<TARGET_PROPERTY:EnTT,INTERFACE_INCLUDE_DIRECTORIES>)
  34. add_compile_options($<TARGET_PROPERTY:EnTT,INTERFACE_COMPILE_OPTIONS>)
  35. function(SETUP_TARGET TARGET_NAME)
  36. set_target_properties(${TARGET_NAME} PROPERTIES CXX_EXTENSIONS OFF)
  37. target_compile_features(${TARGET_NAME} PRIVATE ${ENTT_CXX_STD})
  38. target_link_libraries(${TARGET_NAME} PRIVATE EnTT)
  39. if(MSVC)
  40. target_compile_options(
  41. ${TARGET_NAME}
  42. PRIVATE
  43. # vs2017 emits too many false positives for my tastes
  44. $<IF:$<EQUAL:${MSVC_TOOLSET_VERSION},141>, /W1, /W4>
  45. # clang-cl goes a little wrong with some warnings instead
  46. $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","Clang">:
  47. -Wno-deprecated-declarations
  48. -Wno-ignored-qualifiers
  49. -Wno-unknown-warning-option
  50. -Wno-exceptions
  51. -Wno-unused-local-typedef
  52. -Wno-unused-private-field
  53. >
  54. # documentation diagnostic turned on for clang-cl only
  55. $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","Clang">:-Wdocumentation>
  56. /EHsc /wd4324 /wd4996
  57. $<$<CONFIG:Debug>:/Od>
  58. $<$<CONFIG:Release>:/O2>
  59. )
  60. else()
  61. target_compile_options(
  62. ${TARGET_NAME}
  63. PRIVATE
  64. -pedantic -fvisibility=hidden -Wall -Wshadow -Wno-deprecated-declarations
  65. $<$<CONFIG:Debug>:-O0 -g>
  66. $<$<CONFIG:Release>:-O2>
  67. )
  68. endif()
  69. target_compile_definitions(
  70. ${TARGET_NAME}
  71. PRIVATE
  72. ENTT_ID_TYPE=${ENTT_ID_TYPE}
  73. _ENABLE_EXTENDED_ALIGNED_STORAGE
  74. NOMINMAX
  75. ${ARGN}
  76. )
  77. if(ENTT_HAS_HEADER_VERSION)
  78. target_compile_definitions(
  79. ${TARGET_NAME}
  80. PRIVATE
  81. ENTT_HAS_HEADER_VERSION
  82. )
  83. endif()
  84. endfunction()
  85. add_library(odr OBJECT odr.cpp)
  86. set_target_properties(odr PROPERTIES POSITION_INDEPENDENT_CODE ON)
  87. SETUP_TARGET(odr)
  88. function(SETUP_BASIC_TEST TEST_NAME TEST_SOURCES)
  89. add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCES})
  90. target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  91. SETUP_TARGET(${TEST_NAME} ${ARGN})
  92. add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
  93. endfunction()
  94. function(SETUP_LIB_SHARED_TEST TEST_NAME SUB_PATH)
  95. set(TARGET_NAME ${TEST_NAME}_${SUB_PATH})
  96. add_library(_${TARGET_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/lib.cpp)
  97. SETUP_TARGET(_${TARGET_NAME} ENTT_API_EXPORT)
  98. SETUP_BASIC_TEST(lib_${TARGET_NAME} lib/${TEST_NAME}/${SUB_PATH}/main.cpp ENTT_API_IMPORT)
  99. target_link_libraries(lib_${TARGET_NAME} PRIVATE _${TARGET_NAME})
  100. endfunction()
  101. function(SETUP_LIB_PLUGIN_TEST TEST_NAME SUB_PATH)
  102. set(TARGET_NAME ${TEST_NAME}_${SUB_PATH})
  103. add_library(_${TARGET_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/plugin.cpp)
  104. SETUP_TARGET(_${TARGET_NAME} ${ARGVN})
  105. SETUP_BASIC_TEST(lib_${TARGET_NAME} lib/${TEST_NAME}/${SUB_PATH}/main.cpp PLUGIN="$<TARGET_FILE:_${TARGET_NAME}>" ${ARGVN})
  106. target_include_directories(_${TARGET_NAME} PRIVATE ${cr_INCLUDE_DIR})
  107. target_include_directories(lib_${TARGET_NAME} PRIVATE ${cr_INCLUDE_DIR})
  108. target_link_libraries(lib_${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS})
  109. add_dependencies(lib_${TARGET_NAME} _${TARGET_NAME})
  110. endfunction()
  111. # Test benchmark
  112. if(ENTT_BUILD_BENCHMARK)
  113. SETUP_BASIC_TEST(benchmark benchmark/benchmark.cpp)
  114. endif()
  115. # Test example
  116. if(ENTT_BUILD_EXAMPLE)
  117. SETUP_BASIC_TEST(custom_identifier example/custom_identifier.cpp)
  118. SETUP_BASIC_TEST(entity_copy example/entity_copy.cpp)
  119. SETUP_BASIC_TEST(signal_less example/signal_less.cpp)
  120. endif()
  121. # Test lib
  122. if(ENTT_BUILD_LIB)
  123. FetchContent_Declare(
  124. cr
  125. GIT_REPOSITORY https://github.com/fungos/cr.git
  126. GIT_TAG master
  127. GIT_SHALLOW 1
  128. )
  129. FetchContent_GetProperties(cr)
  130. if(NOT cr_POPULATED)
  131. FetchContent_Populate(cr)
  132. set(cr_INCLUDE_DIR ${cr_SOURCE_DIR})
  133. endif()
  134. SETUP_LIB_SHARED_TEST(dispatcher shared)
  135. SETUP_LIB_PLUGIN_TEST(dispatcher plugin)
  136. SETUP_LIB_SHARED_TEST(emitter shared)
  137. SETUP_LIB_PLUGIN_TEST(emitter plugin)
  138. SETUP_LIB_SHARED_TEST(locator shared)
  139. SETUP_LIB_PLUGIN_TEST(locator plugin)
  140. SETUP_LIB_SHARED_TEST(meta shared)
  141. SETUP_LIB_PLUGIN_TEST(meta plugin)
  142. SETUP_LIB_PLUGIN_TEST(meta plugin_std ENTT_STANDARD_CPP)
  143. SETUP_LIB_SHARED_TEST(registry shared)
  144. SETUP_LIB_PLUGIN_TEST(registry plugin)
  145. endif()
  146. # Test snapshot
  147. if(ENTT_BUILD_SNAPSHOT)
  148. FetchContent_Declare(
  149. cereal
  150. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  151. GIT_TAG v1.2.2
  152. GIT_SHALLOW 1
  153. )
  154. FetchContent_GetProperties(cereal)
  155. if(NOT cereal_POPULATED)
  156. FetchContent_Populate(cereal)
  157. set(cereal_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)
  158. endif()
  159. SETUP_BASIC_TEST(cereal snapshot/snapshot.cpp)
  160. target_include_directories(cereal PRIVATE ${cereal_INCLUDE_DIR})
  161. endif()
  162. # Test config
  163. SETUP_BASIC_TEST(version entt/config/version.cpp)
  164. # Test container
  165. SETUP_BASIC_TEST(dense_map entt/container/dense_map.cpp)
  166. SETUP_BASIC_TEST(dense_set entt/container/dense_set.cpp)
  167. # Test core
  168. SETUP_BASIC_TEST(algorithm entt/core/algorithm.cpp)
  169. SETUP_BASIC_TEST(any entt/core/any.cpp)
  170. SETUP_BASIC_TEST(compressed_pair entt/core/compressed_pair.cpp)
  171. SETUP_BASIC_TEST(enum entt/core/enum.cpp)
  172. SETUP_BASIC_TEST(family entt/core/family.cpp)
  173. SETUP_BASIC_TEST(hashed_string entt/core/hashed_string.cpp)
  174. SETUP_BASIC_TEST(ident entt/core/ident.cpp)
  175. SETUP_BASIC_TEST(iterator entt/core/iterator.cpp)
  176. SETUP_BASIC_TEST(memory entt/core/memory.cpp)
  177. SETUP_BASIC_TEST(monostate entt/core/monostate.cpp)
  178. SETUP_BASIC_TEST(tuple entt/core/tuple.cpp)
  179. SETUP_BASIC_TEST(type_info entt/core/type_info.cpp)
  180. SETUP_BASIC_TEST(type_traits entt/core/type_traits.cpp)
  181. SETUP_BASIC_TEST(utility entt/core/utility.cpp)
  182. # Test entity
  183. SETUP_BASIC_TEST(component entt/entity/component.cpp)
  184. SETUP_BASIC_TEST(entity entt/entity/entity.cpp)
  185. SETUP_BASIC_TEST(group entt/entity/group.cpp)
  186. SETUP_BASIC_TEST(handle entt/entity/handle.cpp)
  187. SETUP_BASIC_TEST(helper entt/entity/helper.cpp)
  188. SETUP_BASIC_TEST(observer entt/entity/observer.cpp)
  189. SETUP_BASIC_TEST(organizer entt/entity/organizer.cpp)
  190. SETUP_BASIC_TEST(registry entt/entity/registry.cpp)
  191. SETUP_BASIC_TEST(runtime_view entt/entity/runtime_view.cpp)
  192. SETUP_BASIC_TEST(sigh_mixin entt/entity/sigh_mixin.cpp)
  193. SETUP_BASIC_TEST(snapshot entt/entity/snapshot.cpp)
  194. SETUP_BASIC_TEST(sparse_set entt/entity/sparse_set.cpp)
  195. SETUP_BASIC_TEST(storage entt/entity/storage.cpp)
  196. SETUP_BASIC_TEST(storage_entity entt/entity/storage_entity.cpp)
  197. SETUP_BASIC_TEST(view entt/entity/view.cpp)
  198. # Test graph
  199. SETUP_BASIC_TEST(adjacency_matrix entt/graph/adjacency_matrix.cpp)
  200. SETUP_BASIC_TEST(dot entt/graph/dot.cpp)
  201. SETUP_BASIC_TEST(flow entt/graph/flow.cpp)
  202. # Test locator
  203. SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
  204. # Test meta
  205. SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
  206. SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp)
  207. SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp)
  208. SETUP_BASIC_TEST(meta_context entt/meta/meta_context.cpp)
  209. SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp)
  210. SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp)
  211. SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp)
  212. SETUP_BASIC_TEST(meta_dtor entt/meta/meta_dtor.cpp)
  213. SETUP_BASIC_TEST(meta_func entt/meta/meta_func.cpp)
  214. SETUP_BASIC_TEST(meta_handle entt/meta/meta_handle.cpp)
  215. SETUP_BASIC_TEST(meta_pointer entt/meta/meta_pointer.cpp)
  216. SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp)
  217. SETUP_BASIC_TEST(meta_range entt/meta/meta_range.cpp)
  218. SETUP_BASIC_TEST(meta_template entt/meta/meta_template.cpp)
  219. SETUP_BASIC_TEST(meta_type entt/meta/meta_type.cpp)
  220. SETUP_BASIC_TEST(meta_utility entt/meta/meta_utility.cpp)
  221. # Test poly
  222. SETUP_BASIC_TEST(poly entt/poly/poly.cpp)
  223. # Test process
  224. SETUP_BASIC_TEST(process entt/process/process.cpp)
  225. SETUP_BASIC_TEST(scheduler entt/process/scheduler.cpp)
  226. # Test resource
  227. SETUP_BASIC_TEST(resource entt/resource/resource.cpp)
  228. SETUP_BASIC_TEST(resource_cache entt/resource/resource_cache.cpp)
  229. SETUP_BASIC_TEST(resource_loader entt/resource/resource_loader.cpp)
  230. # Test signal
  231. SETUP_BASIC_TEST(delegate entt/signal/delegate.cpp)
  232. SETUP_BASIC_TEST(dispatcher entt/signal/dispatcher.cpp)
  233. SETUP_BASIC_TEST(emitter entt/signal/emitter.cpp)
  234. SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)