From c9f9f2602452b49f2285aba3e8d2d0173418d6bf Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 10 Jan 2024 09:24:43 -0800 Subject: [PATCH 1/5] Add modern cmake config targets to s2geometry --- CMakeLists.txt | 23 ++++++++++++++++++++++- Config.cmake.in | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 7610f9c2..04258012 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,7 +246,10 @@ 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 +435,13 @@ install(TARGETS ${S2_TARGETS} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") +install(TARGETS s2 EXPORT s2Targets) +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 +596,14 @@ endif() if (${SWIG_FOUND} AND ${Python3_FOUND}) add_subdirectory("src/python" python) endif() + +include(CMakePackageConfigHelpers) + +# generate the config file that is 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..ac09b2dc --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/s2Targets.cmake" ) From 36545ece026619a0cd34bf3b4967bfa54c88d91b Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Fri, 26 Jan 2024 08:10:44 +0100 Subject: [PATCH 2/5] Config.cmake.in: Fix formatting --- Config.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.cmake.in b/Config.cmake.in index ac09b2dc..939d9330 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -1,3 +1,3 @@ @PACKAGE_INIT@ -include ( "${CMAKE_CURRENT_LIST_DIR}/s2Targets.cmake" ) +include("${CMAKE_CURRENT_LIST_DIR}/s2Targets.cmake") From 40da982fbd4aed262aebbdb7cd289be1e8cf6af6 Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Fri, 26 Jan 2024 08:20:58 +0100 Subject: [PATCH 3/5] CMakeLists.txt: Reformat Fix formatting to be consistent with existing formatting. Mostly, this is aligning after "(" if possible without a line wrap and moving ")" to be on a line with other content. [")" handling does not seem to be consistent with the CMake docs, but is consistent with the rest of the file.] --- CMakeLists.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04258012..2c986b23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,8 +248,7 @@ if (S2_USE_SYSTEM_INCLUDES) else () target_include_directories(s2 PUBLIC $ - $ - ) + $) endif () # Add version information to the target @@ -437,10 +436,9 @@ install(TARGETS ${S2_TARGETS} install(TARGETS s2 EXPORT s2Targets) install(EXPORT s2Targets - NAMESPACE s2 - FILE s2Targets.cmake - DESTINATION share/s2/ -) + NAMESPACE s2 + FILE s2Targets.cmake + DESTINATION share/s2/) if (BUILD_TESTS) if (NOT GOOGLETEST_ROOT) @@ -599,11 +597,10 @@ endif() include(CMakePackageConfigHelpers) -# generate the config file that is includes the exports +# 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 -) + NO_CHECK_REQUIRED_COMPONENTS_MACRO) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/s2Config.cmake DESTINATION "share/s2/") From 7860b23646f857e524eaf26337da05ce15842ace Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Fri, 26 Jan 2024 12:40:16 -0800 Subject: [PATCH 4/5] Apply suggestions from code review --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c986b23..6e1d206f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -434,7 +434,10 @@ 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 From f599816305e88b322c3243bac62018bd5704e1da Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Fri, 26 Jan 2024 21:46:53 +0100 Subject: [PATCH 5/5] CMakeLists.txt: Format comments --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e1d206f..b0f6e78e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -434,10 +434,12 @@ 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 +# 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 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