Skip to content
Open
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
43 changes: 37 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
12 changes: 12 additions & 0 deletions cmake/GeometryCentralConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 15 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${EIGEN3_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../deps/happly>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../deps/nanort/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
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)
Expand Down