24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

CMakeLists.txt 6.89 KB
Newer Older
1 2 3 4 5 6 7 8 9
cmake_minimum_required(VERSION 3.9)

project(elsa VERSION 0.5
        DESCRIPTION "elsa recon toolbox"
        LANGUAGES CXX)


# ------------ elsa options ------------
# ------------
10 11 12
# detect if elsa is being as a submodule, enable/disable some options based on this
if(NOT DEFINED ELSA_MASTER_PROJECT)
    if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
David Frank's avatar
David Frank committed
13 14 15 16 17
        set(ELSA_MASTER_PROJECT ON)
    else()
        set(ELSA_MASTER_PROJECT OFF)
    endif()
endif ()
18

19 20 21
option(ELSA_TESTING "Enable building the unit tests" ${ELSA_MASTER_PROJECT})
option(ELSA_CREATE_JUNIT_REPORTS "Enable creating JUnit style reports when running tests" ON)
option(ELSA_COVERAGE "Enable test coverage computation and reporting" OFF)
Jens Petit's avatar
Jens Petit committed
22
option(ELSA_BENCHMARKS "Enable elsa benchmark test cases" OFF)
David Frank's avatar
David Frank committed
23

24 25 26 27 28
option(GIT_SUBMODULE "Enable updating the submodules during build" ${ELSA_MASTER_PROJECT})
option(ELSA_INSTALL "Enable generating the install targets for make install" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_EXAMPLES "Enable building of examples" ${ELSA_MASTER_PROJECT})

option(ELSA_BUILD_CUDA_PROJECTORS "Enable building (or attempting to) the CUDA projectors" ON)
29
option(ELSA_BUILD_WITH_MORE_WARNINGS "Enable all and extra warnings when building (-Wall -Wextra)" ON)
30 31 32

option(ELSA_SANITIZE_THREAD "Build elsa with thread sanitizers (TSAN)" OFF)
option(ELSA_SANITIZE_ADDRESS "Build elsa with address and undefined-behavior sanitizers (ASAN and UBSAN)" OFF)
David Frank's avatar
David Frank committed
33

34
option(ELSA_CUDA_VECTOR "Build elsa with GPU DataContainer support and default" OFF)
35 36 37 38 39 40 41

# ------------ general setup -----------
# ------------

# add our cmake modules under cmake/
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

42
# set default built type to "Release" (if no other specified)
43 44 45
set(DEFAULT_BUILD_TYPE "Release")
include(SetDefaultBuildType)

46

47 48 49
# ------------ dependencies ------------
# ------------

50
# only add the dependencies if elsa is stand-alone
David Frank's avatar
David Frank committed
51
if(ELSA_MASTER_PROJECT)
52 53 54
    # include the git submodule update
    include(UpdateGitSubmodules)

55 56
    # setup Eigen Library
    set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/eigen3")
David Frank's avatar
David Frank committed
57 58 59
    find_package(Eigen3 3.3 REQUIRED)
    message(STATUS "Using eigen3 submodule at ${EIGEN3_INCLUDE_DIR}")

60 61
    # setup spdlog Library
    set(Spdlog_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/spdlog")
David Frank's avatar
David Frank committed
62 63
    find_package(Spdlog REQUIRED)
    message(STATUS "Using spdlog submodule at ${Spdlog_INCLUDE_DIR}")
64 65 66

    # setup Dnnl library
    find_package(Dnnl)
67 68 69 70 71 72

    if(ELSA_CUDA_VECTOR)
        find_package(CUDA REQUIRED)
        find_package(Quickvec REQUIRED)
        message(STATUS "Using Quickvec submodule at ${Quickvec_INCLUDE_DIR}")
    endif()
73
else()
74
    message(STATUS "    No dependencies added for elsa, as it is not stand-alone")
75 76
endif()

77 78 79 80 81 82 83

# set where to install the exports/targets
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/elsa)


84
# include the InstallElsaModule function
85 86
include(InstallElsaModule)

