CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. # EnTT
  2. cmake_minimum_required(VERSION 3.28)
  3. # Read project version
  4. set(ENTT_VERSION_REGEX "#define ENTT_VERSION_.*[ \t]+(.+)")
  5. file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/src/entt/config/version.h" ENTT_VERSION REGEX ${ENTT_VERSION_REGEX})
  6. list(TRANSFORM ENTT_VERSION REPLACE ${ENTT_VERSION_REGEX} "\\1")
  7. string(JOIN "." ENTT_VERSION ${ENTT_VERSION})
  8. # Project configuration
  9. project(
  10. EnTT
  11. VERSION ${ENTT_VERSION}
  12. DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
  13. HOMEPAGE_URL "https://github.com/skypjack/entt"
  14. LANGUAGES C CXX
  15. )
  16. if(NOT CMAKE_BUILD_TYPE)
  17. set(CMAKE_BUILD_TYPE Debug)
  18. endif()
  19. message(VERBOSE "*")
  20. message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
  21. message(VERBOSE "* Copyright (c) 2017-2026 Michele Caini <michele.caini@gmail.com>")
  22. message(VERBOSE "*")
  23. # CMake stuff
  24. list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
  25. # Compiler stuff
  26. option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." OFF)
  27. option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if available." OFF)
  28. option(ENTT_USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
  29. if(ENTT_USE_LIBCPP)
  30. if(NOT WIN32)
  31. include(CheckCXXSourceCompiles)
  32. include(CMakePushCheckState)
  33. cmake_push_check_state()
  34. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
  35. check_cxx_source_compiles("
  36. #include<type_traits>
  37. int main() { return std::is_same_v<int, char>; }
  38. " ENTT_HAS_LIBCPP)
  39. cmake_pop_check_state()
  40. endif()
  41. if(NOT ENTT_HAS_LIBCPP)
  42. message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available.")
  43. endif()
  44. endif()
  45. if(ENTT_USE_SANITIZER)
  46. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
  47. set(ENTT_HAS_SANITIZER TRUE CACHE BOOL "" FORCE)
  48. mark_as_advanced(ENTT_HAS_SANITIZER)
  49. endif()
  50. if(NOT ENTT_HAS_SANITIZER)
  51. message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available.")
  52. endif()
  53. endif()
  54. if(ENTT_USE_CLANG_TIDY)
  55. find_program(ENTT_CLANG_TIDY_EXECUTABLE "clang-tidy")
  56. if(NOT ENTT_CLANG_TIDY_EXECUTABLE)
  57. message(VERBOSE "The option ENTT_USE_CLANG_TIDY is set but clang-tidy executable is not available.")
  58. endif()
  59. endif()
  60. # Add EnTT target
  61. include(GNUInstallDirs)
  62. add_library(EnTT INTERFACE)
  63. add_library(EnTT::EnTT ALIAS EnTT)
  64. target_include_directories(
  65. EnTT
  66. INTERFACE
  67. $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src>
  68. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  69. )
  70. target_compile_features(EnTT INTERFACE cxx_std_20)
  71. if(ENTT_HAS_LIBCPP)
  72. target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
  73. endif()
  74. if(ENTT_HAS_SANITIZER)
  75. target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
  76. target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
  77. endif()
  78. if(ENTT_CLANG_TIDY_EXECUTABLE)
  79. set(ENTT_CLANG_TIDY_OPTIONS ";--config-file=${EnTT_SOURCE_DIR}/.clang-tidy;--header-filter=${EnTT_SOURCE_DIR}/src/entt/.*")
  80. if(MSVC AND NOT (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
  81. set(ENTT_CLANG_TIDY_OPTIONS "${ENTT_CLANG_TIDY_OPTIONS};--extra-arg=/EHsc;--extra-arg=/wd4996")
  82. endif()
  83. set(CMAKE_CXX_CLANG_TIDY "${ENTT_CLANG_TIDY_EXECUTABLE}${ENTT_CLANG_TIDY_OPTIONS}")
  84. endif()
  85. # Add EnTT goodies
  86. option(ENTT_INCLUDE_HEADERS "Add all EnTT headers to the EnTT target." OFF)
  87. option(ENTT_INCLUDE_NATVIS "Add EnTT natvis files to the EnTT target." OFF)
  88. if(ENTT_INCLUDE_HEADERS)
  89. set(
  90. HEADERS_FILES
  91. config/config.h
  92. config/macro.h
  93. config/version.h
  94. container/dense_map.hpp
  95. container/dense_set.hpp
  96. container/table.hpp
  97. container/fwd.hpp
  98. core/algorithm.hpp
  99. core/any.hpp
  100. core/bit.hpp
  101. core/compressed_pair.hpp
  102. core/concepts.hpp
  103. core/enum.hpp
  104. core/family.hpp
  105. core/fwd.hpp
  106. core/hashed_string.hpp
  107. core/ident.hpp
  108. core/iterator.hpp
  109. core/memory.hpp
  110. core/monostate.hpp
  111. core/ranges.hpp
  112. core/tuple.hpp
  113. core/type_info.hpp
  114. core/type_traits.hpp
  115. core/utility.hpp
  116. entity/component.hpp
  117. entity/entity.hpp
  118. entity/fwd.hpp
  119. entity/group.hpp
  120. entity/handle.hpp
  121. entity/mixin.hpp
  122. entity/helper.hpp
  123. entity/organizer.hpp
  124. entity/ranges.hpp
  125. entity/registry.hpp
  126. entity/runtime_view.hpp
  127. entity/snapshot.hpp
  128. entity/sparse_set.hpp
  129. entity/storage.hpp
  130. entity/view.hpp
  131. graph/adjacency_matrix.hpp
  132. graph/dot.hpp
  133. graph/flow.hpp
  134. graph/fwd.hpp
  135. locator/locator.hpp
  136. meta/adl_pointer.hpp
  137. meta/container.hpp
  138. meta/context.hpp
  139. meta/factory.hpp
  140. meta/fwd.hpp
  141. meta/meta.hpp
  142. meta/node.hpp
  143. meta/pointer.hpp
  144. meta/policy.hpp
  145. meta/range.hpp
  146. meta/resolve.hpp
  147. meta/template.hpp
  148. meta/type_traits.hpp
  149. meta/utility.hpp
  150. poly/fwd.hpp
  151. poly/poly.hpp
  152. process/fwd.hpp
  153. process/process.hpp
  154. process/scheduler.hpp
  155. resource/cache.hpp
  156. resource/fwd.hpp
  157. resource/loader.hpp
  158. resource/resource.hpp
  159. signal/delegate.hpp
  160. signal/dispatcher.hpp
  161. signal/emitter.hpp
  162. signal/fwd.hpp
  163. signal/sigh.hpp
  164. stl/array.hpp
  165. stl/atomic.hpp
  166. stl/functional.hpp
  167. stl/iterator.hpp
  168. stl/memory.hpp
  169. stl/tuple.hpp
  170. stl/type_traits.hpp
  171. stl/utility.hpp
  172. stl/vector.hpp
  173. tools/davey.hpp
  174. entt.hpp
  175. fwd.hpp
  176. tools.hpp
  177. )
  178. list(TRANSFORM HEADERS_FILES APPEND ">" OUTPUT_VARIABLE HEADERS_BUILD_INTERFACE)
  179. list(TRANSFORM HEADERS_BUILD_INTERFACE PREPEND "$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/")
  180. list(TRANSFORM HEADERS_FILES APPEND ">" OUTPUT_VARIABLE HEADERS_INSTALL_INTERFACE)
  181. list(TRANSFORM HEADERS_INSTALL_INTERFACE PREPEND "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/entt/")
  182. target_sources(EnTT INTERFACE ${HEADERS_BUILD_INTERFACE} ${HEADERS_INSTALL_INTERFACE})
  183. endif()
  184. if(ENTT_INCLUDE_NATVIS)
  185. if(MSVC)
  186. set(ENTT_HAS_NATVIS TRUE CACHE BOOL "" FORCE)
  187. mark_as_advanced(ENTT_HAS_NATVIS)
  188. endif()
  189. if(NOT ENTT_HAS_NATVIS)
  190. message(VERBOSE "The option ENTT_INCLUDE_NATVIS is set but natvis files are not supported. They will not be added to the target.")
  191. endif()
  192. endif()
  193. if(ENTT_HAS_NATVIS)
  194. set(
  195. NATVIS_FILES
  196. config.natvis
  197. container.natvis
  198. core.natvis
  199. entity.natvis
  200. graph.natvis
  201. locator.natvis
  202. meta.natvis
  203. poly.natvis
  204. process.natvis
  205. resource.natvis
  206. signal.natvis
  207. )
  208. list(TRANSFORM NATVIS_FILES APPEND ">" OUTPUT_VARIABLE NATVIS_BUILD_INTERFACE)
  209. list(TRANSFORM NATVIS_BUILD_INTERFACE PREPEND "$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/natvis/")
  210. list(TRANSFORM NATVIS_FILES APPEND ">" OUTPUT_VARIABLE NATVIS_INSTALL_INTERFACE)
  211. list(TRANSFORM NATVIS_INSTALL_INTERFACE PREPEND "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/entt/natvis/")
  212. target_sources(EnTT INTERFACE ${NATVIS_BUILD_INTERFACE} ${NATVIS_INSTALL_INTERFACE})
  213. endif()
  214. # Install EnTT and all related files
  215. option(ENTT_INSTALL "Install EnTT and all related files." OFF)
  216. if(ENTT_INSTALL)
  217. # Install pkg-config file
  218. include(JoinPaths)
  219. set(EnTT_PKGCONFIG ${CMAKE_CURRENT_BINARY_DIR}/entt.pc)
  220. join_paths(EnTT_PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
  221. configure_file(
  222. ${EnTT_SOURCE_DIR}/cmake/in/entt.pc.in
  223. ${EnTT_PKGCONFIG}
  224. @ONLY
  225. )
  226. install(
  227. FILES ${EnTT_PKGCONFIG}
  228. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  229. )
  230. # Install EnTT
  231. include(CMakePackageConfigHelpers)
  232. install(
  233. TARGETS EnTT
  234. EXPORT EnTTTargets
  235. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  236. )
  237. write_basic_package_version_file(
  238. EnTTConfigVersion.cmake
  239. VERSION ${PROJECT_VERSION}
  240. COMPATIBILITY AnyNewerVersion
  241. )
  242. configure_package_config_file(
  243. ${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
  244. EnTTConfig.cmake
  245. INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  246. )
  247. export(
  248. EXPORT EnTTTargets
  249. FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
  250. NAMESPACE EnTT::
  251. )
  252. install(
  253. EXPORT EnTTTargets
  254. FILE EnTTTargets.cmake
  255. DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  256. NAMESPACE EnTT::
  257. )
  258. install(
  259. FILES
  260. ${PROJECT_BINARY_DIR}/EnTTConfig.cmake
  261. ${PROJECT_BINARY_DIR}/EnTTConfigVersion.cmake
  262. DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  263. )
  264. install(
  265. DIRECTORY src/
  266. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  267. FILES_MATCHING
  268. PATTERN "*.h"
  269. PATTERN "*.hpp"
  270. PATTERN "*.natvis"
  271. )
  272. export(PACKAGE EnTT)
  273. endif()
  274. # Tests and testbed
  275. option(ENTT_BUILD_TESTING "Enable building tests." OFF)
  276. option(ENTT_BUILD_TESTBED "Enable building testbed." OFF)
  277. if(ENTT_BUILD_TESTING OR ENTT_BUILD_TESTBED)
  278. set(ENTT_ID_TYPE std::uint32_t CACHE STRING "Type of identifiers to use for tests and testbed")
  279. set(ENTT_CXX_STD cxx_std_20 CACHE STRING "C++ standard revision to use for tests and testbed")
  280. # Tests and tesetbed do not work together because SDL gets confused with EnTT tests
  281. if(ENTT_BUILD_TESTING)
  282. option(ENTT_FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  283. option(ENTT_BUILD_BENCHMARK "Build benchmark." OFF)
  284. option(ENTT_BUILD_EXAMPLE "Build examples." OFF)
  285. option(ENTT_BUILD_LIB "Build lib tests." OFF)
  286. option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)
  287. include(CTest)
  288. enable_testing()
  289. add_subdirectory(test)
  290. elseif(ENTT_BUILD_TESTBED)
  291. add_subdirectory(testbed)
  292. endif()
  293. endif()
  294. # Documentation
  295. option(ENTT_BUILD_DOCS "Enable building with documentation." OFF)
  296. if(ENTT_BUILD_DOCS)
  297. add_subdirectory(docs)
  298. endif()