From 29b0440d0dfb07bcecd8ea743a8291f3049123ff Mon Sep 17 00:00:00 2001 From: Liam White Date: Wed, 25 Mar 2026 20:47:39 -0400 Subject: [PATCH 1/2] fix(cmake): export an installable GeometryCentral package Install and export the geometry-central target as a CMake package so downstream projects can use find_package(GeometryCentral CONFIG) without a custom FindGeometryCentral.cmake module. Also split the build and install interfaces so the exported target does not depend on this project's local helper targets, while installed consumers still inherit Eigen transitively. --- CMakeLists.txt | 34 +++++++++++++++++++++++----- cmake/GeometryCentralConfig.cmake.in | 12 ++++++++++ src/CMakeLists.txt | 19 ++++++++++++---- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 cmake/GeometryCentralConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 72fa64c1..b85c4cf5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,11 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # look for stuff in the /cmake directory include(UpdateCacheVariable) +# Install a standard CMake config package so downstream users do not need a custom FindGeometryCentral.cmake module. +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(GC_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/GeometryCentral") # Work with non-standard homebrew installations # (from ceres build system) @@ -50,16 +55,33 @@ SET(GC_HAVE_SUITESPARSE ${GC_HAVE_SUITESPARSE} PARENT_SCOPE) ### Recurse to the source code add_subdirectory(src) -# install +# Install the library and export it as an imported target for find_package(). install( TARGETS geometry-central - ARCHIVE DESTINATION lib - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib) + EXPORT GeometryCentralTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install( - DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION include + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" PATTERN "*.ipp") + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/GeometryCentralConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/GeometryCentralConfig.cmake" + INSTALL_DESTINATION "${GC_INSTALL_CMAKEDIR}") + +# Install the exported target definitions and the package entry point side-by-side. +install( + EXPORT GeometryCentralTargets + NAMESPACE geometry-central:: + DESTINATION "${GC_INSTALL_CMAKEDIR}") + +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/GeometryCentralConfig.cmake" + DESTINATION "${GC_INSTALL_CMAKEDIR}") diff --git a/cmake/GeometryCentralConfig.cmake.in b/cmake/GeometryCentralConfig.cmake.in new file mode 100644 index 00000000..e0d9ac72 --- /dev/null +++ b/cmake/GeometryCentralConfig.cmake.in @@ -0,0 +1,12 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +find_dependency(Eigen3 3.3 REQUIRED NO_MODULE) + +include("${CMAKE_CURRENT_LIST_DIR}/GeometryCentralTargets.cmake") + +# Reattach Eigen after loading the exported target so installed consumers still +# inherit it transitively without exporting this project's local helper target. +set_property(TARGET geometry-central::geometry-central APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Eigen3::Eigen) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b74e243d..649d0d90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,11 +178,22 @@ SET(HEADERS # Create a single library for the project add_library(geometry-central ${SRCS} ${HEADERS}) -# Includes from this project -target_include_directories(geometry-central PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include") +# Public headers include vendored headers directly, so build-tree consumers need +# those include roots explicitly. The install tree collapses them under the +# single installed include directory. +target_include_directories(geometry-central + PUBLIC + $ + $ + $ + $ + $ + PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/../deps/nanoflann/include") -# Add all includes and link libraries from dependencies, which were populated in deps/CMakeLists.txt -target_link_libraries(geometry-central PUBLIC ${GC_DEP_LIBS}) +# Keep Eigen out of the exported build-tree link interface to avoid exporting the +# local helper target created in deps/CMakeLists.txt. The installed package adds +# Eigen3::Eigen back after calling find_dependency(Eigen3). # Set compiler properties for the library target_compile_features(geometry-central PUBLIC cxx_std_11) From f5393c3590db75b434127ff5e8982ec2fe9aa9aa Mon Sep 17 00:00:00 2001 From: Liam White Date: Wed, 25 Mar 2026 20:48:17 -0400 Subject: [PATCH 2/2] fix(cmake): install bundled public dependency headers Install the vendored headers referenced by public geometry-central headers so the install tree is self-contained. This removes the need for downstream post-install copy steps for happly.h and nanort/nanort.h. --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b85c4cf5..6a401daf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,8 +61,7 @@ install( EXPORT GeometryCentralTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ @@ -71,6 +70,16 @@ install( PATTERN "*.h" PATTERN "*.ipp") +# These vendored headers are referenced by installed public headers, so ship them +# in the install tree rather than relying on downstream postInstall copy steps. +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/deps/happly/happly.h" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/deps/nanort/include/nanort/nanort.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nanort") + configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/GeometryCentralConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/GeometryCentralConfig.cmake"