CMakeLists.txt 4.6 KB

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