Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modern cmake config targets to s2geometry #339

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ endif()
if (S2_USE_SYSTEM_INCLUDES)
target_include_directories(s2 SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
jmr marked this conversation as resolved.
Show resolved Hide resolved
else ()
target_include_directories(s2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(s2 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)
endif ()

# Add version information to the target
Expand Down Expand Up @@ -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)
jherico marked this conversation as resolved.
Show resolved Hide resolved
jherico marked this conversation as resolved.
Show resolved Hide resolved
# 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")
Expand Down Expand Up @@ -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/")
3 changes: 3 additions & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/s2Targets.cmake")