CMakeLists.txt 4.77 KB
Newer Older
1
cmake_minimum_required( VERSION 3.12.4 )
2
project( RTSN VERSION 0.1.0 LANGUAGES CXX )
3
set( CMAKE_CXX_STANDARD 17 )
4
set( CMAKE_CXX_STANDARD_REQUIRED ON )
5

6
7
8
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wno-dev" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native -pg -no-pie" )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -Werror" )
9

10
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin" )
11

12
file( GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" "include/*.h" )
13
include_directories( ${CMAKE_SOURCE_DIR}/include )
14
add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} )
15

16
17
18
19
20
21
22
23
24
25
26
27
find_package( OpenMP REQUIRED )
if( OPENMP_FOUND )
    set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
endif()

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

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

28
29
30
31
32
33
34
35
36
37
find_package( BLAS )
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
38
add_compile_definitions( BLAZE_USE_SHARED_MEMORY_PARALLELIZATION=0 )
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
set(flag 1)
if (WIN32)
    execute_process(COMMAND wmic cpu get L3CacheSize
        OUTPUT_VARIABLE tmp
        RESULT_VARIABLE flag
        ERROR_QUIET)
    if (flag)
        execute_process(COMMAND wmic cpu get L2CacheSize
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)
    if (flag)
        execute_process(COMMAND wmic cpu get L1CacheSize
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)
endif (WIN32)

if (UNIX)
    execute_process(COMMAND cat /sys/devices/system/cpu/cpu0/cache/index3/size
        OUTPUT_VARIABLE tmp
        RESULT_VARIABLE flag
        ERROR_QUIET)
    if (flag)
        execute_process(COMMAND cat /sys/devices/system/cpu/cpu0/cache/index2/size
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)
    if (flag)
        execute_process(COMMAND cat /sys/devices/system/cpu/cpu0/cache/index1/size
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)
endif (UNIX)

if (APPLE)
    execute_process(COMMAND sysctl -n hw.l3cachesize
        OUTPUT_VARIABLE tmp
        RESULT_VARIABLE flag
        ERROR_QUIET)
    if (flag)
        execute_process(COMMAND sysctl -n hw.l2cachesize
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)
    if (flag)
        execute_process(COMMAND sysctl -n hw.l1icachesize
            OUTPUT_VARIABLE tmp
            RESULT_VARIABLE flag
            ERROR_QUIET)
    endif (flag)

    if (flag EQUAL 0)
        math(EXPR tmp ${tmp}/1024)  # If successful convert to kibibytes to comply with rest
    endif (flag EQUAL 0)
endif (APPLE)

if (flag)
    message(WARNING "Cache size not found automatically. Using default value as cache size.")
    set(tmp "3072")
endif (flag)

string( REGEX MATCH "([0-9][0-9]+)" tmp ${tmp} )
math( EXPR BLAZE_CACHE_SIZE ${tmp}*1024 )
Jannick Wolters's avatar
Jannick Wolters committed
109
add_compile_definitions( BLAZE_CACHE_SIZE=${BLAZE_CACHE_SIZE}UL )
110
message( STATUS "Blaze: Automatic Cache Size Configuration = ${BLAZE_CACHE_SIZE} KiB" )
111
112
include_directories( ${CMAKE_SOURCE_DIR}/ext/blaze )

Jannick Wolters's avatar
Jannick Wolters committed
113
add_compile_definitions( METIS_EXPORT= )
114
set( DISABLE_PARMETIS_PROGRAMS ON )
115
116
117
118
set( ParMETIS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ext/parmetis )
include_directories( ${ParMETIS_PATH}/include )
include_directories( ${ParMETIS_PATH}/metis/include )
add_subdirectory( ${ParMETIS_PATH} )
Jannick Wolters's avatar
Jannick Wolters committed
119

120
121
122
123
find_package( VTK REQUIRED COMPONENTS vtkIOGeometry vtkFiltersCore )

include_directories( ${CMAKE_SOURCE_DIR}/ext/cpptoml/include )
include_directories( ${CMAKE_SOURCE_DIR}/ext/spdlog/include )
124

125
126
127
128
129
130
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
131
add_compile_definitions( GIT_HASH="${GIT_HASH}" )
132

133
set( CORE_LIBRARIES ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MPI_LIBRARIES} ${VTK_LIBRARIES} parmetis -lstdc++fs )
134

135
136
137
target_link_libraries( ${CMAKE_PROJECT_NAME} ${CORE_LIBRARIES} )

if( BUILD_TESTING )
138
    add_compile_definitions( BUILD_TESTING=1 )
139
140
141
142
143
144
145
    add_subdirectory( ${CMAKE_SOURCE_DIR}/ext/Catch2 )
    include_directories( ${CMAKE_SOURCE_DIR}/ext/Catch2/single_include/catch2 )
    file( GLOB_RECURSE TEST_SRCS RELATIVE ${CMAKE_SOURCE_DIR} "tests/*.cpp" )
    list( REMOVE_ITEM SRCS "src/main.cpp" )
    add_executable( unit_tests ${SRCS} ${TEST_SRCS} )
    target_link_libraries( unit_tests ${CORE_LIBRARIES} )
endif()