87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
# ------------ setup VectorCUDA --------
# ------------
if(ELSA_CUDA_VECTOR)
    set(CMAKE_CXX_EXTENSIONS OFF)

    include(CheckLanguage)
    check_language(CUDA)

    if (CMAKE_CUDA_COMPILER AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        enable_language(CUDA)

        message(STATUS "CUDA support enabled")
        message(STATUS "Enabling DataHandlerGPU")
        message(STATUS "The default container type will be on the GPU")

        add_definitions(-DELSA_CUDA_VECTOR)
        add_subdirectory(thirdparty/quickvec)
    else()
        message(STATUS "CUDA compiler not found or not compiling with clang!")
        message(STATUS "Compiling without a DataHandlerGPU")
        message(STATUS "The default container type will be CPU")
        set(ELSA_CUDA_VECTOR OFF)
    endif()
endif()


114 115 116
# ------------ setup testing -----------
# ------------

117
# if elsa is used as a submodule, turn testing off
David Frank's avatar
 
David Frank committed
118 119 120 121
if(NOT ELSA_MASTER_PROJECT)
    set(ELSA_TESTING OFF)
endif(NOT ELSA_MASTER_PROJECT)

122
if(ELSA_TESTING OR ELSA_BENCHMARKS)
123 124 125

    enable_testing()
    add_subdirectory(thirdparty/Catch2)
David Frank's avatar
David Frank committed
126

127 128 129
    # add the CMake modules for automatic test discovery
    set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/Catch2/contrib" ${CMAKE_MODULE_PATH})

130 131 132 133 134 135 136 137 138 139 140 141 142 143
    if(ELSA_TESTING)
        message(STATUS "elsa testing is enabled")

        add_custom_target(tests
            COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
            COMMENT "Build and run all the tests.")
        if(ELSA_COVERAGE)
            message(STATUS "elsa test coverage is enabled")

            include(CodeCoverage)
            APPEND_COVERAGE_COMPILER_FLAGS()
            set(COVERAGE_LCOV_EXCLUDES '${PROJECT_SOURCE_DIR}/thirdparty/*' '/usr/*')
            SETUP_TARGET_FOR_COVERAGE_LCOV(NAME test_coverage EXECUTABLE ctest)
144

145 146 147 148
        else(ELSA_COVERAGE)
            message(STATUS "elsa test coverage is disabled")
        endif(ELSA_COVERAGE)
    endif(ELSA_TESTING)
David Frank's avatar
David Frank committed
149

150 151 152 153
    if (ELSA_BENCHMARKS)
        message(STATUS "elsa benchmarks are enabled")
        add_subdirectory(benchmarks)
    endif(ELSA_BENCHMARKS)
David Frank's avatar
David Frank committed
154

155
else(ELSA_TESTING OR ELSA_BENCHMARKS)
156
    message(STATUS "    elsa testing is disabled")
157
endif(ELSA_TESTING OR ELSA_BENCHMARKS)
David Frank's avatar
David Frank committed
158 159


160 161 162 163 164 165 166 167 168
# ------------ add code/docs -----------
# ------------

# the elsa library
add_subdirectory(elsa)

# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)

David Frank's avatar
David Frank committed
169 170 171 172
if(ELSA_BUILD_EXAMPLES)
    # the examples
    add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
173

174

175 176 177
# ------------ setup installation ------
# ------------

David Frank's avatar
David Frank committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
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)
David Frank's avatar
 
David Frank committed
206
endif(ELSA_INSTALL)
207 208 209 210 211 212 213 214 215 216


##
# Add uninstall target
# Remove all headers, library and CMake files, which where copied to the install location

add_custom_target(uninstall
    COMMAND ${CMAKE_COMMAND} -P "${PROJECT_SOURCE_DIR}/cmake/Uninstall.cmake"
    COMMENT "Uninstalling elsa (Removing all installed files)"
    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt"
217
    )