CMakeLists.txt 7.04 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
option(ELSA_CUDA_VECTOR "Build elsa with GPU DataContainer support and default" OFF)
32

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


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

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

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

49

50
51
52
# ------------ dependencies ------------
# ------------

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

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

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

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

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

80
81
82
83
84
85
86

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


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

90

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

116
# ------------ Setup Tools -----------
David Frank's avatar
David Frank committed
117
118
119
120
121
122
# ------------

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


123
124
125
# ------------ setup testing -----------
# ------------

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

131
if(ELSA_TESTING OR ELSA_BENCHMARKS)
132
133
134

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

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

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

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

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

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


David Frank's avatar
David Frank committed
170

171
172
173
174
175
176
177
178
179
# ------------ add code/docs -----------
# ------------

# the elsa library
add_subdirectory(elsa)

# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)

David Frank's avatar
David Frank committed
180
181
182
183
if(ELSA_BUILD_EXAMPLES)
    # the examples
    add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
184

185

186
187
188
# ------------ setup installation ------
# ------------

David Frank's avatar
David Frank committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
217
endif(ELSA_INSTALL)
218
219
220
221
222
223
224
225
226
227


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