CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. # Project configuration
  13. #
  14. project(
  15. EnTT
  16. VERSION 3.3.0
  17. DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
  18. HOMEPAGE_URL "https://github.com/skypjack/entt"
  19. LANGUAGES CXX)
  20. include(GNUInstallDirs)
  21. if(NOT CMAKE_BUILD_TYPE)
  22. set(CMAKE_BUILD_TYPE Debug)
  23. endif()
  24. message("*")
  25. message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
  26. message("* Copyright (c) 2017-2020 Michele Caini <michele.caini@gmail.com>")
  27. message("*")
  28. option(USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." ON)
  29. option(USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF)
  30. #
  31. # Compiler stuff
  32. #
  33. if(NOT WIN32 AND USE_LIBCPP)
  34. include(CheckCXXSourceCompiles)
  35. include(CMakePushCheckState)
  36. cmake_push_check_state()
  37. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
  38. check_cxx_source_compiles("
  39. #include<type_traits>
  40. int main() { return std::is_same_v<int, char>; }
  41. " HAS_LIBCPP)
  42. if(NOT HAS_LIBCPP)
  43. message(WARNING "The option USE_LIBCPP is set (by default) but libc++ is not available. The flag will not be added to the target.")
  44. endif()
  45. cmake_pop_check_state()
  46. endif()
  47. #
  48. # Add EnTT target
  49. #
  50. add_library(EnTT INTERFACE)
  51. add_library(EnTT::EnTT ALIAS EnTT)
  52. configure_file(${EnTT_SOURCE_DIR}/cmake/in/version.h.in ${EnTT_SOURCE_DIR}/src/entt/config/version.h @ONLY)
  53. target_include_directories(
  54. EnTT
  55. INTERFACE
  56. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
  57. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  58. )
  59. target_compile_definitions(
  60. EnTT
  61. INTERFACE
  62. $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:DEBUG>
  63. $<$<AND:$<CONFIG:Release>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:RELEASE>
  64. )
  65. if(USE_ASAN)
  66. target_compile_options(EnTT INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-fsanitize=address -fno-omit-frame-pointer>)
  67. target_link_libraries(EnTT INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-fsanitize=address -fno-omit-frame-pointer>)
  68. endif()
  69. if(HAS_LIBCPP)
  70. target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
  71. endif()
  72. target_compile_features(EnTT INTERFACE cxx_std_17)
  73. #
  74. # Install EnTT
  75. #
  76. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  77. set(CUSTOM_INSTALL_CONFIGDIR cmake)
  78. else()
  79. set(CUSTOM_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/entt)
  80. endif()
  81. install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  82. install(TARGETS EnTT EXPORT EnTTTargets)
  83. export(EXPORT EnTTTargets FILE ${EnTT_BINARY_DIR}/EnTTTargets.cmake)
  84. install(
  85. EXPORT EnTTTargets
  86. FILE EnTTTargets.cmake
  87. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  88. NAMESPACE EnTT::
  89. )
  90. #
  91. # Build tree package config file
  92. #
  93. configure_file(cmake/in/EnTTBuildConfig.cmake.in EnTTConfig.cmake @ONLY)
  94. include(CMakePackageConfigHelpers)
  95. #
  96. # Install tree package config file
  97. #
  98. configure_package_config_file(
  99. cmake/in/EnTTConfig.cmake.in
  100. ${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  101. INSTALL_DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  102. PATH_VARS CMAKE_INSTALL_INCLUDEDIR
  103. )
  104. write_basic_package_version_file(
  105. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  106. VERSION ${PROJECT_VERSION}
  107. COMPATIBILITY AnyNewerVersion
  108. )
  109. install(
  110. FILES
  111. ${EnTT_BINARY_DIR}/${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  112. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  113. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  114. )
  115. export(PACKAGE EnTT)
  116. #
  117. # Tests
  118. #
  119. option(BUILD_TESTING "Enable testing with ctest." OFF)
  120. if(BUILD_TESTING)
  121. option(FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  122. option(BUILD_BENCHMARK "Build benchmark." OFF)
  123. option(BUILD_LIB "Build lib example." OFF)
  124. option(BUILD_SNAPSHOT "Build snapshot example." OFF)
  125. enable_testing()
  126. add_subdirectory(test)
  127. endif()
  128. #
  129. # Documentation
  130. #
  131. option(BUILD_DOCS "Enable building with documentation." OFF)
  132. if(BUILD_DOCS)
  133. find_package(Doxygen 1.8)
  134. if(DOXYGEN_FOUND)
  135. add_subdirectory(docs)
  136. endif()
  137. endif()
  138. #
  139. # AOB
  140. #
  141. FILE(GLOB GH_WORKFLOWS .github/workflows/*.yml)
  142. add_custom_target(
  143. entt_aob
  144. SOURCES
  145. ${GH_WORKFLOWS}
  146. .github/FUNDING.yml
  147. AUTHORS
  148. CONTRIBUTING.md
  149. LICENSE
  150. README.md
  151. TODO
  152. )