CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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/algorithm.hpp
  165. stl/array.hpp
  166. stl/atomic.hpp
  167. stl/cstddef.hpp
  168. stl/cstdint.hpp
  169. stl/functional.hpp
  170. stl/iterator.hpp
  171. stl/memory.hpp
  172. stl/tuple.hpp
  173. stl/type_traits.hpp
  174. stl/utility.hpp
  175. stl/vector.hpp
  176. tools/davey.hpp
  177. entt.hpp
  178. fwd.hpp
  179. tools.hpp
  180. )
  181. list(TRANSFORM HEADERS_FILES APPEND ">" OUTPUT_VARIABLE HEADERS_BUILD_INTERFACE)
  182. list(TRANSFORM HEADERS_BUILD_INTERFACE PREPEND "$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/")
  183. list(TRANSFORM HEADERS_FILES APPEND ">" OUTPUT_VARIABLE HEADERS_INSTALL_INTERFACE)
  184. list(TRANSFORM HEADERS_INSTALL_INTERFACE PREPEND "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/entt/")
  185. target_sources(EnTT INTERFACE ${HEADERS_BUILD_INTERFACE} ${HEADERS_INSTALL_INTERFACE})
  186. endif()
  187. if(ENTT_INCLUDE_NATVIS)
  188. if(MSVC)
  189. set(ENTT_HAS_NATVIS TRUE CACHE BOOL "" FORCE)
  190. mark_as_advanced(ENTT_HAS_NATVIS)
  191. endif()
  192. if(NOT ENTT_HAS_NATVIS)
  193. message(VERBOSE "The option ENTT_INCLUDE_NATVIS is set but natvis files are not supported. They will not be added to the target.")
  194. endif()
  195. endif()
  196. if(ENTT_HAS_NATVIS)
  197. set(
  198. NATVIS_FILES
  199. config.natvis
  200. container.natvis
  201. core.natvis
  202. entity.natvis
  203. graph.natvis
  204. locator.natvis
  205. meta.natvis
  206. poly.natvis
  207. process.natvis
  208. resource.natvis
  209. signal.natvis
  210. )
  211. list(TRANSFORM NATVIS_FILES APPEND ">" OUTPUT_VARIABLE NATVIS_BUILD_INTERFACE)
  212. list(TRANSFORM NATVIS_BUILD_INTERFACE PREPEND "$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/natvis/")
  213. list(TRANSFORM NATVIS_FILES APPEND ">" OUTPUT_VARIABLE NATVIS_INSTALL_INTERFACE)
  214. list(TRANSFORM NATVIS_INSTALL_INTERFACE PREPEND "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/entt/natvis/")
  215. target_sources(EnTT INTERFACE ${NATVIS_BUILD_INTERFACE} ${NATVIS_INSTALL_INTERFACE})
  216. endif()
  217. # Install EnTT and all related files
  218. option(ENTT_INSTALL "Install EnTT and all related files." OFF)
  219. if(ENTT_INSTALL)
  220. # Install pkg-config file
  221. include(JoinPaths)
  222. set(EnTT_PKGCONFIG ${CMAKE_CURRENT_BINARY_DIR}/entt.pc)
  223. join_paths(EnTT_PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
  224. configure_file(
  225. ${EnTT_SOURCE_DIR}/cmake/in/entt.pc.in
  226. ${EnTT_PKGCONFIG}
  227. @ONLY
  228. )
  229. install(
  230. FILES ${EnTT_PKGCONFIG}
  231. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  232. )
  233. # Install EnTT
  234. include(CMakePackageConfigHelpers)
  235. install(
  236. TARGETS EnTT
  237. EXPORT EnTTTargets
  238. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  239. )
  240. write_basic_package_version_file(
  241. EnTTConfigVersion.cmake
  242. VERSION ${PROJECT_VERSION}
  243. COMPATIBILITY AnyNewerVersion
  244. )
  245. configure_package_config_file(
  246. ${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
  247. EnTTConfig.cmake
  248. INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  249. )
  250. export(
  251. EXPORT EnTTTargets
  252. FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
  253. NAMESPACE EnTT::
  254. )
  255. install(
  256. EXPORT EnTTTargets
  257. FILE EnTTTargets.cmake
  258. DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  259. NAMESPACE EnTT::
  260. )
  261. install(
  262. FILES
  263. ${PROJECT_BINARY_DIR}/EnTTConfig.cmake
  264. ${PROJECT_BINARY_DIR}/EnTTConfigVersion.cmake
  265. DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
  266. )
  267. install(
  268. DIRECTORY src/
  269. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  270. FILES_MATCHING
  271. PATTERN "*.h"
  272. PATTERN "*.hpp"
  273. PATTERN "*.natvis"
  274. )
  275. export(PACKAGE EnTT)
  276. endif()
  277. # Tests and testbed
  278. option(ENTT_BUILD_TESTING "Enable building tests." OFF)
  279. option(ENTT_BUILD_TESTBED "Enable building testbed." OFF)
  280. if(ENTT_BUILD_TESTING OR ENTT_BUILD_TESTBED)
  281. set(ENTT_ID_TYPE std::uint32_t CACHE STRING "Type of identifiers to use for tests and testbed")
  282. set(ENTT_CXX_STD cxx_std_20 CACHE STRING "C++ standard revision to use for tests and testbed")
  283. # Tests and tesetbed do not work together because SDL gets confused with EnTT tests
  284. if(ENTT_BUILD_TESTING)
  285. option(ENTT_FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  286. option(ENTT_BUILD_BENCHMARK "Build benchmark." OFF)
  287. option(ENTT_BUILD_EXAMPLE "Build examples." OFF)
  288. option(ENTT_BUILD_LIB "Build lib tests." OFF)
  289. option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)
  290. include(CTest)
  291. enable_testing()
  292. add_subdirectory(test)
  293. elseif(ENTT_BUILD_TESTBED)
  294. add_subdirectory(testbed)
  295. endif()
  296. endif()
  297. # Documentation
  298. option(ENTT_BUILD_DOCS "Enable building with documentation." OFF)
  299. if(ENTT_BUILD_DOCS)
  300. add_subdirectory(docs)
  301. endif()