Commit e324db72 authored by David Frank's avatar David Frank
Browse files

Added FindSpdlog.cmake;

Spdlog can now be used with find_package(Spdlog) in the main CMake file (necessary for projects including elsa); Further FindEigen was adapted to not need set(EIGEN3_INCLUDE_DIR ...) if it's a submodule; Renamed some CMake variables
parent ff1d4cb1
Pipeline #159169 passed with stages
in 6 minutes and 8 seconds
cmake_minimum_required(VERSION 3.9)
# detect if elsa is being bundled, disable install and tests
if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON)
else()
set(SUBPROJECT ON)
message(STATUS "Including elsa as a subproject")
endif()
project(elsa VERSION 0.5
DESCRIPTION "elsa recon toolbox"
LANGUAGES CXX)
......@@ -16,10 +7,21 @@ project(elsa VERSION 0.5
# ------------ elsa options ------------
# ------------
# detect if elsa is being bundled, disable install and tests
if (NOT DEFINED ELSA_MASTER_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(ELSA_MASTER_PROJECT ON)
else()
set(ELSA_MASTER_PROJECT OFF)
endif()
endif ()
option(ELSA_TESTING "Enable the unit tests of elsa" ON)
option(GIT_SUBMODULE "Check submodules during build" ON)
option(BUILD_ELSA_PROJECTORS_CUDA "Attempts to build CUDA projectors if set" ON)
option(ELSA_TESTING "Enable the unit tests of elsa" ${ELSA_MASTER_PROJECT})
option(ELSA_INSTALL "Generate the install target" ${ELSA_MASTER_PROJECT})
option(GIT_SUBMODULE "Check submodules during build" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_EXAMPLES "Build examples" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_CUDA_PROJECTORS "Attempts to build CUDA projectors if set" ON)
# ------------ general setup -----------
......@@ -35,28 +37,27 @@ include(SetDefaultBuildType)
# set where to install the exports/targets
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake)
# ------------ dependencies ------------
# ------------
# only populate the dependencies, iff it's a standalone project!
if(NOT_SUBPROJECT)
if(ELSA_MASTER_PROJECT)
# include the git submodule update
include(UpdateGitSubmodules)
# setup the Eigen3 library
find_package(Eigen3 3.3 NO_MODULE QUIET) # first try if there is an installed version
if(NOT EIGEN3_INCLUDE_DIR) # if not found, try our submodule
set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/eigen3")
message(STATUS "Using eigen3 submodule at ${EIGEN3_INCLUDE_DIR}")
find_package(Eigen3 3.3 REQUIRED)
endif()
# find Eigen Library
# if you're not using the submodules use set(EIGEN3_INCLUDE_DIR path/to/Eigen3) to point to the Eigen3 directory
find_package(Eigen3 3.3 REQUIRED)
message(STATUS "Using eigen3 submodule at ${EIGEN3_INCLUDE_DIR}")
# find spdlog Library
# if you're not using the submodules use set(Spdlog_INCLUDE_DIR path/to/spdlog) to point to the spdlog directory
find_package(Spdlog REQUIRED)
message(STATUS "Using spdlog submodule at ${Spdlog_INCLUDE_DIR}")
else()
message(STATUS " No dependencies added for elsa, as it's a subproject")
endif()
# include the In stallElsaModule function
include(InstallElsaModule)
......@@ -64,10 +65,6 @@ include(InstallElsaModule)
# ------------
# reset ELSA_TESTING to only be active, if it's a standlone project
if(SUBPROJECT)
set(ELSA_TESTING OFF)
endif()
if(ELSA_TESTING)
message(STATUS "elsa testing is enabled")
......@@ -89,39 +86,41 @@ add_subdirectory(elsa)
# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)
# the examples
add_subdirectory(examples EXCLUDE_FROM_ALL)
if(ELSA_BUILD_EXAMPLES)
# the examples
add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
# ------------ setup installation ------
# ------------
# set up the target/library for make install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# setup the ElsaConfig*.cmake files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/elsaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
)
# install the config files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
DESTINATION ${INSTALL_CONFIG_DIR}
)
# this puts the local build tree into the user package repository, but not the installed version...
# ...but we rely on the paths in the installed version. sigh. commented out for now.
#export(PACKAGE elsa)
==== BASE ====
if(ELSA_INSTALL)
# set up the target/library for make install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# setup the ElsaConfig*.cmake files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/elsaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
)
# install the config files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
DESTINATION ${INSTALL_CONFIG_DIR}
)
# this puts the local build tree into the user package repository, but not the installed version...
# ...but we rely on the paths in the installed version. sigh. commented out for now.
#export(PACKAGE elsa)
endif(ELSA_INSTALL)
\ No newline at end of file
......@@ -19,6 +19,13 @@
#
# EIGEN3_ROOT
# EIGEN3_ROOT_DIR
#
# as well as in the following subdirectories:
#
# include
# thirdparty
# ThirdParty
# external
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
......@@ -80,11 +87,15 @@ else (EIGEN3_INCLUDE_DIR)
if(NOT EIGEN3_INCLUDE_DIR)
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
HINTS
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT_DIR
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT_DIR
include
thirdparty
ThirdParty
external
PATHS
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
PATH_SUFFIXES eigen3 eigen
)
endif(NOT EIGEN3_INCLUDE_DIR)
......
# Find the spdlog include directory
#
# This module supports requiring a minimum version, e.g. you can do
# find_package(Spdlog 1.2.3)
# to require version 1.2.3 or newer of spdlog.
#
# The following variables are set if spdlog is found.
# Spdlog_FOUND - True when the spdlog include directory is found.
# Spdlog_INCLUDE_DIR - The path to where the spdlog include files are.
# Spdlog_VERSION - The version of spdlog version
#
# Further the following import target will be created, if Spdlog_FOUND is true
# spdlog::spdlog_header_only - The header-only spdlog library
#
# This module reads hints about search locations from
# the following environment variables:
#
# Spdlog_ROOT
# Spdlog_ROOT_DIR
#
# as well as in the following subdirectories
#
# include
# thirdparty
# ThirdParty
# external
#
#
# function to check version of spdlog
macro(_spdlog_check_version)
file(READ "${Spdlog_INCLUDE_DIR}/include/spdlog/version.h" _spdlog_version_header)
string(REGEX MATCH "define[ \t]+SPDLOG_VER_MAJOR[ \t]+([0-9]+)" _spdlog_major_version_match "${_spdlog_version_header}")
set(SPDLOG_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+SPDLOG_VER_MINOR[ \t]+([0-9]+)" _spdlog_minor_version_match "${_spdlog_version_header}")
set(SPDLOG_MINOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+SPDLOG_VER_PATCH[ \t]+([0-9]+)" _spdlog_patch_version_match "${_spdlog_version_header}")
set(SPDLOG_PATCH_VERSION "${CMAKE_MATCH_1}")
set(Spdlog_VERSION ${SPDLOG_MAJOR_VERSION}.${SPDLOG_MINOR_VERSION}.${SPDLOG_PATCH_VERSION})
if(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
set(Spdlog_VERSION_OK FALSE)
else(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
set(Spdlog_VERSION_OK TRUE)
endif(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
if(NOT Spdlog_VERSION_OK)
message(STATUS "spdlog version ${Spdlog_VERSION} found in ${Spdlog_INCLUDE_DIR}, but at least version ${Spdlog_FIND_VERSION} is required")
endif(NOT Spdlog_VERSION_OK)
endmacro(_spdlog_check_version)
# if no version is given, we just fall back to version 1.3.0
if(NOT Spdlog_FIND_VERSION)
if(NOT SPDLOG_MAJOR_VERSION)
set(SPDLOG_MAJOR_VERSION 1)
endif(NOT SPDLOG_MAJOR_VERSION)
if(NOT SPDLOG_MINOR_VERSION)
set(SPDLOG_MINOR_VERSION 3)
endif(NOT SPDLOG_MINOR_VERSION)
if(NOT SPDLOG_PATCH_VERSION)
set(SPDLOG_PATCH_VERSION 0)
endif(NOT SPDLOG_PATCH_VERSION)
set(Spdlog_FIND_VERSION "${SPDLOG_MAJOR_VERSION}.${SPDLOG_MINOR_VERSION}.${SPDLOG_PATCH_VERSION}")
endif(NOT Spdlog_FIND_VERSION)
find_package(PkgConfig)
if(EXISTS "${Spdlog_INCLUDE_DIR}")
_spdlog_check_version()
set(Spdlog_FOUND ${Spdlog_VERSION_OK})
else(EXISTS "${Spdlog_INCLUDE_DIR}")
# search first if an Eigen3Config.cmake is available in the system,
# if successful this would set EIGEN3_INCLUDE_DIR and the rest of
# the script will work as usual
find_package(Spdlog ${Spdlog_FIND_VERSION} NO_MODULE QUIET)
if(NOT Spdlog_INCLUDE_DIR)
find_path(Spdlog_INCLUDE_DIR
NAMES include/spdlog/spdlog.h
HINTS
ENV SPDLOG_ROOT
ENV SPDLOG_ROOT_DIR
include
thirdparty
ThirdParty
external
DOC "spdlog library header files"
PATH_SUFFIXES spdlog
)
message(DEBUG " spdlog dir ${Spdlog_INCLUDE_DIR}")
endif(NOT Spdlog_INCLUDE_DIR)
message(DEBUG " spdlog dir ${Spdlog_INCLUDE_DIR}")
if(Spdlog_INCLUDE_DIR)
_spdlog_check_version()
endif(Spdlog_INCLUDE_DIR)
set(Spdlog_FOUND 0)
endif(EXISTS "${Spdlog_INCLUDE_DIR}")
if(NOT Spdlog_FOUND)
message(STATUS "spdlog could not be found")
endif(NOT Spdlog_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Spdlog DEFAULT_MSG Spdlog_INCLUDE_DIR Spdlog_VERSION_OK)
mark_as_advanced(Spdlog_INCLUDE_DIR)
if(Spdlog_FOUND AND NOT TARGET spdlog::spdlog_header_only)
add_library(spdlog::spdlog_header_only INTERFACE IMPORTED)
set_target_properties(spdlog::spdlog_header_only PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Spdlog_INCLUDE_DIR}/include")
endif(Spdlog_FOUND AND NOT TARGET spdlog::spdlog_header_only)
\ No newline at end of file
# install an elsa module
function(InstallElsaModule ELSA_MODULE_NAME ELSA_MODULE_TARGET_NAME ELSA_MODULE_EXPORT_TARGET)
#This is required so that the exported target has the name core and not elsa_core
if(NOT_SUBPROJECT)
if(ELSA_INSTALL)
#This is required so that the exported target has the name core and not elsa_core
set_target_properties(${ELSA_MODULE_TARGET_NAME} PROPERTIES EXPORT_NAME ${ELSA_MODULE_NAME})
include(GNUInstallDirs)
......@@ -24,5 +24,5 @@ function(InstallElsaModule ELSA_MODULE_NAME ELSA_MODULE_TARGET_NAME ELSA_MODULE_
NAMESPACE elsa::
DESTINATION ${INSTALL_CONFIG_DIR}
)
endif(NOT_SUBPROJECT)
endif(ELSA_INSTALL)
endfunction()
......@@ -16,9 +16,9 @@ add_subdirectory(functionals)
add_subdirectory(problems)
add_subdirectory(solvers)
add_subdirectory(projectors)
if(BUILD_ELSA_PROJECTORS_CUDA)
if(ELSA_BUILD_CUDA_PROJECTORS)
add_subdirectory(projectors_cuda)
endif(BUILD_ELSA_PROJECTORS_CUDA)
endif(ELSA_BUILD_CUDA_PROJECTORS)
add_subdirectory(generators)
......
......@@ -23,14 +23,13 @@ set(MODULE_SOURCES
add_library(${ELSA_MODULE_TARGET_NAME} ${MODULE_HEADERS} ${MODULE_SOURCES})
add_library(elsa::${ELSA_MODULE_NAME} ALIAS ${ELSA_MODULE_TARGET_NAME})
target_link_libraries(${ELSA_MODULE_TARGET_NAME} PUBLIC spdlog::spdlog)
target_include_directories(${ELSA_MODULE_TARGET_NAME}
PUBLIC
$<INSTALL_INTERFACE:include/${ELSA_MODULE_NAME}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
target_link_libraries(${ELSA_MODULE_TARGET_NAME} PUBLIC spdlog::spdlog_header_only)
# require C++17
target_compile_features(${ELSA_MODULE_TARGET_NAME} PUBLIC cxx_std_17)
......@@ -46,4 +45,4 @@ endif(ELSA_TESTING)
registerComponent(${ELSA_MODULE_NAME})
# install the module
InstallElsaModule(${ELSA_MODULE_NAME} ${ELSA_MODULE_TARGET_NAME} ${ELSA_MODULE_EXPORT_TARGET})
\ No newline at end of file
InstallElsaModule(${ELSA_MODULE_NAME} ${ELSA_MODULE_TARGET_NAME} ${ELSA_MODULE_EXPORT_TARGET})
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