CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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:${PROJECT_SOURCE_DIR}/src>
  64. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  65. )
  66. target_compile_definitions(
  67. EnTT
  68. INTERFACE
  69. $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:DEBUG>
  70. $<$<AND:$<CONFIG:Release>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:RELEASE>
  71. )
  72. if(USE_ASAN)
  73. target_compile_options(EnTT INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-fsanitize=address -fno-omit-frame-pointer>)
  74. target_link_libraries(EnTT INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-fsanitize=address -fno-omit-frame-pointer>)
  75. endif()
  76. if(HAS_LIBCPP)
  77. target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
  78. endif()
  79. target_compile_features(EnTT INTERFACE cxx_std_17)
  80. #
  81. # Install EnTT
  82. #
  83. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  84. set(CUSTOM_INSTALL_CONFIGDIR cmake)
  85. else()
  86. set(CUSTOM_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/entt)
  87. endif()
  88. install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  89. install(TARGETS EnTT EXPORT EnTTTargets)
  90. export(EXPORT EnTTTargets FILE ${EnTT_BINARY_DIR}/EnTTTargets.cmake)
  91. install(
  92. EXPORT EnTTTargets
  93. FILE EnTTTargets.cmake
  94. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  95. NAMESPACE EnTT::
  96. )
  97. #
  98. # Build tree package config file
  99. #
  100. configure_file(cmake/in/EnTTBuildConfig.cmake.in EnTTConfig.cmake @ONLY)
  101. include(CMakePackageConfigHelpers)
  102. #
  103. # Install tree package config file
  104. #
  105. configure_package_config_file(
  106. cmake/in/EnTTConfig.cmake.in
  107. ${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  108. INSTALL_DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  109. PATH_VARS CMAKE_INSTALL_INCLUDEDIR
  110. )
  111. write_basic_package_version_file(
  112. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  113. VERSION ${PROJECT_VERSION}
  114. COMPATIBILITY AnyNewerVersion
  115. )
  116. install(
  117. FILES
  118. ${EnTT_BINARY_DIR}/${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  119. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  120. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  121. )
  122. export(PACKAGE EnTT)
  123. #
  124. # Tests
  125. #
  126. option(BUILD_TESTING "Enable testing with ctest." OFF)
  127. if(BUILD_TESTING)
  128. option(FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  129. option(BUILD_BENCHMARK "Build benchmark." OFF)
  130. option(BUILD_LIB "Build lib example." OFF)
  131. option(BUILD_SNAPSHOT "Build snapshot example." OFF)
  132. enable_testing()
  133. add_subdirectory(test)
  134. endif()
  135. #
  136. # Documentation
  137. #
  138. option(BUILD_DOCS "Enable building with documentation." OFF)
  139. if(BUILD_DOCS)
  140. find_package(Doxygen 1.8)
  141. if(DOXYGEN_FOUND)
  142. add_subdirectory(docs)
  143. endif()
  144. endif()
  145. #
  146. # AOB
  147. #
  148. set(
  149. AOB_SOURCES
  150. .github/workflows/build.yml
  151. .github/workflows/coverage.yml
  152. .github/FUNDING.yml
  153. AUTHORS
  154. CONTRIBUTING.md
  155. LICENSE
  156. README.md
  157. TODO
  158. )
  159. add_custom_target(aob SOURCES ${AOB_SOURCES})
  160. source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${AOB_SOURCES})