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

CMakeLists.txt 3.19 KB
Newer Older
Tobias Lasser's avatar
Tobias Lasser committed
1 2
cmake_minimum_required(VERSION 3.9)

3 4
# setup macro for component registration, so you can use find_package(elsa COMPONENT name)
# also sets all target names
Tobias Lasser's avatar
Tobias Lasser committed
5 6
macro(registerComponent name)
    set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};${name}" PARENT_SCOPE)
7
    set(ELSA_REGISTERED_TARGETS "${ELSA_REGISTERED_TARGETS};elsa_${name}" PARENT_SCOPE)
Tobias Lasser's avatar
Tobias Lasser committed
8 9
endmacro()

10

David Frank's avatar
David Frank committed
11
# macro for the unit tests
12
macro(ELSA_TEST NAME)
David Frank's avatar
David Frank committed
13
    # create the test executable
14
    add_executable(test_${NAME} EXCLUDE_FROM_ALL test_${NAME}.cpp test_main.cpp)
David Frank's avatar
David Frank committed
15
    # add catch and the corresponding elsa library
16
    target_link_libraries(test_${NAME} PRIVATE Catch2::Catch2 ${ELSA_MODULE_TARGET_NAME} elsa::test_routines)
David Frank's avatar
David Frank committed
17 18
    # enable C++17
    target_compile_features(test_${NAME} PUBLIC cxx_std_17)
Jens Petit's avatar
Jens Petit committed
19 20
    # include helpers
    target_include_directories(test_${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/elsa/test_routines/)
David Frank's avatar
David Frank committed
21 22 23 24 25 26

    # if we use JUnit reporter handle arguments
    if(${ELSA_CREATE_JUNIT_REPORTS})
        file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_reports)
        set(ELSA_JUNIT_ARGUMENTS "-r junit" "-o ${PROJECT_BINARY_DIR}/test_reports/test_${NAME}.xml")
    endif(${ELSA_CREATE_JUNIT_REPORTS})
27
    add_dependencies(tests test_${NAME})
David Frank's avatar
David Frank committed
28 29 30

    # let Catch discover and register all the test cases
    catch_discover_tests(test_${NAME} TEST_SPEC ${ELSA_JUNIT_ARGUMENTS})
31
endmacro(ELSA_TEST)
David Frank's avatar
David Frank committed
32

33

David Frank's avatar
David Frank committed
34 35 36 37 38
# add sanitizers if in debug mode
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
    include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake)
endif()

39

Tobias Lasser's avatar
Tobias Lasser committed
40 41 42 43 44
# add the elsa modules
add_subdirectory(core)
add_subdirectory(logging)
add_subdirectory(io)
add_subdirectory(operators)
Tobias Lasser's avatar
Tobias Lasser committed
45 46 47
add_subdirectory(functionals)
add_subdirectory(problems)
add_subdirectory(solvers)
48
add_subdirectory(projectors)
David Frank's avatar
David Frank committed
49
if(ELSA_BUILD_CUDA_PROJECTORS)
Nikola Dinev's avatar
Nikola Dinev committed
50
    add_subdirectory(projectors_cuda)
David Frank's avatar
David Frank committed
51
endif(ELSA_BUILD_CUDA_PROJECTORS)
52
add_subdirectory(generators)
53
add_subdirectory(test_routines)
Tobias Lasser's avatar
Tobias Lasser committed
54 55


56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
# library to build and add all registered components of the library
add_library(elsa_all INTERFACE)
add_library(elsa::all ALIAS elsa_all)

# link against all modules
target_link_libraries(elsa_all INTERFACE ${ELSA_REGISTERED_TARGETS})
target_include_directories(elsa_all INTERFACE
        $<INSTALL_INTERFACE:include/elsa/>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        )

# register the all "module"
registerComponent(all)

# install the all module and the elsa.h file
InstallElsaModule(all elsa_all elsa_allTargets)
install(FILES elsa.h
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/elsa/)


76 77
# if stand-alone and option set, turn on all warnings for all components
if(${ELSA_MASTER_PROJECT} AND ${ELSA_BUILD_WITH_MORE_WARNINGS})
78
    list(REMOVE_ITEM ELSA_REGISTERED_COMPONENTS "")
79
    foreach(_component ${ELSA_REGISTERED_COMPONENTS})
80 81 82 83 84 85 86
        if (NOT(_component MATCHES "projector_kernels"))
            if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
                target_compile_options(elsa_${_component} PUBLIC -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
            endif()
            if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
                target_compile_options(elsa_${_component} PUBLIC /W3 /WX)
            endif()
87 88 89
        endif()
    endforeach(_component ELSA_REGISTERED_COMPONENTS)
endif()