-
Notifications
You must be signed in to change notification settings - Fork 27
/
CMakeLists.txt
660 lines (547 loc) · 24.3 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
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# =============================================================================
# CADET
#
# Copyright © 2008-present: The CADET-Core Authors
# Please see the AUTHORS.md file.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Public License v3.0 (or, at
# your option, any later version) which accompanies this distribution, and
# is available at http://www.gnu.org/licenses/gpl.html
# =============================================================================
# Require a fairly new cmake version
cmake_minimum_required(VERSION 3.12)
# Prohibit in-source build
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source build prohibited.")
endif()
# Set module path in order to use custom CMake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
find_package(Git)
# Write the current version number to variable
if (GIT_FOUND)
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CADET_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT "${CADET_VERSION}" STREQUAL "")
message(STATUS "Get version from git")
# Remove first character ("v")
string(LENGTH "${CADET_VERSION}" CADET_VERSION_STRLEN)
math(EXPR CADET_VERSION_STRLEN "${CADET_VERSION_STRLEN}-1")
string(SUBSTRING "${CADET_VERSION}" 1 ${CADET_VERSION_STRLEN} CADET_VERSION)
endif()
endif()
endif()
# In case of missing tags, default to versions.txt file
if ("${CADET_VERSION}" STREQUAL "")
message(STATUS "Get version from file")
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" CADET_VERSION)
endif()
message(STATUS "CADET version: ${CADET_VERSION}")
# Get current commit hash from git
if (GIT_FOUND)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
endif()
if (NOT DEFINED GIT_SHA1)
set(GIT_SHA1 "NO-COMMIT-HASH")
set(GIT_REFSPEC "NO-REFSPEC")
endif()
message(STATUS "Current git HEAD: ${GIT_REFSPEC} SHA1 ${GIT_SHA1}")
# Name of the current project
project(CadetFramework
VERSION ${CADET_VERSION}
DESCRIPTION "Liquid column chromatography simulator"
HOMEPAGE_URL "https://github.com/cadet/cadet-core"
LANGUAGES CXX C)
# Always use '-fPIC'/'-fPIE' option
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Hide symbols by default
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# Enable folders for IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# ---------------------------------------------------
# Other configuration options
# ---------------------------------------------------
# Option that allows users to build release or debug version
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE} (default)")
endif()
# Default IPO setting: OFF for Debug, ON for all other build types
set(DEFAULT_IPO_ENABLED ON)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_IPO_ENABLED OFF)
endif()
include(FeatureSummary)
option(ENABLE_LOGGING "Enables logging" ON)
add_feature_info(ENABLE_LOGGING ENABLE_LOGGING "Enables logging")
option(ENABLE_BENCHMARK "Enables benchmark mode (fine-grained timing)" OFF)
add_feature_info(ENABLE_BENCHMARK ENABLE_BENCHMARK "Enables benchmark mode (fine-grained timing)")
option(ENABLE_PLATFORM_TIMER "Use a platform-dependent timer" OFF)
add_feature_info(ENABLE_PLATFORM_TIMER ENABLE_PLATFORM_TIMER "Use a platform-dependent timer")
option(ENABLE_THREADING "Use multi-threading" OFF)
add_feature_info(ENABLE_THREADING ENABLE_THREADING "Use multi-threading")
option(ENABLE_DEBUG_THREADING "Use multi-threading in debug builds" OFF)
add_feature_info(ENABLE_DEBUG_THREADING ENABLE_DEBUG_THREADING "Use multi-threading in debug builds")
option(ENABLE_2D_MODELS "Build 2D models (e.g., 2D general rate model, multichannel transport)" ON)
add_feature_info(ENABLE_2D_MODELS ENABLE_2D_MODELS "Build 2D models (e.g., 2D general rate model, multichannel transport)")
option(ENABLE_DG "Build DG variants of models" ON)
add_feature_info(ENABLE_DG ENABLE_DG "Build DG variants of models")
option(ENABLE_SUNDIALS_OPENMP "Prefer OpenMP vector implementation of SUNDIALS if available (for large problems)" OFF)
add_feature_info(ENABLE_SUNDIALS_OPENMP ENABLE_SUNDIALS_OPENMP "Prefer OpenMP vector implementation of SUNDIALS if available (for large problems)")
option(ENABLE_ANALYTIC_JACOBIAN_CHECK "Enable verification of analytical Jacobian by AD" OFF)
add_feature_info(ENABLE_ANALYTIC_JACOBIAN_CHECK ENABLE_ANALYTIC_JACOBIAN_CHECK "Enable verification of analytical Jacobian by AD")
set(ADLIB "sfad" CACHE STRING "Selects the AD library, options are 'sfad', 'setfad'")
string(TOLOWER ${ADLIB} ADLIB)
set(NUM_MAX_AD_DIRS 80 CACHE STRING "Sets the maximum number of AutoDiff directions")
option(ENABLE_CADET_CLI "Build CADET command line interface" ON)
add_feature_info(ENABLE_CADET_CLI ENABLE_CADET_CLI "Build CADET command line interface")
option(ENABLE_CADET_TOOLS "Build CADET tools" ON)
add_feature_info(ENABLE_CADET_TOOLS ENABLE_CADET_TOOLS "Build CADET tools")
option(ENABLE_TESTS "Build CADET tests" OFF)
add_feature_info(ENABLE_TESTS ENABLE_TESTS "Build CADET tests")
option(ENABLE_PACKAGED_SUNDIALS "Use packaged SUNDIALS code" ON)
add_feature_info(ENABLE_PACKAGED_SUNDIALS ENABLE_PACKAGED_SUNDIALS "Use packaged SUNDIALS code")
option(ENABLE_IPO "Enable interprocedural optimization if compiler supports it" ${DEFAULT_IPO_ENABLED})
add_feature_info(ENABLE_IPO ENABLE_IPO "Enable interprocedural optimization if compiler supports it")
option(ENABLE_ASAN "Enable address sanitizer (clang and gcc)" OFF)
add_feature_info(ENABLE_ASAN ENABLE_ASAN "Enable address sanitizer (clang and gcc)")
option(ENABLE_UBSAN "Enable undefined behavior sanitizer (clang and gcc)" OFF)
add_feature_info(ENABLE_UBSAN ENABLE_UBSAN "Enable undefined behavior sanitizer (clang and gcc)")
option(ENABLE_STATIC_LINK_DEPS "Prefer static over dynamic linking of dependencies" OFF)
add_feature_info(ENABLE_STATIC_LINK_DEPS ENABLE_STATIC_LINK_DEPS "Prefer static over dynamic linking of dependencies")
option(ENABLE_STATIC_LINK_LAPACK "Prefer static over dynamic linking of LAPACK and BLAS" OFF)
add_feature_info(ENABLE_STATIC_LINK_LAPACK ENABLE_STATIC_LINK_LAPACK "Prefer static over dynamic linking of LAPACK and BLAS")
option(ENABLE_STATIC_LINK_CLI "Prefer static over dynamic linking for CADET CLI" OFF)
add_feature_info(ENABLE_STATIC_LINK_CLI ENABLE_STATIC_LINK_CLI "Prefer static over dynamic linking for CADET CLI")
option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add paths to linker search and installed rpath" ON)
add_feature_info(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add paths to linker search and installed rpath")
# Hande RPATH on OSX when not installing to a system directory, see
# https://groups.google.com/d/msg/fenics-dev/KSCrob4M_1M/zsJwdN-SCAAJ
# and https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH
if (UNIX)
# The RPATH to be used when installing, but only if it's not a system directory
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if ("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
endif()
# ---------------------------------------------------
# Check build environment
# ---------------------------------------------------
include(WriteCompilerDetectionHeader)
set(TBB_TARGET "")
if (ENABLE_THREADING)
set(TBB_PREFER_STATIC_LIBS ${ENABLE_STATIC_LINK_DEPS})
set(TBB_USE_DEBUG_BUILD OFF)
find_package(TBB COMPONENTS tbb OPTIONAL_COMPONENTS tbb_preview)
set_package_properties(TBB PROPERTIES
TYPE RECOMMENDED
PURPOSE "Accelerates computation via multi-threading"
)
set(CADET_PARALLEL_FLAG "")
if (TBB_FOUND)
# Use tbb_preview instead of tbb if it has been found
if (TBB_tbb_preview_FOUND)
set(TBB_TARGET "TBB::TBBpreview")
else()
set(TBB_TARGET "TBB::TBB")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (ENABLE_DEBUG_THREADING)
set(CADET_PARALLEL_FLAG "CADET_PARALLELIZE")
endif()
else()
set(CADET_PARALLEL_FLAG "CADET_PARALLELIZE")
endif()
get_target_property(TBB_IFACE_COMP_DEF ${TBB_TARGET} INTERFACE_COMPILE_DEFINITIONS)
if (TBB_IFACE_COMP_DEF)
list(APPEND TBB_IFACE_COMP_DEF ${CADET_PARALLEL_FLAG})
else()
set(TBB_IFACE_COMP_DEF ${CADET_PARALLEL_FLAG})
endif()
if (TBB_IFACE_COMP_DEF)
set_target_properties(${TBB_TARGET} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${TBB_IFACE_COMP_DEF}")
endif()
unset(TBB_IFACE_COMP_DEF)
if (TBB_INTERFACE_VERSION GREATER_EQUAL 11004)
# Use global_control instead of task_scheduler_init
get_target_property(TBB_IFACE_COMP_DEF ${TBB_TARGET} INTERFACE_COMPILE_DEFINITIONS)
set_target_properties(${TBB_TARGET} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${TBB_IFACE_COMP_DEF}")
if (TBB_IFACE_COMP_DEF)
list(APPEND TBB_IFACE_COMP_DEF "CADET_TBB_GLOBALCTRL")
else()
set(TBB_IFACE_COMP_DEF "CADET_TBB_GLOBALCTRL")
endif()
if (TBB_IFACE_COMP_DEF)
set_target_properties(${TBB_TARGET} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${TBB_IFACE_COMP_DEF}")
endif()
unset(TBB_IFACE_COMP_DEF)
endif()
endif()
endif()
set(BLA_STATIC ${ENABLE_STATIC_LINK_LAPACK})
find_package(LAPACK)
set_package_properties(LAPACK PROPERTIES
TYPE RECOMMENDED
PURPOSE "Solution of dense linear systems"
)
if (NOT ENABLE_PACKAGED_SUNDIALS)
# SUNDIALS_ROOT environment variable can be used to find SUNDIALS package
set(SUNDIALS_PREFER_STATIC_LIBRARIES ${ENABLE_STATIC_LINK_DEPS})
find_package(SUNDIALS REQUIRED COMPONENTS sundials_idas sundials_nvecserial OPTIONAL_COMPONENTS sundials_nvecopenmp)
set_package_properties(SUNDIALS PROPERTIES
TYPE REQUIRED
PURPOSE "Time integration"
)
# Check whether OpenMP is available in SUNDIAL'S NVECTOR module
set(SUNDIALS_NVEC_TARGET "SUNDIALS::sundials_nvecserial")
if (SUNDIALS_sundials_nvecopenmp_LIBRARY AND ENABLE_SUNDIALS_OPENMP)
# Prefer OpenMP over serial version
set(SUNDIALS_NVEC_TARGET "SUNDIALS::sundials_nvecopenmp")
get_target_property(SUNDIALS_IFACE_COMP_DEF SUNDIALS::sundials_nvecopenmp INTERFACE_COMPILE_DEFINITIONS)
if (SUNDIALS_IFACE_COMP_DEF)
list(APPEND SUNDIALS_IFACE_COMP_DEF "CADET_SUNDIALS_OPENMP")
else()
set(SUNDIALS_IFACE_COMP_DEF "CADET_SUNDIALS_OPENMP")
endif()
set_target_properties(SUNDIALS::sundials_nvecopenmp PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${SUNDIALS_IFACE_COMP_DEF}")
unset(SUNDIALS_IFACE_COMP_DEF)
endif()
# Determine SUNDIALS interface version
if (SUNDIALS_FOUND)
get_target_property(SUNDIALS_IFACE_COMP_DEF SUNDIALS::sundials_idas INTERFACE_COMPILE_DEFINITIONS)
if (SUNDIALS_IFACE_COMP_DEF)
list(APPEND SUNDIALS_IFACE_COMP_DEF "CADET_SUNDIALS_IFACE=${SUNDIALS_VERSION_MAJOR}")
else()
set(SUNDIALS_IFACE_COMP_DEF "CADET_SUNDIALS_IFACE=${SUNDIALS_VERSION_MAJOR}")
endif()
set_target_properties(SUNDIALS::sundials_idas PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${SUNDIALS_IFACE_COMP_DEF}")
unset(SUNDIALS_IFACE_COMP_DEF)
endif()
else()
set(SUNDIALS_FOUND TRUE)
set(SUNDIALS_VERSION "3.2.1")
set(SUNDIALS_NVEC_TARGET "SUNDIALS::sundials_nvecserial")
add_subdirectory(ThirdParty/sundials)
add_library(SUNDIALS::sundials_idas INTERFACE IMPORTED)
target_link_libraries(SUNDIALS::sundials_idas INTERFACE sundials_idas_static)
target_include_directories(SUNDIALS::sundials_idas INTERFACE ThirdParty/sundials/include ThirdParty/sundials/src "${CMAKE_BINARY_DIR}/ThirdParty/sundials/include")
set_target_properties(SUNDIALS::sundials_idas PROPERTIES INTERFACE_COMPILE_DEFINITIONS "CADET_SUNDIALS_IFACE=3")
add_library(SUNDIALS::sundials_nvecserial INTERFACE IMPORTED)
target_include_directories(SUNDIALS::sundials_nvecserial INTERFACE ThirdParty/sundials/include "${CMAKE_BINARY_DIR}/ThirdParty/sundials/include")
target_link_libraries(SUNDIALS::sundials_nvecserial INTERFACE sundials_nvecserial_static)
endif()
if (ENABLE_CADET_TOOLS OR ENABLE_CADET_CLI)
set(HDF5_USE_STATIC_LIBRARIES ${ENABLE_STATIC_LINK_DEPS})
find_package(HDF5 COMPONENTS C)
set_package_properties(HDF5 PROPERTIES
DESCRIPTION "Hierarchical Data Format 5 (HDF5)"
URL "https://www.hdfgroup.org/HDF5"
TYPE RECOMMENDED
PURPOSE "File IO"
)
if (HDF5_FOUND)
# Create custom HDF5 target if CMake's FindHDF5 is too old
if (NOT TARGET HDF5::HDF5)
list(LENGTH HDF5_C_LIBRARIES HDF5_C_LEN)
if (HDF5_C_LEN GREATER 1)
list(GET HDF5_C_LIBRARIES 0 HDF5_MAIN_LIBRARY)
set(HDF5_SUPPORT_LIBRARIES ${HDF5_C_LIBRARIES})
list(REMOVE_AT HDF5_SUPPORT_LIBRARIES 0)
else()
set(HDF5_MAIN_LIBRARY ${HDF5_C_LIBRARIES})
set(HDF5_SUPPORT_LIBRARIES)
endif()
add_library(HDF5::HDF5 UNKNOWN IMPORTED)
set_target_properties(HDF5::HDF5 PROPERTIES
IMPORTED_LOCATION ${HDF5_MAIN_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_C_INCLUDE_DIRS}"
# INTERFACE_COMPILE_DEFINITIONS ${HDF5_C_DEFINITIONS}
)
if (HDF5_SUPPORT_LIBRARIES)
target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_SUPPORT_LIBRARIES})
endif()
unset(HDF5_SUPPORT_LIBRARIES)
unset(HDF5_MAIN_LIBRARY)
unset(HDF5_C_LEN)
endif()
# Make sure HDF5_LIBRARY_DIRS is defined
if ((NOT DEFINED HDF5_LIBRARY_DIRS) OR (NOT HDF5_LIBRARY_DIRS) OR ("${HDF5_LIBRARY_DIRS}" STREQUAL ""))
list(GET HDF5_LIBRARIES 0 HDF5_LIB_TEMP)
get_filename_component(HDF5_LIBRARY_DIRS ${HDF5_LIB_TEMP} DIRECTORY)
unset(HDF5_LIB_TEMP)
endif()
# Check if we need additional libraries for linking (i.e., zlib, szip)
include(${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
include(${CMAKE_ROOT}/Modules/CMakePushCheckState.cmake)
cmake_push_check_state(RESET)
# Set libs and includes
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS})
CHECK_CXX_SOURCE_COMPILES("#include <hdf5.h>\nint main(int argc, char** argv){\n H5Zfilter_avail(H5Z_FILTER_SZIP);\nH5Zfilter_avail(H5Z_FILTER_DEFLATE);\nreturn 0;\n}\n" HDF5_DONT_NEED_ZLIBS)
# Reset libs and includes
cmake_pop_check_state()
# Find szip and zlib libs if we need them
if (NOT HDF5_DONT_NEED_ZLIBS)
# Prefer static libs if enabled
set(_HDF5_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(ENABLE_STATIC_LINK_DEPS)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
endif()
find_library(HDF5_SZLIB NAMES libszip szip PATHS ${HDF5_LIBRARY_DIRS})
find_library(HDF5_ZLIB NAMES libzlib zlib PATHS ${HDF5_LIBRARY_DIRS})
if (HDF5_SZLIB)
list(APPEND HDF5_LIBRARIES ${HDF5_SZLIB})
add_library(HDF5::SZLIB UNKNOWN IMPORTED)
set_target_properties(HDF5::SZLIB PROPERTIES IMPORTED_LOCATION ${HDF5_SZLIB})
target_link_libraries(HDF5::HDF5 INTERFACE HDF5::SZLIB)
endif()
if (HDF5_ZLIB)
list(APPEND HDF5_LIBRARIES ${HDF5_ZLIB})
add_library(HDF5::ZLIB UNKNOWN IMPORTED)
set_target_properties(HDF5::ZLIB PROPERTIES IMPORTED_LOCATION ${HDF5_ZLIB})
target_link_libraries(HDF5::HDF5 INTERFACE HDF5::ZLIB)
endif()
unset(HDF5_SZLIB)
unset(HDF5_ZLIB)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_HDF5_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(_HDF5_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
endif()
endif()
if (ENABLE_2D_MODELS)
set(SUPERLU_PREFER_STATIC_LIBS ${ENABLE_STATIC_LINK_DEPS})
find_package(SuperLU)
set_package_properties(SuperLU PROPERTIES
TYPE RECOMMENDED
PURPOSE "Sparse matrix solver"
)
set(UMFPACK_PREFER_STATIC_LIBS ${ENABLE_STATIC_LINK_DEPS})
find_package(UMFPACK)
set_package_properties(UMFPACK PROPERTIES
TYPE RECOMMENDED
PURPOSE "Sparse matrix solver"
)
endif()
set(EIGEN_TARGET "")
if (ENABLE_DG)
find_package(Eigen3 3.4 REQUIRED NO_MODULE)
# Disable DG if Eigen is not present
if (NOT TARGET Eigen3::Eigen)
message(STATUS "Disabling DG support because Eigen3 could not be found")
set(ENABLE_DG OFF)
else()
set(EIGEN_TARGET "Eigen3::Eigen")
endif()
endif()
set(IPO_AVAILABLE OFF)
if (ENABLE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_RESULT OUTPUT IPO_OUT LANGUAGES CXX)
if (IPO_RESULT)
set(IPO_AVAILABLE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(WARNING "IPO is not supported: ${IPO_OUT}")
endif()
unset(IPO_RESULT)
unset(IPO_OUT)
endif()
# ---------------------------------------------------
# Add selected modules to the build system and add the targets to the list of all targets
# ---------------------------------------------------
add_library(CADET::CompileOptions INTERFACE IMPORTED)
target_compile_features(CADET::CompileOptions INTERFACE cxx_std_23)
set(CMAKE_CXX_EXTENSIONS OFF)
if (WIN32)
target_compile_definitions(CADET::CompileOptions INTERFACE NOMINMAX)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(CADET::CompileOptions INTERFACE CADET_LOGLEVEL_MIN=Trace DEBUG _DEBUG)
else()
target_compile_definitions(CADET::CompileOptions INTERFACE CADET_LOGLEVEL_MIN=Warning NDEBUG)
endif()
if (ENABLE_BENCHMARK)
target_compile_definitions(CADET::CompileOptions INTERFACE CADET_BENCHMARK_MODE)
endif()
if (ENABLE_PLATFORM_TIMER)
target_compile_definitions(CADET::CompileOptions INTERFACE CADET_USE_PLATFORM_TIMER)
if ((NOT APPLE) AND (NOT WIN32))
target_link_libraries(CADET::CompileOptions INTERFACE rt)
endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -pedantic-errors -Wextra -Wno-unused-parameter -Wno-unused-function> #-Wconversion -Wsign-conversion
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /wd4100 /bigobj /MP>
)
else()
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -pedantic-errors -Wextra -Wno-unused-parameter -Wno-unused-function> #-Wconversion -Wsign-conversion
$<$<CXX_COMPILER_ID:MSVC>:
/W4 /wd4100 /MP>
)
endif()
if (ENABLE_ASAN)
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-fsanitize=address>)
target_link_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-fsanitize=address>)
endif()
if (ENABLE_UBSAN)
target_compile_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-fsanitize=undefined>)
target_link_options(CADET::CompileOptions INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-fsanitize=undefined>)
endif()
add_library(CADET::AD INTERFACE IMPORTED)
if (ADLIB STREQUAL "sfad")
message(STATUS "AD library: SFAD")
target_compile_definitions(CADET::AD INTERFACE ACTIVE_SFAD)
target_include_directories(CADET::AD INTERFACE "${CMAKE_SOURCE_DIR}/include/ad")
elseif (ADLIB STREQUAL "setfad")
message(STATUS "AD library: SETFAD")
target_compile_definitions(CADET::AD INTERFACE ACTIVE_SETFAD)
target_include_directories(CADET::AD INTERFACE "${CMAKE_SOURCE_DIR}/include/ad")
else()
message(FATAL_ERROR "Unkown AD library ${ADLIB} (options are 'sfad', 'setfad')")
endif()
# Build tools
add_subdirectory(src/build-tools)
# CADET library
add_subdirectory(src/libcadet)
if (ENABLE_CADET_CLI)
add_subdirectory(src/cadet-cli)
endif()
if (ENABLE_CADET_TOOLS)
add_subdirectory(src/tools)
endif()
if (ENABLE_TESTS)
add_subdirectory(test)
# Add "make check" target
include(ProcessorCount)
ProcessorCount(NPROC)
add_custom_target(check COMMAND test/testRunner -d yes --tbbthreads ${NPROC})
endif()
# ---------------------------------------------------
# Set properties, definitions, install target etc.
# ---------------------------------------------------
# Packaging support
include(CPack)
set(CPACK_PACKAGE_VENDOR "CADET")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_STRIP_FILES ON)
# Combine LICENSE.txt and ThirdParty-LICENSES.txt
file(WRITE "${CMAKE_BINARY_DIR}/LICENSE.txt" "####################################################################################\n")
file(APPEND "${CMAKE_BINARY_DIR}/LICENSE.txt" "## CADET ##\n")
file(APPEND "${CMAKE_BINARY_DIR}/LICENSE.txt" "####################################################################################\n")
file(READ "${CMAKE_SOURCE_DIR}/LICENSE.txt" LICENSE_TEXT)
file(APPEND "${CMAKE_BINARY_DIR}/LICENSE.txt" "\n${LICENSE_TEXT}")
file(READ "${CMAKE_SOURCE_DIR}/ThirdParty-LICENSES.txt" LICENSE_THIRDPARTY)
file(APPEND "${CMAKE_BINARY_DIR}/LICENSE.txt" "\n\n${LICENSE_THIRDPARTY}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_IGNORE_FILES
/.git
/\\\\.DS_Store
)
message("")
message("--------------------------- Feature Summary ---------------------------")
feature_summary(WHAT ALL)
# Summary
message("")
message("------------------------------- Summary -------------------------------")
message("C++ compiler name: ${CMAKE_CXX_COMPILER_ID} at ${CMAKE_CXX_COMPILER}")
message("Build type: ${CMAKE_BUILD_TYPE}")
message("Source dir: ${CMAKE_SOURCE_DIR}")
message("Binary dir: ${CMAKE_BINARY_DIR}")
message("Install dir: ${CMAKE_INSTALL_PREFIX}")
message("C Flags: ${CMAKE_C_FLAGS}")
message("C++ Flags: ${CMAKE_CXX_FLAGS}")
message("IPO enabled: ${IPO_AVAILABLE}")
message("------------------------------- Modules -------------------------------")
message("CADET-CLI: ${ENABLE_CADET_CLI}")
message("Tools: ${ENABLE_CADET_TOOLS}")
message("Tests: ${ENABLE_TESTS}")
message("------------------------------- Options -------------------------------")
message("Logging: ${ENABLE_LOGGING}")
message("Benchmark mode: ${ENABLE_BENCHMARK}")
message("Platform-dependent timer: ${ENABLE_PLATFORM_TIMER}")
message("AD library: ${ADLIB}")
message("2D Models: ${ENABLE_2D_MODELS}")
message("Check analytic Jacobian: ${ENABLE_ANALYTIC_JACOBIAN_CHECK}")
message("----------------------------- Dependencies ----------------------------")
message("Found BLAS: ${BLAS_FOUND}")
if (BLAS_FOUND)
message(" Linker flags ${BLAS_LINKER_FLAGS}")
message(" Libs ${BLAS_LIBRARIES}")
message(" Underscore suffix ${BLAS_UNDERSCORE_SUFFIX}")
endif()
message("Found LAPACK: ${LAPACK_FOUND}")
if (LAPACK_FOUND)
message(" Linker flags ${LAPACK_LINKER_FLAGS}")
message(" Libs ${LAPACK_LIBRARIES}")
endif()
message("Found TBB: ${TBB_FOUND}")
if (TBB_FOUND)
message(" Version ${TBB_VERSION} (Interface ${TBB_INTERFACE_VERSION})")
message(" Include ${TBB_INCLUDE_DIRS}")
message(" Definitions ${TBB_DEFINITIONS}")
message(" Libs ${TBB_LIBRARIES}")
endif()
if (ENABLE_PACKAGED_SUNDIALS)
message("Found SUNDIALS: ${SUNDIALS_FOUND}")
message(" Version ${SUNDIALS_VERSION}")
message(" Packaged")
else()
message("Found SUNDIALS: ${SUNDIALS_FOUND}")
if (SUNDIALS_FOUND)
message(" Version ${SUNDIALS_VERSION}")
message(" Includes ${SUNDIALS_INCLUDE_DIRS}")
message(" Libs ${SUNDIALS_LIBRARIES}")
endif()
endif()
if (ENABLE_2D_MODELS)
message("Found SuperLU: ${SUPERLU_FOUND}")
if (SUPERLU_FOUND)
message(" Version ${SUPERLU_VERSION}")
message(" Includes ${SUPERLU_INCLUDE_DIRS}")
message(" Libs ${SUPERLU_LIBRARIES}")
message(" Integer type ${SUPERLU_INT_TYPE}")
endif()
message("Found UMFPACK: ${UMFPACK_FOUND}")
if (UMFPACK_FOUND)
message(" Version ${UMFPACK_VERSION}")
message(" Includes ${UMFPACK_INCLUDE_DIRS}")
message(" Libs ${UMFPACK_LIBRARIES}")
endif()
endif()
if (ENABLE_DG)
message("Found Eigen3: ${Eigen3_FOUND}")
if (TARGET Eigen3::Eigen)
message(" Version ${Eigen3_VERSION}")
message(" Includes ${Eigen3_INCLUDE_DIRS}")
endif()
endif()
message("Found HDF5: ${HDF5_FOUND}")
if (HDF5_FOUND)
message(" Version ${HDF5_VERSION}")
message(" Includes ${HDF5_INCLUDE_DIRS}")
message(" Libs ${HDF5_LIBRARIES}")
message(" Defs ${HDF5_C_DEFINITIONS}")
endif()
message("-----------------------------------------------------------------------")
message("")