|
| 1 | +cmake_minimum_required(VERSION 3.14) |
| 2 | +project(CppGeometryLibrary VERSION 1.0.0 LANGUAGES CXX) |
| 3 | + |
| 4 | +# Header-only interface target |
| 5 | +add_library(CppGeometryLibrary INTERFACE) |
| 6 | +add_library(CppGeometryLibrary::CppGeometryLibrary ALIAS CppGeometryLibrary) |
| 7 | + |
| 8 | +target_include_directories(CppGeometryLibrary INTERFACE |
| 9 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 10 | + $<INSTALL_INTERFACE:include> |
| 11 | +) |
| 12 | +target_compile_features(CppGeometryLibrary INTERFACE cxx_std_17) |
| 13 | + |
| 14 | +# Tests (optional, enabled when this is the top-level project) |
| 15 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 16 | + include(CTest) |
| 17 | + if(BUILD_TESTING) |
| 18 | + find_package(GTest REQUIRED) |
| 19 | + add_executable(cpp_geometry_tests tests/Tests.cpp) |
| 20 | + target_link_libraries(cpp_geometry_tests |
| 21 | + PRIVATE CppGeometryLibrary GTest::GTest GTest::Main |
| 22 | + ) |
| 23 | + add_test(NAME cpp_geometry_tests COMMAND cpp_geometry_tests) |
| 24 | + endif() |
| 25 | +endif() |
| 26 | + |
| 27 | +# Installation |
| 28 | +include(GNUInstallDirs) |
| 29 | + |
| 30 | +install(DIRECTORY include/ |
| 31 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 32 | +) |
| 33 | +install(TARGETS CppGeometryLibrary |
| 34 | + EXPORT CppGeometryLibraryTargets |
| 35 | +) |
| 36 | +install(EXPORT CppGeometryLibraryTargets |
| 37 | + FILE CppGeometryLibraryTargets.cmake |
| 38 | + NAMESPACE CppGeometryLibrary:: |
| 39 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary |
| 40 | +) |
| 41 | + |
| 42 | +include(CMakePackageConfigHelpers) |
| 43 | + |
| 44 | +configure_package_config_file( |
| 45 | + cmake/CppGeometryLibraryConfig.cmake.in |
| 46 | + ${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfig.cmake |
| 47 | + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary |
| 48 | +) |
| 49 | +write_basic_package_version_file( |
| 50 | + ${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfigVersion.cmake |
| 51 | + VERSION ${PROJECT_VERSION} |
| 52 | + COMPATIBILITY AnyNewerVersion |
| 53 | +) |
| 54 | +install(FILES |
| 55 | + ${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfig.cmake |
| 56 | + ${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfigVersion.cmake |
| 57 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary |
| 58 | +) |
0 commit comments