forked from LLNL/Elemental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
369 lines (293 loc) · 11.5 KB
/
CMakeLists.txt
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
cmake_minimum_required(VERSION 3.9)
project(Hydrogen C CXX)
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif ()
set(HYDROGEN_VERSION_MAJOR 0)
set(HYDROGEN_VERSION_MINOR 1)
# Back-compatibility, until it's all sorted out
set(EL_VERSION_MAJOR ${HYDROGEN_VERSION_MAJOR})
set(EL_VERSION_MINOR ${HYDROGEN_VERSION_MINOR})
string(TOUPPER "${PROJECT_NAME}" UPPER_PROJECT_NAME)
if (NOT CMAKE_BUILD_TYPE MATCHES "Debug")
set(HYDROGEN_RELEASE_BUILD TRUE)
endif ()
# Prevent in-source builds
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR
"In-source build attempted; please clean the CMake cache and then "
"switch to an out-of-source build, e.g.,\n"
"rm CMakeCache.txt && rm -Rf CMakeFiles/\nmkdir build/ && "
"cd build/ && cmake ..\n")
endif ()
# Set the module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
# Add warning flags
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-pedantic" CXX_COMPILER_HAS_PEDANTIC_FLAG)
check_cxx_compiler_flag("-Wpedantic" CXX_COMPILER_HAS_WPEDANTIC_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
if (CXX_COMPILER_HAS_PEDANTIC_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
elseif (CXX_COMPILER_HAS_WPEDANTIC_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wpedantic")
endif ()
# Configuration options
option(${PROJECT_NAME}_EXPORT_PACKAGE_REGISTRY
"Export the build directory to the user's CMake package registry." OFF)
if (NOT ${PROJECT_NAME}_EXPORT_PACKAGE_REGISTRY)
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON)
endif ()
option(CMAKE_POSITION_INDEPENDENT_CODE
"Build using position-independent code" ON)
option(${PROJECT_NAME}_ENABLE_TESTING "Build the test suite." ON)
option(${PROJECT_NAME}_ENABLE_QUADMATH
"Search for quadmath library and enable related features if found." OFF)
option(${PROJECT_NAME}_ENABLE_QD
"Search for QD library and enable related features if found." OFF)
option(${PROJECT_NAME}_ENABLE_MPC
"Search for MPC(+MPFR+GMP) library and enable related features if found."
OFF)
option(${PROJECT_NAME}_ENABLE_CUDA
"Search for CUDA support and enable related features if found."
ON)
if (${PROJECT_NAME}_ENABLE_CUDA)
option(${PROJECT_NAME}_ENABLE_CUB
"Search for CUB support and enable related features if found."
ON)
endif ()
# Legacy options, with EL_ prefix intact
option(BINARY_SUBDIRECTORIES "Install binaries into tree based on type" ON)
#
# MEMORY-RELATED OPTIONS
#
option(${PROJECT_NAME}_USE_64BIT_INTS
"Use 64-bit integers for internal indexing" OFF)
option(${PROJECT_NAME}_USE_64BIT_BLAS_INTS
"Use 64-bit integers for BLAS/LAPACK" OFF)
if (${PROJECT_NAME}_USE_64BIT_BLAS_INTS)
set(EL_USE_64BIT_BLAS_INTS ON)
set(${PROJECT_NAME}_USE_64BIT_INTS ON)
endif ()
if (${PROJECT_NAME}_USE_64BIT_INTS)
set(EL_USE_64BIT_INTS ON)
endif ()
option(${PROJECT_NAME}_ZERO_INIT "Initialize buffers to zero by default?" OFF)
mark_as_advanced(${PROJECT_NAME}_ZERO_INIT)
option(${PROJECT_NAME}_ENABLE_VALGRIND
"Search for valgrind and enable related features" OFF)
mark_as_advanced(${PROJECT_NAME}_ENABLE_VALGRIND)
#
# OpenMP
#
option(${PROJECT_NAME}_ENABLE_OPENMP
"Enable OpenMP support in Hydrogen" OFF)
# At one point, a bug was found in IBM's C++ compiler for Blue Gene/P,
# where OpenMP statements of the form a[i] += alpha b[i], with complex data,
# would segfault and/or return incorrect results
option(${PROJECT_NAME}_AVOID_OMP_FMA "Avoid a bug in the IBM compilers." OFF)
mark_as_advanced(${PROJECT_NAME}_AVOID_OMP_FMA)
#
# MPI
#
option(${PROJECT_NAME}_USE_CUSTOM_ALLTOALLV "Avoid MPI_Alltoallv for performance reasons" ON)
mark_as_advanced(${PROJECT_NAME}_USE_CUSTOM_ALLTOALLV)
# Since it is surprisingly common for MPI libraries to have bugs in their
# support for complex data, the following option forces Elemental to cast
# all possible MPI communications in terms of twice as many real units of data.
option(${PROJECT_NAME}_AVOID_COMPLEX_MPI "Avoid potentially buggy complex MPI routines" ON)
mark_as_advanced(${PROJECT_NAME}_AVOID_COMPLEX_MPI)
# Due to a subtle flaw in the Blue Gene/P extensions for MPICH2, treating
# floating-point data as a collection of byte-sized objects results in a
# better algorithm being chosen for MPI_Allgather. This should not effect
# performance on most machines.
option(${PROJECT_NAME}_USE_BYTE_ALLGATHERS "Avoid BG/P allgather performance bug." ON)
mark_as_advanced(${PROJECT_NAME}_USE_BYTE_ALLGATHERS)
# If MPI_Reduce_scatter_block doesn't exist, perform it by composing
# MPI_Allreduce and std::memcpy rather than MPI_Reduce and MPI_Scatter
option(${PROJECT_NAME}_REDUCE_SCATTER_BLOCK_VIA_ALLREDUCE
"AllReduce based block MPI_Reduce_scatter" OFF)
mark_as_advanced(${PROJECT_NAME}_REDUCE_SCATTER_BLOCK_VIA_ALLREDUCE)
#
# Runtime warnings
#
# Print a warning any time a redistribution is performed which unpacks a
# large amount of data with a non-unit stride
option(${PROJECT_NAME}_CACHE_WARNINGS "Warns when using cache-unfriendly routines" OFF)
mark_as_advanced(${PROJECT_NAME}_CACHE_WARNINGS)
# Print a warning when an improperly aligned redistribution is performed,
# i.e., if an unnecessary permutation communication stage must take place
option(${PROJECT_NAME}_UNALIGNED_WARNINGS
"Warn when performing unaligned redistributions" OFF)
mark_as_advanced(${PROJECT_NAME}_UNALIGNED_WARNINGS)
# Print a warning if an opportunity was missed to implement a redistribution
# approach specifically for vectors (instead of matrices)
option(${PROJECT_NAME}_VECTOR_WARNINGS
"Warn when vector redistribution chances are missed" OFF)
mark_as_advanced(${PROJECT_NAME}_VECTOR_WARNINGS)
#
# Check the compiler features
#
if (${PROJECT_NAME}_ENABLE_CUDA)
include(CheckLanguage)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if (NOT CMAKE_CUDA_STANDARD OR CMAKE_CUDA_STANDAR EQUAL 98)
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
endif ()
find_package(CUDA) # Enable all the macros
if (${PROJECT_NAME}_ENABLE_CUB)
find_package(CUB REQUIRED)
set(HYDROGEN_HAVE_CUB TRUE)
else ()
set(HYDROGEN_HAVE_CUB FALSE)
endif ()
if (NOT TARGET cuda::toolkit)
add_library(cuda::toolkit INTERFACE IMPORTED)
set_property(TARGET cuda::toolkit PROPERTY
INTERFACE_LINK_LIBRARIES
"${CUDA_CUBLAS_LIBRARIES}" "${CUDA_LIBRARIES}" "${CUB_LIBRARIES}")
set_property(TARGET cuda::toolkit PROPERTY
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CUDA>:-arch=sm_30>)
set_property(TARGET cuda::toolkit PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${CUDA_INCLUDE_DIRS}")
endif ()
set(HYDROGEN_HAVE_CUDA TRUE)
else ()
message(FATAL_ERROR "CUDA support not found. Disabling CUDA the features.")
set(${PROJECT_NAME}_ENABLE_CUDA FALSE)
set(HYDROGEN_HAVE_CUDA FALSE)
endif ()
endif (${PROJECT_NAME}_ENABLE_CUDA)
# FIXME: GET RID OF FORTRAN
include(detect/CXX)
include(detect/Fortran)
#
# Find third-party libraries
#
if (${PROJECT_NAME}_ENABLE_OPENMP)
include(FindAndVerifyOpenMP)
if (OpenMP_FOUND)
set(EL_HYBRID ON)
set(EL_HAVE_OPENMP TRUE)
else ()
message(WARNING "Requested OpenMP support but OpenMP support was either "
"not found or not functional.")
set(EL_HYBRID OFF)
set(EL_HAVE_OPENMP FALSE)
set(${PROJECT_NAME}_ENABLE_OPENMP OFF)
endif ()
endif (${PROJECT_NAME}_ENABLE_OPENMP)
include(FindAndVerifyMPI)
include(FindAndVerifyLAPACK)
include(FindAndVerifyExtendedPrecision)
# External projects build internally
# TODO Investigate why
add_subdirectory(external/pmrrr)
# Add SuiteSparse (TODO: Why bundled here?)
add_subdirectory(external/suite_sparse)
include_directories(external/suite_sparse/include)
# Macro for setting up full paths
macro(set_full_path VAR)
unset(__tmp_names)
foreach(filename ${ARGN})
unset(__name)
get_filename_component(__name "${filename}" ABSOLUTE)
list(APPEND __tmp_names "${__name}")
endforeach()
set(${VAR} "${__tmp_names}")
endmacro()
set(HYDROGEN_HEADERS)
set(HYDROGEN_SOURCES)
add_subdirectory(include)
add_subdirectory(src)
configure_file("${PROJECT_SOURCE_DIR}/cmake/configure_files/config.h.in"
"${PROJECT_BINARY_DIR}/include/El/config.h")
configure_file("${PROJECT_SOURCE_DIR}/cmake/configure_files/hydrogen_config.h.in"
"${PROJECT_BINARY_DIR}/include/El/hydrogen_config.h")
add_library(${PROJECT_NAME} "${HYDROGEN_SOURCES}" "${HYDROGEN_HEADERS}")
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/El>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
if (TARGET OpenMP::OpenMP_CXX)
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
endif ()
target_link_libraries(${PROJECT_NAME} PUBLIC pmrrr)
target_link_libraries(${PROJECT_NAME} PUBLIC MPI::MPI_CXX)
target_link_libraries(${PROJECT_NAME} PUBLIC LAPACK::lapack)
target_link_libraries(${PROJECT_NAME} PUBLIC EP::extended_precision)
if (HYDROGEN_HAVE_CUDA)
target_link_libraries(${PROJECT_NAME} PUBLIC cuda::toolkit)
endif ()
if (BUILD_SHARED_LIBS)
if (APPLE)
target_link_libraries(${PROJECT_NAME} PUBLIC "-Wl,-undefined,error")
else ()
target_link_libraries(${PROJECT_NAME} PUBLIC "-Wl,-no-undefined")
endif ()
endif ()
# Setup the tests
if (${PROJECT_NAME}_ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
endif ()
# Setup the library install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include/El
)
# Install target stuff
include (CMakePackageConfigHelpers)
# Write the version file for both the build and the install tree
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/HydrogenConfigVersion.cmake"
VERSION "${HYDROGEN_VERSION_MAJOR}.${HYDROGEN_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
# Write the configure file for the build tree
set(INCLUDE_INSTALL_DIRS "${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include/El"
"${CMAKE_BINARY_DIR}/include/El")
set(LIB_INSTALL_DIR "${CMAKE_BINARY_DIR}")
configure_package_config_file(cmake/configure_files/HydrogenConfig.cmake.in
"${CMAKE_BINARY_DIR}/HydrogenConfig.cmake"
INSTALL_DESTINATION "${CMAKE_BINARY_DIR}"
PATH_VARS INCLUDE_INSTALL_DIRS LIB_INSTALL_DIR)
# Build tree export
export(EXPORT HydrogenTargets NAMESPACE H:: FILE HydrogenTargets.cmake)
# Write the configure file for the install tree
set(INCLUDE_INSTALL_DIRS include)
set(LIB_INSTALL_DIR lib)
set(CMAKE_INSTALL_DIR lib/cmake/hydrogen)
configure_package_config_file(cmake/configure_files/HydrogenConfig.cmake.in
"${CMAKE_BINARY_DIR}/cmake/HydrogenConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}
PATH_VARS INCLUDE_INSTALL_DIRS LIB_INSTALL_DIR)
# Install the configuration headers
install(FILES
"${PROJECT_BINARY_DIR}/include/El/config.h"
"${PROJECT_BINARY_DIR}/include/El/hydrogen_config.h"
DESTINATION "include/El")
# Install tree export
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE H::
DESTINATION lib/cmake/hydrogen)
# Install the headers
install(DIRECTORY include DESTINATION .
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
# Install the cmake stuff
install(FILES
"${PROJECT_BINARY_DIR}/cmake/HydrogenConfig.cmake"
"${PROJECT_BINARY_DIR}/HydrogenConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DIR})
install(DIRECTORY cmake/modules DESTINATION lib/cmake/hydrogen
FILES_MATCHING PATTERN "*.cmake")