CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. # Tests configuration
  2. include(FetchContent)
  3. include(CheckCXXSourceCompiles)
  4. set(THREADS_PREFER_PTHREAD_FLAG ON)
  5. find_package(Threads REQUIRED)
  6. if(ENTT_FIND_GTEST_PACKAGE)
  7. find_package(GTest REQUIRED)
  8. else()
  9. FetchContent_Declare(
  10. googletest
  11. GIT_REPOSITORY https://github.com/google/googletest.git
  12. GIT_TAG main
  13. GIT_SHALLOW 1
  14. )
  15. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  16. FetchContent_MakeAvailable(googletest)
  17. add_library(GTest::Main ALIAS gtest_main)
  18. target_compile_features(gtest PUBLIC cxx_std_20)
  19. set_target_properties(gtest PROPERTIES CXX_CLANG_TIDY "")
  20. target_compile_features(gtest_main PUBLIC cxx_std_20)
  21. set_target_properties(gtest_main PROPERTIES CXX_CLANG_TIDY "")
  22. target_compile_features(gmock PUBLIC cxx_std_20)
  23. set_target_properties(gmock PROPERTIES CXX_CLANG_TIDY "")
  24. target_compile_features(gmock_main PUBLIC cxx_std_20)
  25. set_target_properties(gmock_main PROPERTIES CXX_CLANG_TIDY "")
  26. endif()
  27. include_directories($<TARGET_PROPERTY:EnTT,INTERFACE_INCLUDE_DIRECTORIES>)
  28. add_compile_options($<TARGET_PROPERTY:EnTT,INTERFACE_COMPILE_OPTIONS>)
  29. function(SETUP_TARGET TARGET_NAME)
  30. set_target_properties(${TARGET_NAME} PROPERTIES CXX_EXTENSIONS OFF)
  31. target_compile_features(${TARGET_NAME} PRIVATE ${ENTT_CXX_STD})
  32. target_link_libraries(${TARGET_NAME} PRIVATE EnTT)
  33. if(MSVC)
  34. set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/PROFILE")
  35. target_compile_options(
  36. ${TARGET_NAME}
  37. PRIVATE
  38. $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","Clang">:
  39. -Wdocumentation
  40. -Wno-deprecated-declarations
  41. -Wno-exceptions
  42. -Wconversion
  43. >
  44. /EHsc /wd4324 /wd4996
  45. # disabling INCREMENTAL is required by SizeBench
  46. $<$<CONFIG:Debug>:/Od /INCREMENTAL:NO>
  47. $<$<CONFIG:Release>:/O2>
  48. )
  49. target_link_options(
  50. ${TARGET_NAME}
  51. PRIVATE
  52. # disabling INCREMENTAL is required by SizeBench
  53. $<$<CONFIG:Debug>:/INCREMENTAL:NO>
  54. $<$<CONFIG:Release>:/OPT:NOICF>
  55. )
  56. else()
  57. target_compile_options(
  58. ${TARGET_NAME}
  59. PRIVATE
  60. -fvisibility=hidden
  61. -pedantic
  62. -Wall
  63. -Wconversion
  64. -Wno-deprecated-declarations
  65. -Wshadow
  66. $<$<CONFIG:Debug>:-O0 -g>
  67. $<$<CONFIG:Release>:-O2>
  68. )
  69. endif()
  70. target_compile_definitions(
  71. ${TARGET_NAME}
  72. PRIVATE
  73. ENTT_ID_TYPE=${ENTT_ID_TYPE}
  74. _ENABLE_EXTENDED_ALIGNED_STORAGE
  75. NOMINMAX
  76. ${ARGN}
  77. )
  78. endfunction()
  79. add_library(odr OBJECT odr.cpp)
  80. set_target_properties(odr PROPERTIES POSITION_INDEPENDENT_CODE ON)
  81. SETUP_TARGET(odr)
  82. function(SETUP_BASIC_TEST)
  83. cmake_parse_arguments(BASIC_TEST "DEFS" "NAME" "SOURCES" ${ARGN})
  84. add_executable(${BASIC_TEST_NAME} $<TARGET_OBJECTS:odr> ${BASIC_TEST_SOURCES})
  85. target_link_libraries(${BASIC_TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  86. SETUP_TARGET(${BASIC_TEST_NAME} ${BASIC_TEST_UNPARSED_ARGUMENTS})
  87. add_test(NAME ${BASIC_TEST_NAME} COMMAND ${BASIC_TEST_NAME})
  88. set_tests_properties(${BASIC_TEST_NAME} PROPERTIES TIMEOUT 60)
  89. endfunction()
  90. function(SETUP_BASIC_TEST_DEPRECATED TEST_NAME TEST_SOURCES)
  91. add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCES})
  92. target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  93. SETUP_TARGET(${TEST_NAME} ${ARGN})
  94. add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
  95. set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60)
  96. endfunction()
  97. function(SETUP_LIB_SHARED_TEST TEST_NAME SUB_PATH)
  98. set(TARGET_NAME ${TEST_NAME}_${SUB_PATH})
  99. add_library(_${TARGET_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/lib.cpp)
  100. SETUP_TARGET(_${TARGET_NAME} ENTT_API_EXPORT)
  101. SETUP_BASIC_TEST(NAME lib_${TARGET_NAME} SOURCES lib/${TEST_NAME}/${SUB_PATH}/main.cpp DEFS ENTT_API_IMPORT)
  102. set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  103. target_link_libraries(lib_${TARGET_NAME} PRIVATE _${TARGET_NAME})
  104. endfunction()
  105. function(SETUP_LIB_PLUGIN_TEST TEST_NAME SUB_PATH)
  106. set(TARGET_NAME ${TEST_NAME}_${SUB_PATH})
  107. add_library(_${TARGET_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/plugin.cpp)
  108. SETUP_TARGET(_${TARGET_NAME} ${ARGVN})
  109. SETUP_BASIC_TEST(NAME lib_${TARGET_NAME} SOURCES lib/${TEST_NAME}/${SUB_PATH}/main.cpp DEFS PLUGIN="$<TARGET_FILE:_${TARGET_NAME}>" ${ARGVN})
  110. target_link_libraries(_${TARGET_NAME} PRIVATE cr::cr)
  111. target_link_libraries(lib_${TARGET_NAME} PRIVATE cr::cr ${CMAKE_DL_LIBS})
  112. set_target_properties(_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  113. set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  114. target_compile_options(_${TARGET_NAME} PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  115. target_compile_options(lib_${TARGET_NAME} PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  116. add_dependencies(lib_${TARGET_NAME} _${TARGET_NAME})
  117. endfunction()
  118. # Test benchmark
  119. if(ENTT_BUILD_BENCHMARK)
  120. SETUP_BASIC_TEST(
  121. NAME benchmark
  122. SOURCES benchmark/benchmark.cpp
  123. )
  124. set_target_properties(benchmark PROPERTIES CXX_CLANG_TIDY "")
  125. endif()
  126. # Test example
  127. if(ENTT_BUILD_EXAMPLE)
  128. SETUP_BASIC_TEST(
  129. NAME example
  130. SOURCES
  131. example/custom_identifier.cpp
  132. example/entity_copy.cpp
  133. example/reserved_bits.cpp
  134. example/signal_less.cpp
  135. )
  136. endif()
  137. # Test lib
  138. if(ENTT_BUILD_LIB)
  139. FetchContent_Declare(
  140. cr
  141. GIT_REPOSITORY https://github.com/fungos/cr.git
  142. GIT_TAG master
  143. GIT_SHALLOW 1
  144. )
  145. FetchContent_MakeAvailable(cr)
  146. add_library(cr::cr ALIAS cr)
  147. SETUP_LIB_SHARED_TEST(dispatcher shared)
  148. SETUP_LIB_PLUGIN_TEST(dispatcher plugin)
  149. SETUP_LIB_SHARED_TEST(emitter shared)
  150. SETUP_LIB_PLUGIN_TEST(emitter plugin)
  151. SETUP_LIB_SHARED_TEST(locator shared)
  152. SETUP_LIB_PLUGIN_TEST(locator plugin)
  153. SETUP_LIB_SHARED_TEST(meta shared)
  154. SETUP_LIB_PLUGIN_TEST(meta plugin)
  155. SETUP_LIB_PLUGIN_TEST(meta plugin_std ENTT_STANDARD_CPP)
  156. SETUP_LIB_SHARED_TEST(registry shared)
  157. SETUP_LIB_PLUGIN_TEST(registry plugin)
  158. SETUP_LIB_SHARED_TEST(view shared)
  159. SETUP_LIB_PLUGIN_TEST(view plugin)
  160. endif()
  161. # Test snapshot
  162. if(ENTT_BUILD_SNAPSHOT)
  163. FetchContent_Declare(
  164. cereal
  165. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  166. GIT_TAG v1.3.2
  167. GIT_SHALLOW 1
  168. )
  169. set(BUILD_DOC OFF CACHE BOOL "" FORCE)
  170. set(BUILD_SANDBOX OFF CACHE BOOL "" FORCE)
  171. set(SKIP_PORTABILITY_TEST ON CACHE BOOL "" FORCE)
  172. set(SKIP_PERFORMANCE_COMPARISON ON CACHE BOOL "" FORCE)
  173. FetchContent_MakeAvailable(cereal)
  174. SETUP_BASIC_TEST_DEPRECATED(cereal_snapshot snapshot/snapshot.cpp)
  175. target_link_libraries(cereal_snapshot PRIVATE cereal)
  176. target_compile_options(cereal_snapshot PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  177. set_target_properties(cereal_snapshot PROPERTIES CXX_CLANG_TIDY "")
  178. endif()
  179. # Test config
  180. SETUP_BASIC_TEST(
  181. NAME config
  182. SOURCES entt/config/version.cpp
  183. )
  184. # Test container
  185. SETUP_BASIC_TEST(
  186. NAME container
  187. SOURCES
  188. entt/container/dense_map.cpp
  189. entt/container/dense_set.cpp
  190. entt/container/table.cpp
  191. )
  192. # Test core
  193. SETUP_BASIC_TEST(
  194. NAME core
  195. SOURCES
  196. entt/core/algorithm.cpp
  197. entt/core/any.cpp
  198. entt/core/bit.cpp
  199. entt/core/compressed_pair.cpp
  200. entt/core/enum.cpp
  201. entt/core/family.cpp
  202. entt/core/hashed_string.cpp
  203. entt/core/ident.cpp
  204. entt/core/iterator.cpp
  205. entt/core/memory.cpp
  206. entt/core/monostate.cpp
  207. entt/core/tuple.cpp
  208. entt/core/type_info.cpp
  209. entt/core/type_traits.cpp
  210. entt/core/utility.cpp
  211. )
  212. # Test entity
  213. SETUP_BASIC_TEST_DEPRECATED(component entt/entity/component.cpp)
  214. SETUP_BASIC_TEST_DEPRECATED(entity entt/entity/entity.cpp)
  215. SETUP_BASIC_TEST_DEPRECATED(group entt/entity/group.cpp)
  216. SETUP_BASIC_TEST_DEPRECATED(handle entt/entity/handle.cpp)
  217. SETUP_BASIC_TEST_DEPRECATED(helper entt/entity/helper.cpp)
  218. SETUP_BASIC_TEST_DEPRECATED(organizer entt/entity/organizer.cpp)
  219. SETUP_BASIC_TEST_DEPRECATED(reactive_mixin entt/entity/reactive_mixin.cpp)
  220. SETUP_BASIC_TEST_DEPRECATED(registry entt/entity/registry.cpp)
  221. SETUP_BASIC_TEST_DEPRECATED(runtime_view entt/entity/runtime_view.cpp)
  222. SETUP_BASIC_TEST_DEPRECATED(sigh_mixin entt/entity/sigh_mixin.cpp)
  223. SETUP_BASIC_TEST_DEPRECATED(snapshot entt/entity/snapshot.cpp)
  224. SETUP_BASIC_TEST_DEPRECATED(sparse_set entt/entity/sparse_set.cpp)
  225. SETUP_BASIC_TEST_DEPRECATED(storage entt/entity/storage.cpp)
  226. SETUP_BASIC_TEST_DEPRECATED(storage_entity entt/entity/storage_entity.cpp)
  227. SETUP_BASIC_TEST_DEPRECATED(storage_no_instance entt/entity/storage_no_instance.cpp)
  228. SETUP_BASIC_TEST_DEPRECATED(storage_utility entt/entity/storage_utility.cpp)
  229. SETUP_BASIC_TEST_DEPRECATED(storage_utility_no_mixin entt/entity/storage_utility.cpp ENTT_NO_MIXIN)
  230. SETUP_BASIC_TEST_DEPRECATED(view entt/entity/view.cpp)
  231. # Test graph
  232. SETUP_BASIC_TEST(
  233. NAME graph
  234. SOURCES
  235. entt/graph/adjacency_matrix.cpp
  236. entt/graph/dot.cpp
  237. entt/graph/flow.cpp
  238. )
  239. # Test locator
  240. SETUP_BASIC_TEST(
  241. NAME locator
  242. SOURCES entt/locator/locator.cpp
  243. )
  244. # Test meta
  245. SETUP_BASIC_TEST(
  246. NAME meta
  247. SOURCES
  248. entt/meta/meta_any.cpp
  249. entt/meta/meta_base.cpp
  250. entt/meta/meta_container.cpp
  251. entt/meta/meta_context.cpp
  252. entt/meta/meta_conv.cpp
  253. entt/meta/meta_ctor.cpp
  254. entt/meta/meta_custom.cpp
  255. entt/meta/meta_data.cpp
  256. entt/meta/meta_factory.cpp
  257. entt/meta/meta_func.cpp
  258. entt/meta/meta_handle.cpp
  259. entt/meta/meta_pointer.cpp
  260. entt/meta/meta_range.cpp
  261. entt/meta/meta_template.cpp
  262. entt/meta/meta_type.cpp
  263. entt/meta/meta_utility.cpp
  264. )
  265. # Test poly
  266. SETUP_BASIC_TEST(
  267. NAME poly
  268. SOURCES entt/poly/poly.cpp
  269. )
  270. # Test process
  271. SETUP_BASIC_TEST(
  272. NAME process
  273. SOURCES
  274. entt/process/process.cpp
  275. entt/process/scheduler.cpp
  276. )
  277. # Test resource
  278. SETUP_BASIC_TEST(
  279. NAME resource
  280. SOURCES
  281. entt/resource/resource.cpp
  282. entt/resource/resource_cache.cpp
  283. entt/resource/resource_loader.cpp
  284. )
  285. # Test signal
  286. SETUP_BASIC_TEST(
  287. NAME signal
  288. SOURCES
  289. entt/signal/delegate.cpp
  290. entt/signal/dispatcher.cpp
  291. entt/signal/emitter.cpp
  292. entt/signal/sigh.cpp
  293. )
  294. # Test stl
  295. SETUP_BASIC_TEST(
  296. NAME stl
  297. SOURCES
  298. entt/stl/functional.cpp
  299. entt/stl/memory.cpp
  300. DEFS ENTT_USE_STL
  301. )