1
0

CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 /bigobj
  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. set(options DEFS)
  84. set(oneValueArgs NAME)
  85. set(multiValueArgs SOURCES INCLUDE)
  86. cmake_parse_arguments(BASIC_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  87. add_executable(${BASIC_TEST_NAME} $<TARGET_OBJECTS:odr> ${BASIC_TEST_SOURCES})
  88. target_link_libraries(${BASIC_TEST_NAME} PRIVATE GTest::Main Threads::Threads)
  89. target_include_directories(${BASIC_TEST_NAME} PRIVATE ${BASIC_TEST_INCLUDE})
  90. SETUP_TARGET(${BASIC_TEST_NAME} ${BASIC_TEST_UNPARSED_ARGUMENTS})
  91. add_test(NAME ${BASIC_TEST_NAME} COMMAND ${BASIC_TEST_NAME})
  92. set_tests_properties(${BASIC_TEST_NAME} PROPERTIES TIMEOUT 60)
  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(NAME lib_${TARGET_NAME} SOURCES lib/${TEST_NAME}/${SUB_PATH}/main.cpp DEFS ENTT_API_IMPORT)
  99. set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  100. target_link_libraries(lib_${TARGET_NAME} PRIVATE _${TARGET_NAME})
  101. endfunction()
  102. function(SETUP_LIB_PLUGIN_TEST TEST_NAME SUB_PATH)
  103. set(TARGET_NAME ${TEST_NAME}_${SUB_PATH})
  104. add_library(_${TARGET_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/plugin.cpp)
  105. SETUP_TARGET(_${TARGET_NAME} ${ARGVN})
  106. SETUP_BASIC_TEST(NAME lib_${TARGET_NAME} SOURCES lib/${TEST_NAME}/${SUB_PATH}/main.cpp DEFS PLUGIN="$<TARGET_FILE:_${TARGET_NAME}>" ${ARGVN})
  107. target_link_libraries(_${TARGET_NAME} PRIVATE cr::cr)
  108. target_link_libraries(lib_${TARGET_NAME} PRIVATE cr::cr ${CMAKE_DL_LIBS})
  109. set_target_properties(_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  110. set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
  111. target_compile_options(_${TARGET_NAME} PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  112. target_compile_options(lib_${TARGET_NAME} PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  113. add_dependencies(lib_${TARGET_NAME} _${TARGET_NAME})
  114. endfunction()
  115. # Test benchmark
  116. if(ENTT_BUILD_BENCHMARK)
  117. SETUP_BASIC_TEST(
  118. NAME benchmark
  119. SOURCES benchmark/benchmark.cpp
  120. )
  121. set_target_properties(benchmark PROPERTIES CXX_CLANG_TIDY "")
  122. endif()
  123. # Test example
  124. if(ENTT_BUILD_EXAMPLE)
  125. SETUP_BASIC_TEST(
  126. NAME example
  127. SOURCES
  128. example/custom_identifier.cpp
  129. example/entity_copy.cpp
  130. example/reserved_bits.cpp
  131. example/signal_less.cpp
  132. )
  133. endif()
  134. # Test lib
  135. if(ENTT_BUILD_LIB)
  136. FetchContent_Declare(
  137. cr
  138. GIT_REPOSITORY https://github.com/fungos/cr.git
  139. GIT_TAG master
  140. GIT_SHALLOW 1
  141. )
  142. FetchContent_MakeAvailable(cr)
  143. add_library(cr::cr ALIAS cr)
  144. SETUP_LIB_SHARED_TEST(dispatcher shared)
  145. SETUP_LIB_PLUGIN_TEST(dispatcher plugin)
  146. SETUP_LIB_SHARED_TEST(emitter shared)
  147. SETUP_LIB_PLUGIN_TEST(emitter plugin)
  148. SETUP_LIB_SHARED_TEST(locator shared)
  149. SETUP_LIB_PLUGIN_TEST(locator plugin)
  150. SETUP_LIB_SHARED_TEST(meta shared)
  151. SETUP_LIB_PLUGIN_TEST(meta plugin)
  152. SETUP_LIB_PLUGIN_TEST(meta plugin_std ENTT_STANDARD_CPP)
  153. SETUP_LIB_SHARED_TEST(registry shared)
  154. SETUP_LIB_PLUGIN_TEST(registry plugin)
  155. SETUP_LIB_SHARED_TEST(view shared)
  156. SETUP_LIB_PLUGIN_TEST(view plugin)
  157. endif()
  158. # Test snapshot
  159. if(ENTT_BUILD_SNAPSHOT)
  160. FetchContent_Declare(
  161. cereal
  162. GIT_REPOSITORY https://github.com/USCiLab/cereal.git
  163. GIT_TAG v1.3.2
  164. GIT_SHALLOW 1
  165. )
  166. set(BUILD_DOC OFF CACHE BOOL "" FORCE)
  167. set(BUILD_SANDBOX OFF CACHE BOOL "" FORCE)
  168. set(SKIP_PORTABILITY_TEST ON CACHE BOOL "" FORCE)
  169. set(SKIP_PERFORMANCE_COMPARISON ON CACHE BOOL "" FORCE)
  170. FetchContent_MakeAvailable(cereal)
  171. SETUP_BASIC_TEST(
  172. NAME snapshot
  173. SOURCES snapshot/snapshot.cpp
  174. )
  175. target_link_libraries(snapshot PRIVATE cereal)
  176. target_compile_options(snapshot PRIVATE $<$<NOT:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">>:-Wno-conversion>)
  177. set_target_properties(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 config_ext
  185. SETUP_BASIC_TEST(
  186. NAME config_ext
  187. SOURCES entt/config_ext/config.cpp
  188. INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include
  189. )
  190. # Test container
  191. SETUP_BASIC_TEST(
  192. NAME container
  193. SOURCES
  194. entt/container/dense_map.cpp
  195. entt/container/dense_set.cpp
  196. entt/container/table.cpp
  197. )
  198. # Test core
  199. SETUP_BASIC_TEST(
  200. NAME core
  201. SOURCES
  202. entt/core/algorithm.cpp
  203. entt/core/any.cpp
  204. entt/core/bit.cpp
  205. entt/core/compressed_pair.cpp
  206. entt/core/concepts.cpp
  207. entt/core/enum.cpp
  208. entt/core/family.cpp
  209. entt/core/hashed_string.cpp
  210. entt/core/ident.cpp
  211. entt/core/iterator.cpp
  212. entt/core/memory.cpp
  213. entt/core/monostate.cpp
  214. entt/core/tuple.cpp
  215. entt/core/type_info.cpp
  216. entt/core/type_traits.cpp
  217. entt/core/utility.cpp
  218. )
  219. # Test entity
  220. SETUP_BASIC_TEST(
  221. NAME entity
  222. SOURCES
  223. entt/entity/component.cpp
  224. entt/entity/entity.cpp
  225. entt/entity/group.cpp
  226. entt/entity/handle.cpp
  227. entt/entity/helper.cpp
  228. entt/entity/organizer.cpp
  229. entt/entity/reactive_mixin.cpp
  230. entt/entity/registry.cpp
  231. entt/entity/runtime_view.cpp
  232. entt/entity/sigh_mixin.cpp
  233. entt/entity/snapshot.cpp
  234. entt/entity/sparse_set.cpp
  235. entt/entity/storage.cpp
  236. entt/entity/storage_entity.cpp
  237. entt/entity/storage_no_instance.cpp
  238. entt/entity/storage_utility.cpp
  239. entt/entity/view.cpp
  240. )
  241. # Test entity_no_mixin
  242. SETUP_BASIC_TEST(
  243. NAME entity_no_mixin
  244. SOURCES
  245. entt/entity_no_mixin/storage_utility.cpp
  246. DEFS ENTT_NO_MIXIN
  247. )
  248. # Test graph
  249. SETUP_BASIC_TEST(
  250. NAME graph
  251. SOURCES
  252. entt/graph/adjacency_matrix.cpp
  253. entt/graph/dot.cpp
  254. entt/graph/flow.cpp
  255. )
  256. # Test locator
  257. SETUP_BASIC_TEST(
  258. NAME locator
  259. SOURCES entt/locator/locator.cpp
  260. )
  261. # Test meta
  262. SETUP_BASIC_TEST(
  263. NAME meta
  264. SOURCES
  265. entt/meta/meta_any.cpp
  266. entt/meta/meta_base.cpp
  267. entt/meta/meta_container.cpp
  268. entt/meta/meta_context.cpp
  269. entt/meta/meta_conv.cpp
  270. entt/meta/meta_ctor.cpp
  271. entt/meta/meta_custom.cpp
  272. entt/meta/meta_data.cpp
  273. entt/meta/meta_dereference.cpp
  274. entt/meta/meta_factory.cpp
  275. entt/meta/meta_func.cpp
  276. entt/meta/meta_handle.cpp
  277. entt/meta/meta_range.cpp
  278. entt/meta/meta_template.cpp
  279. entt/meta/meta_type.cpp
  280. entt/meta/meta_utility.cpp
  281. )
  282. # Test poly
  283. SETUP_BASIC_TEST(
  284. NAME poly
  285. SOURCES entt/poly/poly.cpp
  286. )
  287. # Test process
  288. SETUP_BASIC_TEST(
  289. NAME process
  290. SOURCES
  291. entt/process/process.cpp
  292. entt/process/scheduler.cpp
  293. )
  294. # Test resource
  295. SETUP_BASIC_TEST(
  296. NAME resource
  297. SOURCES
  298. entt/resource/resource.cpp
  299. entt/resource/resource_cache.cpp
  300. entt/resource/resource_loader.cpp
  301. )
  302. # Test signal
  303. SETUP_BASIC_TEST(
  304. NAME signal
  305. SOURCES
  306. entt/signal/delegate.cpp
  307. entt/signal/dispatcher.cpp
  308. entt/signal/emitter.cpp
  309. entt/signal/sigh.cpp
  310. )
  311. # Test stl
  312. SETUP_BASIC_TEST(
  313. NAME stl
  314. SOURCES
  315. entt/stl/functional.cpp
  316. entt/stl/iterator.cpp
  317. entt/stl/memory.cpp
  318. DEFS ENTT_USE_STL
  319. )
  320. # Test stl_ext
  321. SETUP_BASIC_TEST(
  322. NAME stl_ext
  323. SOURCES
  324. entt/stl_ext/algorithm.cpp
  325. entt/stl_ext/array.cpp
  326. entt/stl_ext/atomic.cpp
  327. entt/stl_ext/bit.cpp
  328. entt/stl_ext/cmath.cpp
  329. entt/stl_ext/concepts.cpp
  330. entt/stl_ext/cstddef.cpp
  331. entt/stl_ext/cstdint.cpp
  332. entt/stl_ext/functional.cpp
  333. entt/stl_ext/ios.cpp
  334. entt/stl_ext/iterator.cpp
  335. entt/stl_ext/limits.cpp
  336. entt/stl_ext/memory.cpp
  337. entt/stl_ext/ostream.cpp
  338. entt/stl_ext/sstream.cpp
  339. entt/stl_ext/string.cpp
  340. entt/stl_ext/string_view.cpp
  341. entt/stl_ext/tuple.cpp
  342. entt/stl_ext/type_traits.cpp
  343. entt/stl_ext/utility.cpp
  344. entt/stl_ext/vector.cpp
  345. INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include
  346. )