CMakeLists.txt 8.85 KB
Newer Older
1
cmake_minimum_required( VERSION 3.16 )
2
project( KiT-RT VERSION 0.1.0 LANGUAGES CXX )
3

4
### OPTIONS #####################################
5
option( BUILD_TESTING "builds all available unit tests" OFF )
6
option( BUILD_GUI "additionally builds a user interface" OFF )
jannick.wolters's avatar
jannick.wolters committed
7
option( BUILD_DOC "builds Doxygen and Sphinx documentation" OFF )
8
9
option( BUILD_UNITY "enables unity build for faster compile times" ON )
option( BUILD_CODE_COV "enables compiler option required for code coverage analysis" OFF )
10
#################################################
11
12


13
14
15
16
17
18
### COMPILER ####################################
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( KITRT_RELEASE_OPTIONS -march=native -w )
set( KITRT_RELWITHDEBINFO_OPTIONS -march=native -pg -no-pie )
set( KITRT_DEBUG_OPTIONS -Wall -Wextra -Wpedantic )
19
20
if( BUILD_UNITY AND NOT BUILD_CODE_COV )
    message( STATUS "Unity build enabled" )
21
    set( CMAKE_UNITY_BUILD ON )
22
    set( CMAKE_UNITY_BUILD_BATCH_SIZE 0 )
23
endif()
24
#################################################
25

26

27
### LIBRARIES ###################################
28
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
jannick.wolters's avatar
jannick.wolters committed
29

30
31
32
33
34
35
36
37
find_package( OpenMP REQUIRED )

find_package( MPI REQUIRED )
include_directories( ${MPI_INCLUDE_PATH} )

find_package( LAPACK REQUIRED )
include_directories( ${LAPACK_INCLUDE_DIR} )

38
find_package( BLAS )
39

40
find_package( VTK COMPONENTS vtkIOGeometry vtkFiltersCore REQUIRED )
41
42
43
44
45
46
47

find_package( Python3 COMPONENTS Interpreter Development NumPy REQUIRED )
include_directories( ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS} )
add_compile_definitions( KITRT_PYTHON_PATH="${CMAKE_SOURCE_DIR}/python" )

add_compile_definitions( BLAZE_USE_SHARED_MEMORY_PARALLELIZATION=0 )
message( STATUS "Blaze: Shared memory parallelization disabled" )
48
49
50
51
52
53
54
55
if( BLAS_FOUND )
    message( STATUS "Blaze: BLAS mode enabled" )
    add_compile_definitions( BLAZE_BLAS_MODE=1 )
    include_directories( ${BLAS_INCLUDE_DIR} )
else()
    message( STATUS "Blaze: BLAS mode disabled" )
    add_compile_definitions( BLAZE_BLAS_MODE=0 )
endif()
jannick.wolters's avatar
jannick.wolters committed
56
include( blaze-cache-config )
57
58
include_directories( ${CMAKE_SOURCE_DIR}/ext/blaze )

59
60
include_directories( ${CMAKE_SOURCE_DIR}/ext/cpptoml/include )
include_directories( ${CMAKE_SOURCE_DIR}/ext/spdlog/include )
61

jannick.wolters's avatar
jannick.wolters committed
62
set( CORE_LIBRARIES ${Python3_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MPI_LIBRARIES} ${VTK_LIBRARIES} OpenMP::OpenMP_CXX -lstdc++fs )
63
64
65
66
#################################################


