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

CMakeLists.txt 7.39 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)
Nikola Dinev's avatar
Nikola Dinev committed
29
option(ELSA_BUILD_PYTHON_BINDINGS "Attempt to build python bindings if enabled (required libclang-dev)" ON)
30
option(ELSA_BUILD_WITH_MORE_WARNINGS "Enable all and extra warnings when building (-Wall -Wextra)" ON)
31

32
option(ELSA_CUDA_VECTOR "Build elsa with GPU DataContainer support and default" OFF)
33

David Frank's avatar
David Frank committed
34 35 36 37 38 39
set(ELSA_SANITIZER
        "" CACHE STRING
        "Compile with a sanitizer. Options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'"
        )


40 41 42 43 44 45
# ------------ general setup -----------
# ------------

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

46
# set default built type to "Release" (if no other specified)
47 48 49
set(DEFAULT_BUILD_TYPE "Release")
include(SetDefaultBuildType)

50

51 52 53
# ------------ dependencies ------------
# ------------

54
# only add the dependencies if elsa is stand-alone
David Frank's avatar
David Frank committed
55
if(ELSA_MASTER_PROJECT)
56 57 58
    # include the git submodule update
    include(UpdateGitSubmodules)

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

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

    # setup Dnnl library
    find_package(Dnnl)
71 72 73 74 75 76

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

81 82 83 84 85 86 87

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


88
# include the InstallElsaModule function
89 90
include(InstallElsaModule)

Nikola Dinev's avatar
Nikola Dinev committed
91
add_subdirectory(thirdparty/pybind11)
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
# ------------ 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()

118
# ------------ Setup Tools -----------
David Frank's avatar
David Frank committed
119 120 121 122 123 124
# ------------

# Includes clang-format, clang-tidy, cmake-format, and sanitizers
include(Tools)


125 126 127
# ------------ setup testing -----------
# ------------

128
# if elsa is used as a submodule, turn testing off
David Frank's avatar
 
David Frank committed
129 130 131 132
if(NOT ELSA_MASTER_PROJECT)
    set(ELSA_TESTING OFF)
endif(NOT ELSA_MASTER_PROJECT)

133
if(ELSA_TESTING OR ELSA_BENCHMARKS)
134 135 136

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

138 139 140
    # add the CMake modules for automatic test discovery
    set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/Catch2/contrib" ${CMAKE_MODULE_PATH})

141 142 143 144 145 146
    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}
147
            USES_TERMINAL
148 149 150 151 152 153 154 155
            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)
156

157 158 159 160
        else(ELSA_COVERAGE)
            message(STATUS "elsa test coverage is disabled")
        endif(ELSA_COVERAGE)
    endif(ELSA_TESTING)
David Frank's avatar
David Frank committed
161

162 163 164 165
    if (ELSA_BENCHMARKS)
        message(STATUS "elsa benchmarks are enabled")
        add_subdirectory(benchmarks)
    endif(ELSA_BENCHMARKS)
David Frank's avatar
David Frank committed
166

167
else(ELSA_TESTING OR ELSA_BENCHMARKS)
168
    message(STATUS "    elsa testing is disabled")
169
endif(ELSA_TESTING OR ELSA_BENCHMARKS)
David Frank's avatar
David Frank committed
170 171


David Frank's avatar
David Frank committed
172

173 174 175
# ------------ add code/docs -----------
# ------------

Nikola Dinev's avatar
Nikola Dinev committed
176 177 178 179 180
# the bindings generator should be added before elsa, as we check whether the target can be built
if (ELSA_BUILD_PYTHON_BINDINGS)
    add_subdirectory(tools/bindings_generation EXCLUDE_FROM_ALL)
endif()

181 182 183 184 185 186
# the elsa library
add_subdirectory(elsa)

# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)

David Frank's avatar
David Frank committed
187 188 189 190
if(ELSA_BUILD_EXAMPLES)
    # the examples
    add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
191

192

193 194 195
# ------------ setup installation ------
# ------------

David Frank's avatar
David Frank committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
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
224
endif(ELSA_INSTALL)
225 226 227 228 229 230 231 232 233 234


##
# 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"
235
    )