🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
6.0 KiB

  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.1.0)
  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. option(USE_COMPILE_OPTIONS "Use compile options from EnTT." ON)
  30. #
  31. # Compiler stuff
  32. #
  33. if(NOT MSVC 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, int> ? 0 : 1; }
  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. 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:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
  64. target_link_libraries(EnTT INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
  65. endif()
  66. if(USE_COMPILE_OPTIONS)
  67. target_compile_options(
  68. EnTT
  69. INTERFACE $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-O0 -g>
  70. # it seems that -O3 ruins a bit the performance when using clang ...
  71. INTERFACE $<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:Clang>>:-O2>
  72. # ... on the other side, GCC is incredibly comfortable with it.
  73. INTERFACE $<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU>>:-O3>
  74. )
  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. )
  96. #
  97. # Build tree package config file
  98. #
  99. configure_file(cmake/in/EnTTBuildConfig.cmake.in EnTTConfig.cmake @ONLY)
  100. include(CMakePackageConfigHelpers)
  101. #
  102. # Install tree package config file
  103. #
  104. configure_package_config_file(
  105. cmake/in/EnTTConfig.cmake.in
  106. ${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  107. INSTALL_DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  108. PATH_VARS CMAKE_INSTALL_INCLUDEDIR
  109. )
  110. write_basic_package_version_file(
  111. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  112. VERSION ${PROJECT_VERSION}
  113. COMPATIBILITY AnyNewerVersion
  114. )
  115. install(
  116. FILES
  117. ${EnTT_BINARY_DIR}/${CUSTOM_INSTALL_CONFIGDIR}/EnTTConfig.cmake
  118. ${EnTT_BINARY_DIR}/EnTTConfigVersion.cmake
  119. DESTINATION ${CUSTOM_INSTALL_CONFIGDIR}
  120. )
  121. export(PACKAGE EnTT)
  122. #
  123. # Tests
  124. #
  125. option(BUILD_TESTING "Enable testing with ctest." OFF)
  126. if(BUILD_TESTING)
  127. set(THREADS_PREFER_PTHREAD_FLAG ON)
  128. find_package(Threads REQUIRED)
  129. option(FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
  130. if(FIND_GTEST_PACKAGE)
  131. find_package(GTest REQUIRED)
  132. else()
  133. # gtest, gtest_main, gmock and gmock_main targets are available from now on
  134. set(GOOGLETEST_DEPS_DIR ${EnTT_SOURCE_DIR}/deps/googletest)
  135. configure_file(${EnTT_SOURCE_DIR}/cmake/in/googletest.in ${GOOGLETEST_DEPS_DIR}/CMakeLists.txt)
  136. execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${GOOGLETEST_DEPS_DIR})
  137. execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${GOOGLETEST_DEPS_DIR})
  138. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  139. add_subdirectory(${GOOGLETEST_DEPS_DIR}/src ${GOOGLETEST_DEPS_DIR}/build)
  140. target_compile_features(gmock_main PRIVATE $<TARGET_PROPERTY:EnTT,INTERFACE_COMPILE_FEATURES>)
  141. target_compile_features(gmock PRIVATE $<TARGET_PROPERTY:EnTT,INTERFACE_COMPILE_FEATURES>)
  142. add_library(GTest::Main ALIAS gtest_main)
  143. endif()
  144. option(BUILD_BENCHMARK "Build benchmark." OFF)
  145. option(BUILD_LIB "Build lib example." OFF)
  146. option(BUILD_MOD "Build mod example." OFF)
  147. option(BUILD_SNAPSHOT "Build snapshot example." OFF)
  148. enable_testing()
  149. add_subdirectory(test)
  150. endif()
  151. #
  152. # Documentation
  153. #
  154. option(BUILD_DOCS "Enable building with documentation." OFF)
  155. if(BUILD_DOCS)
  156. find_package(Doxygen 1.8)
  157. if(DOXYGEN_FOUND)
  158. add_subdirectory(docs)
  159. endif()
  160. endif()
  161. #
  162. # AOB
  163. #
  164. add_custom_target(
  165. entt_aob
  166. SOURCES
  167. appveyor.yml
  168. AUTHORS
  169. CONTRIBUTING.md
  170. LICENSE
  171. README.md
  172. TODO
  173. .travis.yml
  174. )