-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
238 lines (217 loc) · 8.13 KB
/
CMakeLists.txt
File metadata and controls
238 lines (217 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
cmake_minimum_required(VERSION 3.21)
project(ezp C CXX Fortran)
if (NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
message(FATAL_ERROR "Only Linux is supported.")
endif ()
include_directories(${PROJECT_SOURCE_DIR})
if (EXISTS ${PROJECT_SOURCE_DIR}/include)
include_directories(include)
endif ()
include_directories(mpl)
add_compile_definitions(MPICH_SKIP_MPICXX)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror -Wno-empty-body -Wno-format")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_compile_options(-Rno-debug-disables-optimization)
add_link_options(-Rno-debug-disables-optimization)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-Wall)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-fprofile-arcs -ftest-coverage)
# add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fconcepts-diagnostics-depth=4>)
link_libraries(gcov)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
link_libraries(clang_rt.profile)
endif ()
option(EZP_ASAN "Enable address sanitizer (-fsanitize=address,leak,undefined -fno-omit-frame-pointer)." OFF)
if (EZP_ASAN)
add_compile_options(-fsanitize=address,leak,undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address,leak,undefined -fno-omit-frame-pointer)
endif ()
endif ()
set(CMAKE_CXX_STANDARD 20)
option(EZP_ADD_UNDERSCORE "Use lowercase with appended underscore subroutine names." ON)
if (EZP_ADD_UNDERSCORE)
add_compile_definitions(EZP_UNDERSCORE)
endif ()
option(EZP_ENABLE_OPENMP "Use OpenMP whenever possible." ON)
if (EZP_ENABLE_OPENMP)
option(EZP_ENABLE_OPENMP_MUMPS "Use OpenMP for MUMPS." ON)
option(EZP_ENABLE_OPENMP_LIS "Use OpenMP for LIS." ON)
option(EZP_ENABLE_OPENMP_GK "Use OpenMP for GKlib." ON)
endif ()
find_package(MPI REQUIRED COMPONENTS C Fortran)
message(STATUS ${MPIEXEC_EXECUTABLE})
get_filename_component(MPI_ROOT_DIR ${MPIEXEC_EXECUTABLE} DIRECTORY)
file(GLOB MPI_VERSION_FILE
"${MPI_ROOT_DIR}/mpichversion"
"${MPI_ROOT_DIR}/ompi_info"
"${MPI_ROOT_DIR}/impi_info"
)
message(STATUS "MPI_VERSION_FILE: ${MPI_VERSION_FILE}")
option(EZP_ENABLE_TBB "Use TBB." OFF)
set(MKL_LINK static)
if (NOT MKL_THREADING)
if (EZP_ENABLE_TBB AND 0) # somehow linking tbb_thread causes segfault
set(MKL_THREADING tbb_thread)
message(STATUS "MKL_THREADING: ${MKL_THREADING}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(MKL_THREADING gnu_thread)
message(STATUS "MKL_THREADING: ${MKL_THREADING}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(MKL_THREADING intel_thread)
message(STATUS "MKL_THREADING: ${MKL_THREADING}")
endif ()
endif ()
if (NOT MKL_MPI)
if (MPI_VERSION_FILE MATCHES "ompi_info")
set(MKL_MPI openmpi)
message(STATUS "MKL_MPI: ${MKL_MPI}")
elseif (MPI_VERSION_FILE MATCHES "mpichversion")
set(MKL_MPI mpich)
message(STATUS "MKL_MPI: ${MKL_MPI}")
endif ()
endif ()
option(EZP_USE_64BIT_INT "Use 64-bit integer." OFF)
if (EZP_USE_64BIT_INT)
add_compile_definitions(EZP_INT64)
set(MKL_INTERFACE ilp64)
else ()
set(MKL_INTERFACE lp64)
endif ()
option(EZP_USE_SYSTEM_LIBS "Use system libraries." OFF)
option(EZP_ENABLE_LIS "Use Lis iterative sparse solver." ON)
option(EZP_ENABLE_MUMPS "Use MUMPS direct sparse solver." ON)
if (EZP_ENABLE_LIS)
add_subdirectory(external/lis)
endif ()
if (EZP_ENABLE_MUMPS)
add_subdirectory(external/gk)
add_subdirectory(external/mumps)
endif ()
find_package(MKL QUIET PATHS "/opt/intel/oneapi/mkl/latest")
if (MKL_FOUND)
message(STATUS "Using MKL.")
link_libraries(MKL::MKL_SCALAPACK)
add_compile_definitions(EZP_MKL)
elseif (EZP_USE_SYSTEM_LIBS)
find_library(SCALAPACK_LIB scalapack)
if (SCALAPACK_LIB)
message(STATUS "Using system libraries.")
link_libraries(${SCALAPACK_LIB})
else ()
message(FATAL_ERROR "ScaLAPACK not found.")
endif ()
find_library(FLEX_LIB flexiblas)
if (FLEX_LIB)
link_libraries(${FLEX_LIB})
endif ()
find_library(OPENBLAS_LIB openblas)
if (OPENBLAS_LIB)
message(STATUS "Using OpenBLAS.")
link_libraries(${OPENBLAS_LIB})
endif ()
else ()
link_directories(${PROJECT_SOURCE_DIR}/libs)
if (MPI_VERSION_FILE MATCHES "mpichversion")
link_libraries(scalapack-mpich)
elseif (MPI_VERSION_FILE MATCHES "ompi_info")
link_libraries(scalapack-openmpi)
endif ()
link_libraries(lapack blas gfortran)
endif ()
if (EZP_ENABLE_TBB)
if (MKL_FOUND AND MKL_THREADING STREQUAL "tbb_thread")
add_compile_definitions(EZP_TBB)
message(STATUS "Using TBB.")
else ()
find_library(TBB_LIB tbb)
if (TBB_LIB)
add_compile_definitions(EZP_TBB)
message(STATUS "Using TBB.")
link_libraries(${TBB_LIB})
endif ()
endif ()
endif ()
link_libraries(MPI::MPI_C)
if (PROJECT_IS_TOP_LEVEL)
file(GLOB EXAMPLES "*.cpp" "examples/*.cpp")
foreach (EXAMPLE ${EXAMPLES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE} NAME_WLE)
if (EXAMPLE_NAME MATCHES "mumps" AND NOT EZP_ENABLE_MUMPS)
continue()
endif ()
if (EXAMPLE_NAME MATCHES "lis" AND NOT EZP_ENABLE_LIS)
continue()
endif ()
add_executable(${EXAMPLE_NAME} ${EXAMPLE})
if (EXAMPLE_NAME MATCHES "mumps")
target_link_libraries(${EXAMPLE_NAME} mumps)
elseif (EXAMPLE_NAME MATCHES "lis")
target_link_libraries(${EXAMPLE_NAME} lis)
endif ()
endforeach ()
file(GLOB EXAMPLES "tests/*.cpp")
foreach (EXAMPLE ${EXAMPLES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE} NAME_WLE)
if (EXAMPLE_NAME MATCHES "mumps" AND NOT EZP_ENABLE_MUMPS)
continue()
endif ()
if (EXAMPLE_NAME MATCHES "lis" AND NOT EZP_ENABLE_LIS)
continue()
endif ()
add_executable(${EXAMPLE_NAME} ${EXAMPLE})
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(${EXAMPLE_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-variable>)
endif ()
if (EXAMPLE_NAME MATCHES "mumps")
target_link_libraries(${EXAMPLE_NAME} mumps)
elseif (EXAMPLE_NAME MATCHES "lis")
target_link_libraries(${EXAMPLE_NAME} lis)
endif ()
endforeach ()
option(EZP_TEST "Enable testing." OFF)
if (EZP_TEST)
add_executable(catch2 ${EXAMPLES} include/catch2/catchy.cpp)
target_compile_definitions(catch2 PRIVATE EZP_ENABLE_TEST)
if (EZP_ENABLE_MUMPS)
target_link_libraries(catch2 mumps)
endif ()
if (EZP_ENABLE_LIS)
target_link_libraries(catch2 lis)
endif ()
endif ()
endif ()
option(EZP_STANDALONE "Enable standalone solver." OFF)
if (EZP_STANDALONE)
file(GLOB EXAMPLES "standalone/*.cpp")
foreach (EXAMPLE ${EXAMPLES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE} NAME_WLE)
if (EXAMPLE_NAME MATCHES "mumps" AND NOT EZP_ENABLE_MUMPS)
continue()
endif ()
if (EXAMPLE_NAME MATCHES "lis" AND NOT EZP_ENABLE_LIS)
continue()
endif ()
add_executable(${EXAMPLE_NAME} ${EXAMPLE})
if (EXAMPLE_NAME MATCHES "mumps")
target_link_libraries(${EXAMPLE_NAME} mumps)
elseif (EXAMPLE_NAME MATCHES "lis")
target_link_libraries(${EXAMPLE_NAME} lis)
endif ()
install(TARGETS ${EXAMPLE_NAME} DESTINATION bin)
endforeach ()
endif ()
if (UNIX)
get_filename_component(EZP_BUILD_DIR "${CMAKE_BINARY_DIR}" NAME)
if (EZP_BUILD_DIR MATCHES "${CMAKE_BUILD_TYPE}")
set(EZP_SRC_JSON "${CMAKE_BINARY_DIR}/compile_commands.json")
set(EZP_DST_JSON "${CMAKE_BINARY_DIR}/../compile_commands.json")
if (EXISTS "${EZP_SRC_JSON}")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${EZP_SRC_JSON}" "${EZP_DST_JSON}")
message(STATUS "Created symlink: ${EZP_DST_JSON} -> ${EZP_SRC_JSON}")
endif ()
endif ()
endif ()