CMakeLists.txt 10 KB

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