-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeListsLib.txt
520 lines (455 loc) · 21.4 KB
/
CMakeListsLib.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# =========================================================================
# Add the libraries
# =========================================================================
# Set directory to compile external libraries
IF(LIBS_USE_MPI)
SET(LIBS_EXTERNAL_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/${CMAKE_Fortran_COMPILER_ID}-MPI)
ELSE()
SET(LIBS_EXTERNAL_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/${CMAKE_Fortran_COMPILER_ID})
ENDIF()
MARK_AS_ADVANCED(FORCE LIBS_EXTERNAL_LIB_DIR)
# =========================================================================
# Check where the code originates
# =========================================================================
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
EXECUTE_PROCESS(COMMAND git ls-remote --get-url OUTPUT_VARIABLE GIT_ORIGIN)
# Strip lead and trailing white space
string(STRIP ${GIT_ORIGIN} GIT_ORIGIN)
# Origin pointing to gitlab?
MESSAGE(STATUS "Checking git origin: " ${GIT_ORIGIN})
ENDIF()
# Origin pointing to IAG
IF("${GIT_ORIGIN}" MATCHES ".iag.uni-stuttgart.de")
# Strip leading and trailing white space
STRING(STRIP ${GIT_ORIGIN} GIT_ORIGIN)
# Checked out using SSH
IF("${GIT_ORIGIN}" MATCHES "^git@")
SET(LIBS_DLPATH "[email protected]:")
# Checked out using HTTPS
# IF("${GIT_ORIGIN}" MATCHES "^https@")
ELSE()
SET(LIBS_DLPATH "https://gitlab.iag.uni-stuttgart.de/")
ENDIF()
# Origin pointing to ILA
ELSEIF("${GIT_ORIGIN}" MATCHES "ila.uni-stuttgart.de")
# Checked out using SSH
IF("${GIT_ORIGIN}" MATCHES "^git@")
SET(LIBS_DLPATH "[email protected]:")
# Checked out using HTTPS
# IF("${GIT_ORIGIN}" MATCHES "^https@")
ELSE()
SET(LIBS_DLPATH "https://gitlab.ila.uni-stuttgart.de/")
ENDIF()
ELSE()
# Fallback to github
SET(GIT_ORIGIN ".github.com")
ENDIF()
# =========================================================================
# MPI
# =========================================================================
OPTION(LIBS_USE_MPI "Compile SINGLE or MPI version" OFF)
MARK_AS_ADVANCED(FORCE LIBS_USE_MPI)
IF(LIBS_USE_MPI)
SET(MPI_DETERMINE_LIBRARY_VERSION TRUE)
FIND_PACKAGE(MPI REQUIRED)
IF (NOT MPI_Fortran_NO_INTERROGATE)
FOREACH(DIR ${MPI_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${DIR})
ENDFOREACH()
FOREACH(DIR ${MPI_Fortran_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${DIR})
ENDFOREACH()
LIST(APPEND linkedlibs ${MPI_Fortran_LIBRARIES})
ENDIF()
MARK_AS_ADVANCED(FORCE MPI_LIBRARY MPI_EXTRA_LIBRARY)
# Detect MPI implementation and version since it changes some MPI definitions
IF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*CRAY MPICH.*" AND MPI_C_VERSION_MAJOR MATCHES "3")
SET(LIBS_MPI_NAME "Cray MPICH")
STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING})
ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*MPICH.*" AND MPI_C_VERSION_MAJOR MATCHES "3")
SET(LIBS_MPI_NAME "MPICH")
STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING})
ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*Open MPI.*" AND MPI_C_VERSION_MAJOR MATCHES "3")
SET(LIBS_MPI_NAME "OpenMPI")
STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING})
ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*HPE MPT.*" AND MPI_C_VERSION_MAJOR MATCHES "3")
SET(LIBS_MPI_NAME "HPE MPT")
STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING})
ADD_DEFINITIONS(-DLIBS_MPT=1)
ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*Intel.*" AND MPI_C_VERSION_MAJOR MATCHES "3")
SET(LIBS_MPI_NAME "Intel MPI")
STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING})
ELSE()
MESSAGE(FATAL_ERROR "Cannot detect supported MPI type or version. Valid options are Cray MPICH, IntelMPI, MPICH, HPE MPT, and OpenMPI supporting MPI version 3.x")
ENDIF()
MESSAGE(STATUS "Compiling with [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})")
ADD_DEFINITIONS(-DUSE_MPI=1)
ELSE()
UNSET(LIBS_MPI_NAME)
UNSET(MPI_C_LIBRARY_VERSION)
ADD_DEFINITIONS(-DUSE_MPI=0)
ENDIF()
# =========================================================================
# HDF5 library
# =========================================================================
SET(LIBS_BUILD_HDF5 ON CACHE BOOL "Compile and build HDF5 library")
# Set type of library to look up, STATIC/SHARED
SET(LIB_TYPE STATIC)
STRING(TOLOWER ${LIB_TYPE} SEARCH_TYPE)
# We support two methods for finding HDF5:
# a) the version built using configure scripts and b) using CMake
# Support for CMake-built HDF5 is limited to version >1.10.2 which require at CMake >3.10
# Check for env variable HDF5_ROOT as this can cause problems with subsequent building of cmake
SET(HDF5_ROOT "$ENV{HDF5_ROOT}" CACHE STRING "Expose HDF5_ROOT environment variable (cannot be changed here). Use 'export HDF5_ROOT=' to clear the variable." FORCE)
# Use system HDF5
IF(NOT LIBS_BUILD_HDF5)
# Unset leftover paths from old CMake runs
UNSET(HDF5_LIBRARIES)
UNSET(HDF5_INCLUDE_DIR_FORTRAN)
UNSET(HDF5_INCLUDE_DIR)
UNSET(HDF5_DIFF_EXECUTABLE)
# Try to find the CMake version
SET(LIBS_HDF5_CMAKE TRUE)
FIND_PACKAGE(HDF5 NAMES hdf5 COMPONENTS C Fortran ${SEARCH_TYPE} QUIET PATH_SUFFIXES share/cmake)
# CMake version found
IF (HDF5_FOUND)
IF(${CMAKE_VERSION} VERSION_LESS "3.10.0")
MESSAGE (WARNING "HDF5 built with CMake was found! This feature is only supported for CMake 3.10+ and HDF5 1.10.2+ !")
ENDIF()
MESSAGE (STATUS "HDF5 C libs:${HDF5_FOUND} static:${HDF5_static_C_FOUND} and shared:${HDF5_shared_C_FOUND}")
MESSAGE (STATUS "HDF5 Fortran libs: static:${HDF5_static_Fortran_FOUND} and shared:${HDF5_shared_Fortran_FOUND}")
MESSAGE (STATUS "h5diff found:${HDF5_DIFF_EXECUTABLE}")
ELSE()
# Try to find the configure version
SET(LIBS_HDF5_CMAKE FALSE)
FIND_PACKAGE(HDF5 COMPONENTS C Fortran)
# In case CMake did not find HDF5 here, it will generate an error by itself
ENDIF()
# Hide all the HDF5 libs paths
MARK_AS_ADVANCED(FORCE HDF5_DIR)
MARK_AS_ADVANCED(FORCE HDF5_C_LIBRARY_dl)
MARK_AS_ADVANCED(FORCE HDF5_C_LIBRARY_hdf5)
MARK_AS_ADVANCED(FORCE HDF5_C_LIBRARY_m)
MARK_AS_ADVANCED(FORCE HDF5_C_LIBRARY_sz)
MARK_AS_ADVANCED(FORCE HDF5_C_LIBRARY_z)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_dl)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_hdf5)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_hdf5_fortran)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_m)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_sz)
MARK_AS_ADVANCED(FORCE HDF5_Fortran_LIBRARY_z)
# Build HDF5 in HOPR
ELSE()
# Origin pointing to Github
IF("${GIT_ORIGIN}" MATCHES ".github.com")
SET (HDF5DOWNLOAD "https://github.com/HDFGroup/hdf5.git")
ELSE()
SET (HDF5DOWNLOAD ${LIBS_DLPATH}libs/hdf5.git )
ENDIF()
SET (HDF5_DOWNLOAD ${HDF5DOWNLOAD} CACHE STRING "HDF5 Download-link")
MESSAGE (STATUS "Downloading HDF5 from ${HDF5DOWNLOAD}")
MARK_AS_ADVANCED(FORCE HDF5_DOWNLOAD)
#SET HDF5_TAG depending on MPI Version
IF(LIBS_USE_MPI)
# HDF5 1.12.0 and greater is compatible with OpenMPI 4.0.0 and greater
IF("${LIBS_MPI_NAME}" MATCHES "OpenMPI" AND ${MPI_C_LIBRARY_VERSION} VERSION_GREATER_EQUAL "4.0.0")
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
ELSE()
SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag")
ENDIF()
MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} to be compatible with detected [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})")
ELSE()
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} as no MPI support was requested")
ENDIF()
MARK_AS_ADVANCED(FORCE HDF5_TAG)
# Set HDF5 build dir
SET(LIBS_HDF5_DIR ${LIBS_EXTERNAL_LIB_DIR}/HDF5/build)
# Check if HDF5 was already built
IF (NOT EXISTS "${LIBS_HDF5_DIR}/lib/libhdf5.a")
# Set if HDF5 should be built in parallel
IF(LIBS_USE_MPI)
SET(LIBS_HDF5PARALLEL --enable-parallel)
SET(LIBS_HDF5FC ${MPI_Fortran_COMPILER})
SET(LIBS_HDF5CC ${MPI_C_COMPILER})
ELSE()
UNSET(LIBS_HDF5PARALLEL)
SET(LIBS_HDF5FC ${CMAKE_Fortran_COMPILER})
SET(LIBS_HDF5CC ${CMAKE_C_COMPILER} )
ENDIF()
# Set parallel build with maximum number of threads
INCLUDE(ProcessorCount)
PROCESSORCOUNT(N)
# Optional Features:
# --enable-silent-rules less verbose build output (undo: "make V=1")
# --enable-build-mode=(debug|production|clean)
# Sets the build mode. Debug turns on symbols, API
# tracing, asserts, and debug optimization, as well as
# several other minor configure options that aid in
# debugging. Production turns high optimizations on.
# Clean turns nothing on and disables optimization
# (i.e.: a 'clean slate' configuration). All these
# settings can be overridden by using specific
# configure flags. [default=production]
# --disable-dependency-tracking
# speeds up one-time build
# Let CMake take care of download, configure and build
EXTERNALPROJECT_ADD(HDF5
GIT_REPOSITORY ${HDF5_DOWNLOAD}
GIT_TAG ${HDF5_TAG}
GIT_PROGRESS TRUE
${${GITSHALLOW}}
PREFIX ${LIBS_HDF5_DIR}
UPDATE_COMMAND ""
CONFIGURE_COMMAND FC=${LIBS_HDF5FC} CC=${LIBS_HDF5CC} ${LIBS_HDF5_DIR}/src/HDF5/configure --prefix=${LIBS_HDF5_DIR} --with-pic --enable-fortran ${LIBS_HDF5PARALLEL} --libdir=${LIBS_HDF5_DIR}/lib --enable-build-mode=production --enable-silent-rules --disable-dependency-tracking
BUILD_BYPRODUCTS ${LIBS_HDF5_DIR}/lib/libhdf5_fortran.a ${LIBS_HDF5_DIR}/lib/libhdf5.a ${LIBS_HDF5_DIR}/bin/h5diff
# Configure explicitly requires GNU make
BUILD_COMMAND make -j${N}
)
SET(LIBS_HDF5_CMAKE FALSE)
# CMake HDF5 is fast but not yet reliable. The following section can be enabled once HDF5 promotes the CMake option to stable
#EXTERNALPROJECT_ADD(HDF5
# GIT_REPOSITORY ${HDF5DOWNLOAD}
# GIT_TAG ${HDF5_TAG}
# GIT_PROGRESS TRUE
# PREFIX ${LIBS_HDF5_DIR}
# UPDATE_COMMAND ""
# CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBS_HDF5_DIR} -DCMAKE_C_COMPILER=${LIBS_HDF5CC} -DCMAKE_Fortran_COMPILER=${LIBS_HDF5FC} -DBUILD-TESTING=OFF -DHDF5_BUILD_EXAMPLES=OFF -DHDF5_BUILD_TOOLS=OFF -DHDF5_BUILD_FORTRAN=ON -DHDF5_ENABLE_PARALLEL=ON
# BUILD_COMMAND ${MAKE}
#)
# SET(LIBS_HDF5_CMAKE TRUE)
LIST(APPEND SELFBUILTEXTERNALS HDF5)
ENDIF()
# Set HDF5 paths
SET(HDF5_C_INCLUDE_DIR ${LIBS_HDF5_DIR}/include)
SET(HDF5_DIFF_EXECUTABLE ${LIBS_HDF5_DIR}/bin/h5diff)
SET(HDF5_Fortran_INCLUDE_DIR ${LIBS_HDF5_DIR}/include)
SET(HDF5_hdf5_LIBRARY_RELEASE ${LIBS_HDF5_DIR}/lib/libhdf5.a)
SET(HDF5_hdf5_fortran_LIBRARY_RELEASE ${LIBS_HDF5_DIR}/lib/libhdf5_fortran.a)
# Unset leftover paths from old CMake runs
UNSET(HDF5_LIBRARIES)
UNSET(HDF5_INCLUDE_DIR_FORTRAN)
UNSET(HDF5_INCLUDE_DIR)
UNSET(HDF5_DIFF_EXECUTABLE)
# Add HDF5 path to include directories for linking
LIST(APPEND HDF5_INCLUDE_DIR_FORTRAN ${HDF5_Fortran_INCLUDE_DIR} ${HDF5_C_INCLUDE_DIR})
LIST(APPEND HDF5_INCLUDE_DIR ${HDF5_C_INCLUDE_DIR})
MARK_AS_ADVANCED(FORCE HDF5_z_LIBRARY_RELEASE)
# Add ZLIB to include paths for HDF5 data compression
FIND_LIBRARY(HDF5_z_LIBRARY_RELEASE z REQUIRED)
LIST(APPEND HDF5_LIBRARIES ${HDF5_hdf5_fortran_LIBRARY_RELEASE} ${HDF5_hdf5_LIBRARY_RELEASE} ${HDF5_z_LIBRARY_RELEASE} -ldl)
ENDIF()
# Actually add the HDF5 paths (system/custom built) to the linking paths
# HDF5 build with CMake
IF(LIBS_HDF5_CMAKE)
INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR} ${HDF5_INCLUDE_DIR_FORTRAN})
LIST(APPEND linkedlibs ${HDF5_C_${LIB_TYPE}_LIBRARY} ${HDF5_FORTRAN_${LIB_TYPE}_LIBRARY} )
# HDF5 build with configure
ELSE()
INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIR_FORTRAN} ${HDF5_INCLUDE_DIR})
IF(${HDF5_IS_PARALLEL})
MESSAGE(STATUS "Compiling with [HDF5] (v${HDF5_VERSION}) with parallel support")
ELSE()
MESSAGE(STATUS "Compiling with [HDF5] (v${HDF5_VERSION}) without parallel support")
ENDIF()
LIST(APPEND linkedlibs ${HDF5_LIBRARIES} )
ENDIF()
# =========================================================================
# Math libary
# =========================================================================
SET(LIBS_BUILD_MATH_LIB OFF CACHE BOOL "Compile and build math library")
# Check if Intel MKL is requested instead of BLAS/LAPACK
CMAKE_DEPENDENT_OPTION(LIBS_USE_MKL "Use system MKL libraries instead of system BLAS/LAPACK" OFF
"NOT LIBS_BUILD_MATH_LIB" OFF)
# Use system LAPACK/MKL
IF(NOT LIBS_BUILD_MATH_LIB)
IF (LIBS_USE_MKL)
SET(BLA_VENDOR "Intel10_64lp") #search only for Intel BLAS (=MKL)
ENDIF()
# Use Lapack/Blas for GNU
FIND_PACKAGE(LAPACK QUIET)
IF (LAPACK_FOUND)
LIST(APPEND linkedlibs ${LAPACK_LIBRARIES})
MESSAGE(STATUS "Compiling with system [BLAS/Lapack]")
ENDIF()
ELSE()
# Offer LAPACK and OpenBLAS
SET (LIBS_BUILD_MATH_LIB_VENDOR LAPACK CACHE STRING "Choose the type of math lib vendor, options are: LAPACK, OpenBLAS.")
SET_PROPERTY(CACHE LIBS_BUILD_MATH_LIB_VENDOR PROPERTY STRINGS LAPACK OpenBLAS)
# Set parallel build with maximum number of threads
INCLUDE(ProcessorCount)
PROCESSORCOUNT(N)
# Build LAPACK
IF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "LAPACK")
# Origin pointing to Github
IF("${GIT_ORIGIN}" MATCHES ".github.com")
SET (MATHLIB_DOWNLOAD "https://github.com/Reference-LAPACK/lapack.git")
ELSE()
SET (MATHLIB_DOWNLOAD ${LIBS_DLPATH}libs/lapack.git)
ENDIF()
MESSAGE(STATUS "Downloading LAPACK from ${MATHLIB_DOWNLOAD}")
SET (MATH_LIB_DOWNLOAD ${MATHLIB_DOWNLOAD} CACHE STRING "LAPACK Download-link" FORCE)
SET (MATH_LIB_TAG "v3.10.0")
MARK_AS_ADVANCED(FORCE MATH_LIB_DOWNLOAD)
MARK_AS_ADVANCED(FORCE MATH_LIB_TAG)
# Build OpenBLAS
ELSEIF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "OpenBLAS")
IF("${GIT_ORIGIN}" MATCHES ".github.com")
SET (MATHLIB_DOWNLOAD "https://github.com/xianyi/OpenBLAS.git")
ELSE()
SET (MATHLIB_DOWNLOAD ${LIBS_DLPATH}libs/OpenBLAS.git)
ENDIF()
MESSAGE(STATUS "Downloading LAPACK from ${MATHLIB_DOWNLOAD}")
SET (MATH_LIB_DOWNLOAD ${MATHLIB_DOWNLOAD} CACHE STRING "OpenBLAS Download-link" FORCE)
SET (MATH_LIB_TAG "v0.3.17")
MARK_AS_ADVANCED(FORCE MATH_LIB_DOWNLOAD)
MARK_AS_ADVANCED(FORCE MATH_LIB_TAG)
# Unknown math lib vendor
ELSE()
MESSAGE(FATAL_ERROR "Unknown math lib vendor")
ENDIF()
# Set math libs build dir
SET(LIBS_MATH_DIR ${LIBS_EXTERNAL_LIB_DIR}/${LIBS_BUILD_MATH_LIB_VENDOR})
IF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "LAPACK")
# Check if math lib was already built
IF (NOT EXISTS "${LIBS_MATH_DIR}/lib/liblapack.so")
# Let CMake take care of download, configure and build
EXTERNALPROJECT_ADD(${LIBS_BUILD_MATH_LIB_VENDOR}
GIT_REPOSITORY ${MATH_LIB_DOWNLOAD}
GIT_TAG ${MATH_LIB_TAG}
GIT_PROGRESS TRUE
${${GITSHALLOW}}
PREFIX ${LIBS_MATH_DIR}
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=${LIBS_MATH_DIR} -DBLAS++=OFF -DLAPACK++=OFF -DBUILD_SHARED_LIBS=ON -DCBLAS=OFF -DLAPACKE=OFF -DBUILD_TESTING=OFF
BUILD_BYPRODUCTS ${LIBS_MATH_DIR}/lib/liblapack.so ${LIBS_MATH_DIR}/lib/libblas.so
)
LIST(APPEND SELFBUILTEXTERNALS ${LIBS_BUILD_MATH_LIB_VENDOR})
ENDIF()
ELSEIF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "OpenBLAS")
# Check if math lib was already built
IF (NOT EXISTS "${LIBS_MATH_DIR}/libopenblas.so")
# Let CMake take care of download, configure and build
EXTERNALPROJECT_ADD(${LIBS_BUILD_MATH_LIB_VENDOR}
GIT_REPOSITORY ${MATH_LIB_DOWNLOAD}
GIT_TAG ${MATH_LIB_TAG}
GIT_PROGRESS TRUE
${${GITSHALLOW}}
PREFIX ${LIBS_MATH_DIR}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_BYPRODUCTS ${LIBS_MATH_DIR}/src/${LIBS_BUILD_MATH_LIB_VENDOR}/libopenblas.so
BUILD_IN_SOURCE TRUE
INSTALL_COMMAND ""
# Configure explicitly requires GNU make
BUILD_COMMAND make -j${N}
)
LIST(APPEND SELFBUILTEXTERNALS ${LIBS_BUILD_MATH_LIB_VENDOR})
ENDIF()
ENDIF()
IF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "LAPACK")
# Set math lib paths
UNSET(MATH_LIB_LIBRARIES)
SET(MATH_LIB_LIBRARIES ${LIBS_MATH_DIR}/lib)
UNSET(LAPACK_LIBRARY)
UNSET(BLAS_LIBRARY)
UNSET(LAPACK_LIBRARIES)
SET(LAPACK_LIBRARY ${MATH_LIB_LIBRARIES}/liblapack.so)
SET(BLAS_LIBRARY ${MATH_LIB_LIBRARIES}/libblas.so)
SET(LAPACK_LIBRARIES ${LAPACK_LIBRARY}${BLAS_LIBRARY})
# Actually add the math lib paths to the linking paths
INCLUDE_DIRECTORIES (${MATH_LIB_LIBRARIES})
LIST(APPEND linkedlibs ${LAPACK_LIBRARY} ${BLAS_LIBRARY})
MESSAGE(STATUS "Compiling with self-built [LAPACK]")
ELSEIF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "OpenBLAS")
# Set math lib paths
SET(MATH_LIB_LIBRARIES ${LIBS_MATH_DIR}/src/${LIBS_BUILD_MATH_LIB_VENDOR})
UNSET(LAPACK_LIBRARY)
UNSET(LAPACK_LIBRARIES)
SET(LAPACK_LIBRARY ${MATH_LIB_LIBRARIES}/libopenblas.so)
SET(LAPACK_LIBRARIES ${LAPACK_LIBRARY}${BLAS_LIBRARY})
# Actually add the math lib paths to the linking paths
INCLUDE_DIRECTORIES (${MATH_LIB_LIBRARIES})
LIST(APPEND linkedlibs ${LAPACK_LIBRARY} ${BLAS_LIBRARY})
MESSAGE(STATUS "Compiling with self-built [OpenBLAS]")
ENDIF()
ENDIF()
# =========================================================================
# CGNS library
# =========================================================================
OPTION(LIBS_USE_CGNS "Switch for using cgns as a library (needed for input/output of CGNS files)" ON)
IF (NOT LIBS_USE_CGNS)
UNSET(LIBS_BUILD_CGNS CACHE)
UNSET(LIBS_BUILD_CGNS_INT CACHE)
UNSET(LIBS_BUILD_CGNS_TAG CACHE)
ELSE()
ADD_DEFINITIONS(-DPP_USE_CGNS=${HOPR_USE_CGNS})
SET(LIBS_BUILD_CGNS ON CACHE BOOL "Compile and build CGNS library")
SET(LIBS_BUILD_CGNS_INT "32" CACHE STRING "integer type in CGNS lib")
ADD_DEFINITIONS(-DPP_CGNS_INT=${LIBS_BUILD_CGNS_INT})
# Use system CGNS
IF (NOT LIBS_BUILD_CGNS)
FIND_PACKAGE(CGNS)
IF (CGNS_FOUND)
MESSAGE(STATUS "CGNS include dir: " ${CGNS_INCLUDE_DIR})
LIST(INSERT linkedlibs 0 ${CGNS_LIBRARIES})
INCLUDE_DIRECTORIES (${CGNS_INCLUDE_DIR})
# Find "^#define CGNS_VERSION" and get only the numbers and remove trailing line breaks
EXECUTE_PROCESS(COMMAND cat "${CGNS_INCLUDE_DIR}/cgnslib.h" COMMAND grep "^#define CGNS_VERSION" COMMAND grep -o "[[:digit:]]*" COMMAND tr -d '\n' OUTPUT_VARIABLE CGNS_VERSION)
MESSAGE(STATUS "Found CGNS version in cgnslib.h [${CGNS_VERSION}]")
ELSE()
MESSAGE(ERROR "CGNS not found")
ENDIF()
ELSE()
# Set CGNS_Tag
SET (LIBS_BUILD_CGNS_TAG "v4.3.0" CACHE STRING "CGNS version tag from ${CGNSDOWNLOAD}")
SET_PROPERTY(CACHE LIBS_BUILD_CGNS_TAG PROPERTY STRINGS "v3.4.1" "v4.0.0" "v4.3.0")
MESSAGE(STATUS "Compiling CGNS version tag: " ${LIBS_BUILD_CGNS_TAG})
IF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v4.3.0")
SET(CGNS_VERSION 4300)
ELSEIF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v4.0.0")
SET(CGNS_VERSION 4000)
ELSEIF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v3.4.1")
SET(CGNS_VERSION 3401)
ELSE()
SET(CGNS_VERSION -1)
ENDIF()
SET(LIBS_CGNS_DLDIR ${LIBS_EXTERNAL_LIB_DIR}/CGNS${LIBS_BUILD_CGNS_TAG})
SET(LIBS_CGNS_DIR ${LIBS_CGNS_DLDIR})
IF (NOT EXISTS "${LIBS_CGNS_DIR}/lib/libcgns.a")
STRING(COMPARE EQUAL ${LIBS_BUILD_CGNS_INT} "64" LIBS_CGNS_64BIT)
# Origin pointing to Github
IF("${GIT_ORIGIN}" MATCHES ".github.com")
SET (CGNSDOWNLOAD "https://github.com/CGNS/CGNS.git")
ELSE()
SET (CGNSDOWNLOAD ${LIBS_DLPATH}libs/cgns.git )
ENDIF()
MESSAGE(STATUS "Downloading CGNS from ${CGNSDOWNLOAD}")
# Fallback for disabling HDF5 for CGNS compilation
OPTION(LIBS_BUILD_CGNS_ENABLE_HDF5 "Build CGNS library with -DCGNS_ENABLE_HDF5=ON" ON)
MESSAGE(STATUS "Build CGNS library with -DCGNS_ENABLE_HDF5=" ${LIBS_BUILD_CGNS_ENABLE_HDF5})
# Build CGNS with HDF5 support
EXTERNALPROJECT_ADD(cgns
GIT_REPOSITORY ${CGNSDOWNLOAD}
GIT_TAG ${LIBS_BUILD_CGNS_TAG}
GIT_PROGRESS TRUE
${${GITSHALLOW}}
PREFIX ${LIBS_CGNS_DIR}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBS_CGNS_DIR} -DCMAKE_PREFIX_PATH=${LIBS_HDF5_DIR} -DCGNS_ENABLE_FORTRAN=ON -DCGNS_ENABLE_64BIT=${LIBS_CGNS_64BIT} -DCGNS_BUILD_SHARED=ON -DCGNS_USE_SHARED=ON -DCMAKE_BUILD_TYPE=Release -DCGNS_BUILD_CGNSTOOLS=OFF -DCGNS_ENABLE_HDF5=${LIBS_BUILD_CGNS_ENABLE_HDF5} -DCGNS_ENABLE_PARALLEL=OFF -DCGNS_ENABLE_TESTS=OFF -DCMAKE_SKIP_RPATH=ON
BUILD_BYPRODUCTS ${LIBS_CGNS_DIR}/lib/libcgns.a
)
# If HDF5 is built in HOPR, it must occur before the CGNS compilation (for the support of HDF5-based CGNS files)
IF(LIBS_BUILD_HDF5)
IF (NOT EXISTS "${LIBS_HDF5_DIR}/lib/libhdf5.a")
ADD_DEPENDENCIES(cgns HDF5)
ENDIF()
ENDIF()
LIST(APPEND SELFBUILTEXTERNALS cgns)
ENDIF()
LIST(INSERT linkedlibs 0 ${LIBS_CGNS_DIR}/lib/libcgns.a)
INCLUDE_DIRECTORIES( ${LIBS_CGNS_DIR}/include)
MESSAGE(STATUS "Compiling with [CGNS] (${LIBS_BUILD_CGNS_TAG})")
ENDIF()
# set pre-processor flag for CGNS version
ADD_DEFINITIONS(-DPP_CGNS_VERSION=${CGNS_VERSION})
ENDIF()