-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
379 lines (334 loc) · 12.1 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
370
371
372
373
374
375
376
377
378
379
cmake_minimum_required(VERSION 2.8.12)
project(SCALAPACK C Fortran)
# Add the CMake directory for custon CMake modules
set(CMAKE_MODULE_PATH "${SCALAPACK_SOURCE_DIR}/CMAKE" ${CMAKE_MODULE_PATH})
include(CheckFortranFunctionExists)
include(ElCheckFunctionExists)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(TEST_SCALAPACK "Test ScaLAPACK install?" ON)
# Configure the warning and code coverage suppression file
configure_file(
"${SCALAPACK_SOURCE_DIR}/CMAKE/CTestCustom.cmake.in"
"${SCALAPACK_BINARY_DIR}/CTestCustom.cmake"
COPYONLY
)
if(UNIX)
if("${CMAKE_Fortran_COMPILER}" MATCHES "ifort")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fltconsistency -fp_port")
endif()
endif()
#
# MPI
#
set(CMAKE_PREFIX_PATH "${MPI_BASE_DIR};${CMAKE_PREFIX_PATH}")
find_package(MPI)
if(NOT MPI_C_FOUND)
message(FATAL_ERROR "MPI C compiler was not found and is required")
endif()
if(NOT MPI_Fortran_FOUND)
message(FATAL_ERROR "MPI Fortran compiler was not found and is required")
endif()
include_directories(${MPI_C_INCLUDE_PATH})
include_directories(${MPI_Fortran_INCLUDE_PATH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}")
macro(SCALAPACK_install_library lib)
install(TARGETS ${lib} EXPORT scalapack-targets
ARCHIVE DESTINATION lib${LIB_SUFFIX}
LIBRARY DESTINATION lib${LIB_SUFFIX}
RUNTIME DESTINATION Testing)
endmacro()
# --------------------------------------------------
# Testing
if(TEST_SCALAPACK)
SET(DART_TESTING_TIMEOUT 600)
enable_testing()
include(CTest)
enable_testing()
endif()
# --------------------------------------------------
# Organize output files. On Windows this also keeps .dll files next
# to the .exe files that need them, making tests easy to run.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SCALAPACK_BINARY_DIR}/TESTING)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SCALAPACK_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SCALAPACK_BINARY_DIR}/lib)
# --------------------------------------------------
# Check for any necessary platform specific compiler flags
include(CheckBLACSCompilerFlags)
CheckBLACSCompilerFlags()
set(prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
# --------------------------------------------------
# BLACS Internal variables
#
# Fortran Mangling, MPI Tests and BLACS settings
#
include(FortranMangling)
COMPILE(install_COMPILED)
FORTRAN_MANGLING(CDEFS)
message(STATUS "=========")
# --------------------------------------------------
# Compiler Flags
add_definitions("-D${CDEFS}")
# --------------------------------------------------
# ScaLAPACK needs BLAS and LAPACK
option(USE_OPTIMIZED_LAPACK_BLAS "Whether or not to search for optimized LAPACK and BLAS libraries on your machine (if not found, Reference LAPACK and BLAS will be downloaded and installed)" ON)
message(STATUS "CHECKING BLAS AND LAPACK LIBRARIES")
if(LAPACK_LIBRARIES)
message(STATUS "--> LAPACK supplied by user is ${LAPACK_LIBRARIES}.")
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
check_fortran_function_exists("dgesv" LAPACK_FOUND)
unset(CMAKE_REQUIRED_LIBRARIES)
if(LAPACK_FOUND)
message(STATUS
"--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
else()
message(FATAL_ERROR "--> LAPACK supplied by user is NOT working.")
endif()
endif()
if(FORCE_BLIS_LAPACK_BUILD)
set(BUILD_BLIS_LAPACK TRUE)
set(PREFER_BLIS_LAPACK TRUE)
set(DISABLE_OPENBLAS TRUE)
elseif(FORCE_OPENBLAS_BUILD)
set(BUILD_OPENBLAS TRUE)
set(PREFER_OPENBLAS TRUE)
set(DISABLE_BLIS_LAPACK TRUE)
endif()
# Test for pre-built libraries
# ----------------------------
# Check for MKL
# ^^^^^^^^^^^^^
if(SCALAPACK_HYBRID)
set(MKL_LIBS "-mkl")
else()
set(MKL_LIBS "-mkl=sequential")
endif()
message(STATUS "Attempting to link MKL using ${MKL_LIBS}")
set(CMAKE_REQUIRED_FLAGS ${MKL_LIBS})
El_check_function_exists(dpotrf HAVE_DPOTRF_MKL)
El_check_function_exists(dpotrf_ HAVE_DPOTRF_POST_MKL)
if(HAVE_DPOTRF_MKL OR HAVE_DPOTRF_POST_MKL)
set(HAVE_MKL TRUE)
endif()
unset(CMAKE_REQUIRED_FLAGS)
if(APPLE)
# Check for Accelerate
# ^^^^^^^^^^^^^^^^^^^^
message(STATUS "Testing for LAPACK support via Accelerate")
set(ACCELERATE_LIBS "-framework Accelerate")
set(CMAKE_REQUIRED_LIBRARIES ${ACCELERATE_LIBS})
El_check_function_exists(dpotrf HAVE_ACCELERATE_NO_UNDER)
El_check_function_exists(dpotrf_ HAVE_ACCELERATE_UNDER)
unset(CMAKE_REQUIRED_LIBRARIES)
if(HAVE_ACCELERATE_NO_UNDER OR HAVE_ACCELERATE_UNDER)
set(HAVE_ACCELERATE TRUE)
endif()
# Check for vecLib
# ^^^^^^^^^^^^^^^^
message(STATUS "Testing for LAPACK support via vecLib")
set(VECLIB_LIBS "-framework vecLib")
set(CMAKE_REQUIRED_LIBRARIES ${VECLIB_LIBS})
El_check_function_exists(dpotrf HAVE_VECLIB_NO_UNDER)
El_check_function_exists(dpotrf_ HAVE_VECLIB_UNDER)
unset(CMAKE_REQUIRED_LIBRARIES)
if(HAVE_VECLIB_NO_UNDER OR HAVE_VECLIB_UNDER)
set(HAVE_VECLIB TRUE)
endif()
endif()
if(APPLE)
if(PREFER_OPENBLAS AND NOT LAPACK_FOUND)
include(ExternalOpenBLAS)
if(HAVE_OPENBLAS)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${OPENBLAS_LIBS})
elseif(FORCE_OPENBLAS_BUILD)
message(FATAL_ERROR "Demand that OpenBLAS be built could not be met")
endif()
endif()
if(PREFER_BLIS_LAPACK AND NOT LAPACK_FOUND)
include(ExternalBLISLAPACK)
if(HAVE_BLIS_LAPACK)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${BLIS_LAPACK_LIBS})
elseif(FORCE_BLIS_LAPACK_BUILD)
set(FATAL_ERROR "Demand that BLIS+LAPACK be built could not be met")
endif()
endif()
if(HAVE_MKL AND NOT DISABLE_MKL AND NOT LAPACK_FOUND)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${MKL_LIBS})
endif()
if(HAVE_ACCELERATE AND NOT LAPACK_FOUND)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${ACCELERATE_LIBS})
message(STATUS "Using Apple Accelerate framework.")
elseif(HAVE_VECLIB AND NOT LAPACK_FOUND)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${VECLIB_LIBS})
message(STATUS "Using Apple vecLib framework.")
elseif(NOT LAPACK_FOUND AND FORCE_APPLE_MATH)
message(FATAL_ERROR "Demand that Apple math be used could not be met")
endif()
endif()
if(NOT PREFER_BLIS_LAPACK AND NOT PREFER_OPENBLAS AND
HAVE_MKL AND NOT DISABLE_MKL AND NOT LAPACK_FOUND)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${MKL_LIBS})
endif()
if(NOT LAPACK_FOUND AND NOT PREFER_BLIS_LAPACK AND NOT DISABLE_OPENBLAS)
include(ExternalOpenBLAS)
if(HAVE_OPENBLAS)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${OPENBLAS_LIBS})
elseif(FORCE_OPENBLAS_BUILD)
message(FATAL_ERROR "Demand that OpenBLAS be built could not be met")
endif()
endif()
if(NOT LAPACK_FOUND AND NOT DISABLE_BLIS_LAPACK)
include(ExternalBLISLAPACK)
if(HAVE_BLIS_LAPACK)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES ${BLIS_LAPACK_LIBS})
elseif(FORCE_BLIS_LAPACK_BUILD)
set(FATAL_ERROR "Demand that BLIS+LAPACK be built could not be met")
endif()
endif()
if(NOT LAPACK_FOUND)
message(STATUS
"--> Searching for optimized LAPACK and BLAS libraries on your machine.")
find_package(LAPACK)
endif()
message(STATUS "BLAS library: ${BLAS_LIBRARIES}")
message(STATUS "LAPACK library: ${LAPACK_LIBRARIES}")
message(STATUS "=========")
# --------------------------------------------------
# Subdirectories that need to be processed
macro(append_subdir_files variable dirname)
get_directory_property(holder DIRECTORY ${dirname} DEFINITION ${variable})
foreach(depfile ${holder})
list(APPEND ${variable} "${dirname}/${depfile}")
endforeach()
endmacro()
#
# BLACS
#
add_subdirectory(BLACS)
append_subdir_files(blacs "BLACS/SRC")
#
# TOOLS
#
add_subdirectory(TOOLS)
append_subdir_files(tools TOOLS)
append_subdir_files(tools-C TOOLS)
append_subdir_files(extra_lapack "TOOLS/LAPACK")
#
# PBLAS
#
add_subdirectory(PBLAS)
append_subdir_files(pblas "PBLAS/SRC")
append_subdir_files(pblas-F "PBLAS/SRC")
append_subdir_files(pbblas "PBLAS/SRC/PBBLAS")
append_subdir_files(ptzblas "PBLAS/SRC/PTZBLAS")
append_subdir_files(ptools "PBLAS/SRC/PTOOLS")
#
# REDIST
#
add_subdirectory(REDIST)
append_subdir_files(redist "REDIST/SRC")
#
# SRC
#
add_subdirectory(SRC)
append_subdir_files(src "SRC")
append_subdir_files(src-C "SRC")
if(UNIX)
add_library(scalapack ${blacs} ${tools} ${tools-C} ${extra_lapack} ${pblas} ${pblas-F} ${ptzblas} ${ptools} ${pbblas} ${redist} ${src} ${src-C})
if(BUILT_OPENBLAS)
add_dependencies(scalapack project_openblas)
endif()
if(BUILT_BLIS_LAPACK)
add_dependencies(scalapack project_blis_lapack)
endif()
target_link_libraries(scalapack ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES})
if(MPI_C_LINK_FLAGS)
set_target_properties(scalapack PROPERTIES LINK_FLAGS ${MPI_C_LINK_FLAGS})
endif()
scalapack_install_library(scalapack)
else() # Need to separate Fortran and C Code
add_library(scalapack ${blacs} ${tools-C} ${pblas} ${ptools} ${redist} ${src-C})
if(BUILT_OPENBLAS)
add_dependencies(scalapack project_openblas)
endif()
if(BUILT_BLIS_LAPACK)
add_dependencies(scalapack project_blis_lapack)
endif()
target_link_libraries(scalapack ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MPI_C_LIBRARIES})
add_library(scalapack-F ${pblas-F} ${pbblas} ${ptzblas} ${tools} ${src} ${extra_lapack} )
if(BUILT_OPENBLAS)
add_dependencies(scalapack-F project_openblas)
endif()
if(BUILT_BLIS_LAPACK)
add_dependencies(scalapack-F project_blis_lapack)
endif()
target_link_libraries(scalapack-F ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MPI_Fortran_LIBRARIES})
if(MPI_C_LINK_FLAGS)
set_target_properties(scalapack PROPERTIES LINK_FLAGS ${MPI_C_LINK_FLAGS})
set_target_properties(scalapack-F PROPERTIES LINK_FLAGS ${MPI_C_LINK_FLAGS})
endif()
scalapack_install_library(scalapack)
scalapack_install_library(scalapack-F)
endif()
if(TEST_SCALAPACK)
add_subdirectory(TESTING)
endif()
# --------------------------------------------------
# CPACK Packaging
set(CPACK_PACKAGE_NAME "ScaLAPACK")
set(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ScaLAPACK- Linear Algebra Package")
set(SCALAPACK_VERSION 2.0.2)
set(CPACK_PACKAGE_VERSION_MAJOR 2)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 2)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "SCALAPACK")
if(WIN32 AND NOT UNIX)
# There is a bug in NSI that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/scalapack")
set(CPACK_NSIS_CONTACT "[email protected]")
set(CPACK_NSIS_MODIFY_PATH ON)
set(CPACK_NSIS_DISPLAY_NAME "SCALAPACK-${SCALAPACK_VERSION}")
set(CPACK_PACKAGE_RELOCATABLE "true")
else()
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR TGZ)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "scalapack-${SCALAPACK_VERSION}" )
set(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
endif()
include(CPack)
# --------------------------------------------------
export(TARGETS scalapack FILE scalapack-targets.cmake)
configure_file(
${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-version.cmake.in
${SCALAPACK_BINARY_DIR}/scalapack-config-version.cmake @ONLY)
configure_file(
${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-build.cmake.in
${SCALAPACK_BINARY_DIR}/scalapack-config.cmake @ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/CMAKE/scalapack.pc.in
${CMAKE_CURRENT_BINARY_DIR}/scalapack.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scalapack.pc
DESTINATION ${PKG_CONFIG_DIR})
configure_file(
${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-install.cmake.in
${SCALAPACK_BINARY_DIR}/CMakeFiles/scalapack-config.cmake @ONLY)
install(FILES
${SCALAPACK_BINARY_DIR}/CMakeFiles/scalapack-config.cmake
${SCALAPACK_BINARY_DIR}/scalapack-config-version.cmake
DESTINATION lib/cmake/scalapack-${SCALAPACK_VERSION})
install(EXPORT scalapack-targets
DESTINATION lib/cmake/scalapack-${SCALAPACK_VERSION})