|
| 1 | +cmake_minimum_required(VERSION 3.15) |
| 2 | + |
| 3 | +project(AutoDiff |
| 4 | + VERSION 0.4.0 |
| 5 | + LANGUAGES CXX |
| 6 | + DESCRIPTION "" |
| 7 | +) |
| 8 | + |
| 9 | +# PROJECT_IS_TOP_LEVEL is introduced in v3.21 |
| 10 | +if (CMAKE_VERSION VERSION_LESS 3.21) |
| 11 | + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 12 | + set(PROJECT_IS_TOP_LEVEL TRUE) |
| 13 | + else () |
| 14 | + set(PROJECT_IS_TOP_LEVEL FALSE) |
| 15 | + endif () |
| 16 | +endif () |
| 17 | + |
| 18 | +add_library(AutoDiff INTERFACE) |
| 19 | +add_library(AutoDiff::AutoDiff ALIAS AutoDiff) |
| 20 | +target_include_directories( |
| 21 | + AutoDiff INTERFACE |
| 22 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 23 | + $<INSTALL_INTERFACE:include> |
| 24 | +) |
| 25 | +target_compile_features(AutoDiff INTERFACE cxx_std_17) |
| 26 | + |
| 27 | +if (${PROJECT_IS_TOP_LEVEL}) |
| 28 | + |
| 29 | + include(CTest) |
| 30 | + if (BUILD_TESTING) |
| 31 | + add_subdirectory(tests) |
| 32 | + endif () |
| 33 | + |
| 34 | + option(AUTODIFF_BUILD_EXAMPLES "Build example projects" OFF) |
| 35 | + if (AUTODIFF_BUILD_EXAMPLES) |
| 36 | + add_subdirectory(examples) |
| 37 | + endif () |
| 38 | + |
| 39 | + option(AUTODIFF_BUILD_BENCHMARKS "Build benchmarks" OFF) |
| 40 | + if (AUTODIFF_BUILD_BENCHMARKS) |
| 41 | + add_subdirectory(benchmarks) |
| 42 | + endif () |
| 43 | + |
| 44 | + include(GNUInstallDirs) |
| 45 | + |
| 46 | + set(AUTODIFF_CMAKE_CONFIG_DESTINATION lib/cmake/AutoDiff) |
| 47 | + |
| 48 | + include(CMakePackageConfigHelpers) |
| 49 | + configure_package_config_file( |
| 50 | + "${CMAKE_CURRENT_LIST_DIR}/CMake/AutoDiffConfig.cmake.in" |
| 51 | + "${CMAKE_CURRENT_BINARY_DIR}/AutoDiffConfig.cmake" |
| 52 | + INSTALL_DESTINATION "${AUTODIFF_CMAKE_CONFIG_DESTINATION}" |
| 53 | + ) |
| 54 | + write_basic_package_version_file( |
| 55 | + "${CMAKE_CURRENT_BINARY_DIR}/AutoDiffConfigVersion.cmake" |
| 56 | + VERSION ${CMAKE_PROJECT_VERSION} |
| 57 | + COMPATIBILITY SameMajorVersion |
| 58 | + ) |
| 59 | + install( |
| 60 | + FILES |
| 61 | + "${CMAKE_CURRENT_BINARY_DIR}/AutoDiffConfig.cmake" |
| 62 | + "${CMAKE_CURRENT_BINARY_DIR}/AutoDiffConfigVersion.cmake" |
| 63 | + DESTINATION |
| 64 | + "${AUTODIFF_CMAKE_CONFIG_DESTINATION}" |
| 65 | + ) |
| 66 | + |
| 67 | + install( |
| 68 | + TARGETS AutoDiff EXPORT AutoDiffTargets |
| 69 | + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 70 | + ) |
| 71 | + export(EXPORT AutoDiffTargets |
| 72 | + FILE |
| 73 | + "${CMAKE_CURRENT_BINARY_DIR}/AutoDiffTargets.cmake" |
| 74 | + NAMESPACE |
| 75 | + AutoDiff:: |
| 76 | + ) |
| 77 | + install(EXPORT AutoDiffTargets |
| 78 | + FILE |
| 79 | + AutoDiffTargets.cmake |
| 80 | + NAMESPACE |
| 81 | + AutoDiff:: |
| 82 | + DESTINATION |
| 83 | + "${AUTODIFF_CMAKE_CONFIG_DESTINATION}" |
| 84 | + ) |
| 85 | + |
| 86 | + install(DIRECTORY include/AutoDiff |
| 87 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 88 | + ) |
| 89 | + |
| 90 | +endif () |
0 commit comments