Commit decb37be authored by Jonas Jelten's avatar Jonas Jelten 🥕
Browse files

improve elsa importing experience

also install our bundled eigen headers
parent e17c8b9b
......@@ -41,6 +41,9 @@ set(ELSA_SANITIZER
set(ELSA_CUDA_ARCH_TYPE "auto" CACHE STRING "Set CUDA architectures")
option(SYSTEM_EIGEN "Build elsa using the system eigen installation" OFF)
option(SYSTEM_SPDLOG "Build elsa using the system spdlog installation" OFF)
# ------------ general setup -----------
# ------------
......@@ -65,34 +68,90 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# set where to install the exports/targets
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/elsa)
# ------------ dependencies ------------
# ------------
# only add the dependencies if elsa is stand-alone
if(ELSA_MASTER_PROJECT)
# setup Eigen Library
CPMAddPackage(
NAME eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen
# Currently we're on a random master branch commit, until Eigen 3.4 will be released we kind of have to
# stick with it, see also https://gitlab.lrz.de/IP/elsa/-/issues/91 for a little discussion on it
GIT_TAG c1b0aea65
DOWNLOAD_ONLY YES # Eigen's CMakelists are not intended for library use
)
if(SYSTEM_EIGEN)
message(STATUS "Using system-wide Eigen library...")
find_package(Eigen3 REQUIRED)
else()
# setup custom Eigen Library
# once there's a proper release,
# the system-eigen has to be a drop-in replacement for the git-version
CPMAddPackage(
NAME eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen
# Currently we're on a random master branch commit, until Eigen 3.4 will be released we kind of have to
# stick with it, see also https://gitlab.lrz.de/IP/elsa/-/issues/91 for a little discussion on it
GIT_TAG c1b0aea65
DOWNLOAD_ONLY YES # Eigen's CMakelists are not intended for library use
)
# Add the Eigen library target to link against
if(eigen3_ADDED)
add_library(Eigen3::Eigen INTERFACE IMPORTED)
target_include_directories(Eigen3::Eigen INTERFACE ${eigen3_SOURCE_DIR})
# Add the Eigen library target to link against
if(eigen3_ADDED)
message(STATUS "Using bundled Eigen version in ${eigen3_SOURCE_DIR}")
# this target is set-up as a drop-in replacement
# for a system eigen package.
set(EIGEN_BUNDLED_INSTALLDIR "elsa/Eigen")
add_library(Eigen INTERFACE)
add_library(Eigen3::Eigen ALIAS Eigen)
target_include_directories(Eigen INTERFACE
$<BUILD_INTERFACE:${eigen3_SOURCE_DIR}>
$<INSTALL_INTERFACE:${EIGEN_BUNDLED_INSTALLDIR}>
)
# register eigen in the build tree
export(TARGETS Eigen FILE "${CMAKE_CURRENT_BINARY_DIR}/elsa/eigen3Targets.cmake")
# install custom elsa
if(ELSA_INSTALL)
install(TARGETS Eigen EXPORT eigenExport)
install(EXPORT eigenExport
NAMESPACE Eigen3::
FILE "eigen3Targets.cmake"
DESTINATION ${INSTALL_CONFIG_DIR}
)
install(DIRECTORY "${eigen3_SOURCE_DIR}/Eigen/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${EIGEN_BUNDLED_INSTALLDIR}"
)
endif()
endif()
endif()
# setup spdlog Library
CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.9.0
OPTIONS "SPDLOG_INSTALL ON"
)
if(SYSTEM_SPDLOG)
message(STATUS "Using system-wide spdlog library...")
find_package(spdlog REQUIRED)
else()
# setup bundled spdlog
# this already reads spdlog's cmake definitions
CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.9.0
OPTIONS "SPDLOG_INSTALL ON"
)
message(STATUS "Using bundled spdlog version in ${spdlog_SOURCE_DIR}")
# because spdlog didn't do that on its own, we export the target.
# this is just for the in-buildtree linking, won't be installed.
# store in the bindir/elsa/ directory, which may be nested
# in other build directories somehow.
export(
TARGETS spdlog_header_only spdlog
FILE "${CMAKE_CURRENT_BINARY_DIR}/elsa/spdlogTargets.cmake"
)
# SPDLOG_INSTALL will manage install and includedir setup
# to $CMAKE_INSTALL_INCLUDEDIR/spdlog
endif()
# setup Dnnl library
find_package(Dnnl)
......@@ -144,12 +203,6 @@ else()
message(STATUS " No dependencies added for elsa, as it is not stand-alone")
endif()
# set where to install the exports/targets
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/elsa)
# include the install_elsa_module function
include(InstallElsaModule)
......
......@@ -74,8 +74,6 @@ Then you can configure elsa via the `find_package(elsa)` statement and link your
Alternatively, you can link more specifically only against the required elsa modules, such as `target_link_libraries(myTarget elsa::core)`.
In your source code, `#include "elsa.h"` to include all of elsa; alternatively, include only the header files you are actually using to minimize compilation times.
As elsa depends on Eigen3 (version 3.3.9 or newer) and spdlog (version 1.7 or newer), you will need to have these packages installed on your system, and you have to point CMake to those installations.
Contributing
------------
To get involved, please see our [contributing page](https://gitlab.lrz.de/IP/elsa/-/blob/master/CONTRIBUTING.md).
......
......@@ -3,11 +3,19 @@
include(CMakeFindDependencyMacro)
set(_dependend_components @INSTALL_MODULE_DEPENDENCIES@)
set(_module_name @module_name@)
foreach(_comp ${_dependend_components})
message(STATUS "Loading: ${_comp}")
foreach(_comp ${_dependend_components})
# no need to find everything again,
# this list is filled up recursively
list(FIND _elsa_modules_found "${_comp}" MOD_LOADED)
if(NOT MOD_LOADED EQUAL "-1")
continue()
endif()
message(STATUS "Elsa module ${_module_name}: loading component ${_comp} in ${CMAKE_CURRENT_LIST_DIR}")
find_dependency(${_comp} REQUIRED HINTS ${CMAKE_CURRENT_LIST_DIR})
if (${_comp}_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/${_comp}Targets.cmake)
endif(${_comp}_FOUND)
list(APPEND _elsa_modules_found "${_comp}")
endif()
endforeach()
@PACKAGE_INIT@
message(STATUS "finding elsa dependencies...")
include(CMakeFindDependencyMacro)
find_dependency(Eigen3 3.3.7 REQUIRED)
find_dependency(OpenMP QUIET)
find_dependency(Threads REQUIRED) # for spdlog
# for spdlog_header_only
find_dependency(Threads REQUIRED)
# when we bundle/git-download these libs
# we have to ensure that an elsa-downstream project uses the same version,
# and the path to this is encoded in our target info files.
set(BUNDLED_DEPS
spdlog
eigen3
)
foreach(DEP ${BUNDLED_DEPS})
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${DEP}Targets.cmake")
# use the bundled version
message(STATUS "using elsa-bundled version of dependency ${DEP}")
include("${CMAKE_CURRENT_LIST_DIR}/${DEP}Targets.cmake")
else()
# use the system version
message(STATUS "finding system-version of dependency ${DEP}...")
find_dependency(${DEP} REQUIRED)
endif()
endforeach()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/spdlogTargets.cmake")
# this is used for in-repo build linking with the `export()` command
include("${CMAKE_CURRENT_LIST_DIR}/spdlogTargets.cmake")
else()
# this should not be needed, since the elsa:: targets provide
# these PUBLIC dependencies transitively
find_dependency(spdlog REQUIRED)
endif()
if(EXISTS "@CMAKE_CUDA_COMPILER@")
enable_language(CUDA)
......@@ -29,6 +39,7 @@ set(_supported_components @ELSA_REGISTERED_COMPONENTS@)
if(NOT elsa_FIND_COMPONENTS)
# no specific components requested, include all
message(STATUS "finding elsa_all module")
find_dependency(elsa_all REQUIRED HINTS ${CMAKE_CURRENT_LIST_DIR})
if (elsa_all_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/elsa_allTargets.cmake)
......@@ -36,6 +47,7 @@ if(NOT elsa_FIND_COMPONENTS)
message(STATUS "elsa found, using all modules")
else()
# Include specific components
message(STATUS "finding requested elsa components")
foreach(_comp ${elsa_FIND_COMPONENTS})
message(STATUS "elsa loading ${_comp}")
if(NOT _comp IN_LIST _supported_components)
......
......@@ -7,13 +7,6 @@ set(MODULE_SOURCES Logger.cpp LogGuard.cpp Timer.cpp)
list(APPEND MODULE_PUBLIC_DEPS "spdlog::spdlog_header_only")
list(APPEND MODULE_PRIVATE_DEPS)
# because spdlog/cpm didn't do that on its own
# this is just for the in-buildtree linking, won't be installed.
# store in the bindir/elsa/ directory, which may be nested
# in other build directories somehow.
export(TARGETS spdlog_header_only
FILE "${CMAKE_CURRENT_BINARY_DIR}/../spdlogTargets.cmake")
ADD_ELSA_MODULE(
logging "${MODULE_HEADERS}" "${MODULE_SOURCES}" INSTALL_DIR PUBLIC_DEPS ${MODULE_PUBLIC_DEPS}
PRIVATE_DEPS ${MODULE_PRIVATE_DEPS}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment