diff --git a/CMakeLists.txt b/CMakeLists.txt index 7610f9c2..b0f6e78e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,7 +246,9 @@ endif() if (S2_USE_SYSTEM_INCLUDES) target_include_directories(s2 SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) else () - target_include_directories(s2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) + target_include_directories(s2 PUBLIC + $ + $) endif () # Add version information to the target @@ -432,6 +434,17 @@ install(TARGETS ${S2_TARGETS} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") +# Create an export type "s2Targets" detailing the targetable artifacts created +# by this project. +install(TARGETS s2 EXPORT s2Targets) +# Install the export targets as a CMake config file in the share/s2 folder so +# that they can referenced by downstream projects as `s2::s2` after a +# successful `find_package` call. +install(EXPORT s2Targets + NAMESPACE s2 + FILE s2Targets.cmake + DESTINATION share/s2/) + if (BUILD_TESTS) if (NOT GOOGLETEST_ROOT) message(FATAL_ERROR "BUILD_TESTS requires GOOGLETEST_ROOT") @@ -586,3 +599,13 @@ endif() if (${SWIG_FOUND} AND ${Python3_FOUND}) add_subdirectory("src/python" python) endif() + +include(CMakePackageConfigHelpers) + +# Generate the config file that includes the exports. +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/s2Config.cmake" + INSTALL_DESTINATION "share/s2/" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/s2Config.cmake DESTINATION "share/s2/") diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 00000000..939d9330 --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/s2Targets.cmake")