CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #
  2. # EnTT
  3. #
  4. cmake_minimum_required(VERSION 3.12.4)
  5. #
  6. # Building in-tree is not allowed (we take care of your craziness).
  7. #
  8. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  9. message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the source code and call cmake from there. Thank you.")
  10. endif()
  11. #
  12. # Read project version
  13. #
  14. set(ENTT_VERSION_REGEX "#define ENTT_VERSION_.*[ \t]+(.+)")
  15. file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/src/entt/config/version.h" ENTT_VERSION REGEX ${ENTT_VERSION_REGEX})
  16. list(TRANSFORM ENTT_VERSION REPLACE ${ENTT_VERSION_REGEX} "\\1")
  17. string(JOIN "." ENTT_VERSION ${ENTT_VERSION})
  18. #
  19. # Project configuration
  20. #
  21. project(
  22. EnTT
  23. VERSION ${ENTT_VERSION}
  24. DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
  25. HOMEPAGE_URL "https://github.com/skypjack/entt"
  26. LANGUAGES CXX
  27. )
  28. if(NOT CMAKE_BUILD_TYPE)
  29. set(CMAKE_BUILD_TYPE Debug)
  30. endif()
  31. message("*")
  32. message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
  33. message("* Copyright (c) 2017-2020 Michele Caini <michele.caini@gmail.com>")
  34. message("*")
  35. option(USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." ON)
  36. option(USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF)
  37. #
  38. # Compiler stuff
  39. #
  40. if(NOT WIN32 AND USE_LIBCPP)
  41. include(CheckCXXSourceCompiles)
  42. include(CMakePushCheckState)
  43. cmake_push_check_state()
  44. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
  45. check_cxx_source_compiles("
  46. #include<type_traits>
  47. int main() { return std::is_same_v<int, char>; }
  48. " HAS_LIBCPP)
  49. if(NOT HAS_LIBCPP)
  50. message(WARNING "The option USE_LIBCPP is set (by default) but libc++ is not available. The flag will not be added to the target.")
  51. endif()
  52. cmake_pop_check_state()
  53. endif()
  54. #
  55. # Add EnTT target
  56. #
  57. include(GNUInstallDirs)
  58. add_library(EnTT INTERFACE)
  59. add_library(EnTT::EnTT ALIAS EnTT)
  60. target_include_directories(
  61. EnTT
  62. INTERFACE
  63. $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src>
  64. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  65. )
  66. if(USE_ASAN)
  67. target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>)
  68. target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>)
  69. endif()
  70. if(HAS_LIBCPP)
  71. target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
  72. endif()
  73. target_compile_features(EnTT INTERFACE cxx_std_17)
  74. #
  75. # Install EnTT
  76. #
  77. include(CMakePackageConfigHelpers)
  78. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  79. set(CUSTOM_INSTALL_CONFIGDIR cmake)
  80. else()
  81. set(CUSTOM_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/entt)
  82. endif()
  83. install(TARGETS EnTT EXPORT EnTTTargets)
  84. configure_package_config_file(
  85. ${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
  86. EnTTConfig.cmake
  87. INSTALL_DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  88. PATH_VARS CMAKE_INSTALL_INCLUDEDIR
  89. )
  90. write_basic_package_version_file(
  91. EnTTConfigVersion.cmake
  92. VERSION ${PROJECT_VERSION}
  93. COMPATIBILITY AnyNewerVersion
  94. )
  95. install(
  96. EXPORT EnTTTargets
  97. FILE EnTTTargets.cmake
  98. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  99. NAMESPACE EnTT::
  100. )
  101. install(
  102. FILES
  103. ${PROJECT_BINARY_DIR}/EnTTConfig.cmake
  104. ${PROJECT_BINARY_DIR}/EnTTConfigVersion.cmake
  105. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  106. )
  107. install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  108. #
  109. # Tests
  110. #
  111. option(BUILD_TESTING "Enable testing with ctest." OFF)
  112. if(BUILD_TESTING)
  113. option(FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  114. option(BUILD_BENCHMARK "Build benchmark." OFF)
  115. option(BUILD_LIB "Build lib example." OFF)
  116. option(BUILD_SNAPSHOT "Build snapshot example." OFF)
  117. enable_testing()
  118. add_subdirectory(test)
  119. endif()
  120. #
  121. # Documentation
  122. #
  123. option(BUILD_DOCS "Enable building with documentation." OFF)
  124. if(BUILD_DOCS)
  125. find_package(Doxygen 1.8)
  126. if(DOXYGEN_FOUND)
  127. add_subdirectory(docs)
  128. endif()
  129. endif()
  130. #
  131. # AOB
  132. #
  133. add_custom_target(
  134. aob
  135. SOURCES
  136. .github/workflows/build.yml
  137. .github/workflows/coverage.yml
  138. .github/workflows/deploy.yml
  139. .github/FUNDING.yml
  140. AUTHORS
  141. CONTRIBUTING.md
  142. LICENSE
  143. README.md
  144. TODO
  145. )