diff --git a/CMakeLists.txt b/CMakeLists.txt index 72fa64c1..6a401daf 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,42 @@ 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}) install( - DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION include + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING 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" + 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)