CMakeLists.txt 5.02 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)
David Frank's avatar
David Frank committed
22

23
24
25
26
27
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)
28
option(ELSA_BUILD_WITH_MORE_WARNINGS "Enable all and extra warnings when building (-Wall -Wextra)" ON)
29
30
31

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
32

33
34
35
36
37
38
39

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

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

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

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

47

48
49
50
# ------------ dependencies ------------
# ------------

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

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

61
62
    # setup spdlog Library
    set(Spdlog_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/spdlog")
David Frank's avatar
David Frank committed
63
64
    find_package(Spdlog REQUIRED)
    message(STATUS "Using spdlog submodule at ${Spdlog_INCLUDE_DIR}")
65
else()
66
    message(STATUS "    No dependencies added for elsa, as it is not stand-alone")
67
68
endif()

69
# include the InstallElsaModule function
70
71
include(InstallElsaModule)

72

73
74
75
# ------------ setup testing -----------
# ------------

76
# if elsa is used as a submodule, turn testing off
David Frank's avatar
   
David Frank committed
77
78
79
80
if(NOT ELSA_MASTER_PROJECT)
    set(ELSA_TESTING OFF)
endif(NOT ELSA_MASTER_PROJECT)

81
82
83
84
85
if(ELSA_TESTING)
    message(STATUS "elsa testing is enabled")

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

87
88
89
90
91
	add_custom_target(tests
        COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Build and run all the tests.")

92
93
94
    # add the CMake modules for automatic test discovery
    set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/Catch2/contrib" ${CMAKE_MODULE_PATH})

95
96
    if(ELSA_COVERAGE)
        message(STATUS "elsa test coverage is enabled")
97

98
99
100
101
        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)
David Frank's avatar
David Frank committed
102

103
104
105
    else(ELSA_COVERAGE)
        message(STATUS "elsa test coverage is disabled")
    endif(ELSA_COVERAGE)
David Frank's avatar
David Frank committed
106

107
108
109
else(ELSA_TESTING)
    message(STATUS "    elsa testing is disabled")
endif(ELSA_TESTING)
David Frank's avatar
David Frank committed
110
111


112
113
114
115
116
117
118
119
120
# ------------ add code/docs -----------
# ------------

# the elsa library
add_subdirectory(elsa)

# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)

David Frank's avatar
David Frank committed
121
122
123
124
if(ELSA_BUILD_EXAMPLES)
    # the examples
    add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
125

126

127
128
129
# ------------ setup installation ------
# ------------

David Frank's avatar
David Frank committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
158
endif(ELSA_INSTALL)