### MISC ########################################
67
68
69
70
71
72
execute_process(
    COMMAND git rev-parse HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE GIT_HASH
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
Jannick Wolters's avatar
Jannick Wolters committed
73
add_compile_definitions( GIT_HASH="${GIT_HASH}" )
74
#################################################
75

76

77
78
### BUILD KIT-RT ################################
file( GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" "include/*.h" )
Steffen Schotthöfer's avatar
Steffen Schotthöfer committed
79
80
81
82
83
84
85
set( EXCLUDE_DIR "/gui/" )
foreach( TMP_PATH ${SRCS} )
    string( FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND )
    if( NOT ${EXCLUDE_DIR_FOUND} EQUAL -1 )
        list( REMOVE_ITEM SRCS ${TMP_PATH} )
    endif()
endforeach( TMP_PATH )
86
87
include_directories( ${CMAKE_SOURCE_DIR}/include )
add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} ${EXT_SRCS} )
88
target_link_libraries( ${CMAKE_PROJECT_NAME} ${CORE_LIBRARIES} )
89
90
91
92
93
94
95
96
set_target_properties( ${CMAKE_PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin" )
target_compile_options( ${CMAKE_PROJECT_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${KITRT_DEBUG_OPTIONS}>" )
target_compile_options( ${CMAKE_PROJECT_NAME} PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:${KITRT_RELWITHDEBINFO_OPTIONS}>" )
target_compile_options( ${CMAKE_PROJECT_NAME} PUBLIC "$<$<CONFIG:RELEASE>:${KITRT_RELEASE_OPTIONS}>" )
#################################################


### BUILD UNIT TESTS ############################
97
if( BUILD_TESTING )
98
99
100
101
    include( CTest )
    set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/ext/Catch2/contrib ${CMAKE_MODULE_PATH} )
    include( Catch )
    set( CATCH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/ext/Catch2/single_include/catch2 )
102
103
    add_compile_definitions( BUILD_TESTING )
    add_compile_definitions( TESTS_PATH="${CMAKE_SOURCE_DIR}/tests/" )
104
105
106
107
108
109
110
111
112
    add_library( Catch INTERFACE )
    target_include_directories( Catch INTERFACE ${CATCH_INCLUDE_DIR} )
    file( GLOB_RECURSE TEST_SRCS RELATIVE ${CMAKE_SOURCE_DIR} "tests/*.cpp" )
    list( REMOVE_ITEM SRCS "src/main.cpp" )
    add_executable( unit_tests ${TEST_SRCS} ${SRCS} ${EXT_SRCS} )
    target_compile_definitions( unit_tests PUBLIC BUILD_TESTING )
    target_compile_definitions( unit_tests PUBLIC TESTS_PATH="${CMAKE_SOURCE_DIR}/tests/" )
    target_link_libraries( unit_tests Catch ${CORE_LIBRARIES} )
    target_compile_options( unit_tests PUBLIC "$<$<CONFIG:DEBUG>:${KITRT_DEBUG_OPTIONS}>" )
113
114
115
116
117
118
119
120
    if( BUILD_CODE_COV )
        if( CMAKE_COMPILER_IS_GNUCXX )
            set( CODE_COVERAGE_OPTIONS --coverage -g -O0 -w )
            target_compile_options( unit_tests PUBLIC "$<$<CONFIG:DEBUG>:${CODE_COVERAGE_OPTIONS}>" )
            target_link_libraries( unit_tests Catch gcov )
        else()
            message( FATAL_ERROR "Code coverage is currently only supported for gcc!" )
        endif()
121
122
    else()
        target_link_libraries( unit_tests Catch )
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    endif()
    target_compile_options( unit_tests PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:${KITRT_RELWITHDEBINFO_OPTIONS}>" )
    target_compile_options( unit_tests PUBLIC "$<$<CONFIG:RELEASE>:${KITRT_RELEASE_OPTIONS}>" )
    catch_discover_tests( unit_tests )
endif()
#################################################


### BUILD GUI ###################################
if( BUILD_GUI )
    find_package( Qt5 COMPONENTS Core Widgets Gui OpenGL REQUIRED )
    find_package( VTK COMPONENTS vtkGUISupportQt vtkInteractionStyle vtkInteractionWidgets vtkRenderingAnnotation vtkRenderingCore vtkRenderingFreeType vtkRenderingOpenGL2 REQUIRED )
    include_directories( ${CMAKE_SOURCE_DIR}/include/gui )
    file( GLOB_RECURSE GUI_SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/gui/*" )
    file( GLOB_RECURSE GUI_INCL RELATIVE ${CMAKE_SOURCE_DIR} "include/gui/*" )
    add_executable( ${CMAKE_PROJECT_NAME}_gui ${SRCS} ${EXT_SRCS} ${GUI_SRCS} ${GUI_INCL})
    target_compile_definitions( ${CMAKE_PROJECT_NAME}_gui PUBLIC BUILD_GUI )
    set_target_properties( ${CMAKE_PROJECT_NAME}_gui PROPERTIES AUTOMOC ON )
    set_target_properties( ${CMAKE_PROJECT_NAME}_gui PROPERTIES AUTOUIC ON )
    set_target_properties( ${CMAKE_PROJECT_NAME}_gui PROPERTIES AUTORCC ON )
    set( GUI_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL ${VTK_LIBRARIES} )
    target_link_libraries( ${CMAKE_PROJECT_NAME}_gui ${CORE_LIBRARIES} ${GUI_LIBRARIES} )
    set_target_properties( ${CMAKE_PROJECT_NAME}_gui PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin" )
    target_compile_options( ${CMAKE_PROJECT_NAME}_gui PUBLIC "$<$<CONFIG:DEBUG>:${KITRT_DEBUG_OPTIONS}>" )
    target_compile_options( ${CMAKE_PROJECT_NAME}_gui PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:${KITRT_RELWITHDEBINFO_OPTIONS}>" )
    target_compile_options( ${CMAKE_PROJECT_NAME}_gui PUBLIC "$<$<CONFIG:RELEASE>:${KITRT_RELEASE_OPTIONS}>" )
jannick.wolters's avatar
jannick.wolters committed
149
endif()
150
#################################################
jannick.wolters's avatar
jannick.wolters committed
151
152


153
### BUILD DOCUMENTATION #########################
jannick.wolters's avatar
jannick.wolters committed
154
if( BUILD_DOC )
155
156
157
158
159
160
161
    find_package( Doxygen REQUIRED )
    find_package( Sphinx REQUIRED )

    file( GLOB_RECURSE DOC_HEADER RELATIVE ${CMAKE_SOURCE_DIR} "include/*.h" )

    set( DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR} )
    set( DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen )
162
    set( DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml )
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    set( DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/../doc/Doxyfile.in )
    set( DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile )
    configure_file( ${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY )
    file( MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR} )
    add_custom_command( OUTPUT ${DOXYGEN_INDEX_FILE}
                        DEPENDS ${DOC_HEADER}
                        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
                        MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
                        COMMENT "Generating documentaion with Doxygen"
                        VERBATIM )
    add_custom_target( Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE} )

    set( SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../doc )
    set( SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/docs/sphinx )
    set( SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html )
    add_custom_command( OUTPUT ${SPHINX_INDEX_FILE}
jannick.wolters's avatar
jannick.wolters committed
179
                        COMMAND ${SPHINX_EXECUTABLE} ${SPHINX_SOURCE} ${SPHINX_BUILD}
180
181
182
183
184
185
                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
                        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../doc/index.rst ${DOXYGEN_INDEX_FILE}
                        MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py
                        COMMENT "Converting documentation from Doxygen to Sphinx" )

    add_custom_target( Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE} )
jannick.wolters's avatar
jannick.wolters committed
186
endif()
187
#################################################