forked from PRBEM/VERB-4D
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
206 lines (179 loc) · 7.05 KB
/
Copy pathCMakeLists.txt
File metadata and controls
206 lines (179 loc) · 7.05 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
# SPDX-FileCopyrightText: 2015 UCLA
# SPDX-FileCopyrightText: 2025 Bernhard Haas (GFZ)
#
# SPDX-License-Identifier: BSD-3-Clause
# CMakeLists.txt
# Buildsystem for VERB4D - See README.md for build instructions
#
# Author: Anthony Miyaguchi (acmiyaguchi@gmail.com)
cmake_minimum_required(VERSION 3.9)
project(VERB4D C CXX)
set(CMAKE_CXX_STANDARD 17)
# Enable/disable data assimilation
set(DATA_ASSIMILATION FALSE CACHE BOOL "Enable data assimilation")
# Math Constants are not defined in Standard C++. To use them, we must first define _USE_MATH_DEFINES
add_compile_definitions(_USE_MATH_DEFINES)
# Recursively search for header files to include for project files. This isn't
# necessary to compile, but its nice to have in Visual Studio solutions.
file(GLOB_RECURSE VERB4D_HEADERS *.h)
# Add new source files here and re-run cmake
set(VERB4D_SOURCES
src/VERB4D_Solver.cpp
src/Convection_1D_ULTIMATE_QUICKEST6.cpp
src/Convection_1D_2ndORDER_NONUNIFORM_GRID.cpp
src/Convection_2D.cpp
src/Convection_3D.cpp
src/Diffusion_1D.cpp
src/Diffusion_2D.cpp
src/Diffusion_2D_MKL.cpp
src/Diffusion_ADI1.cpp
src/Diffusion_ADI2.cpp
src/Diffusion_ADI3.cpp
src/Interpolation.cpp
src/Logger.cpp
src/Matrix.cpp
src/MatrixSolver.cpp
src/MonotCubicInterpolator.cpp
src/Parameters.cpp
src/ReadInitialData.cpp
src/UpdatableMatrix.cpp)
# Add data assimilation source files and macros
if(DATA_ASSIMILATION)
add_definitions(-DDATA_ASSIMILATION)
set(VERB4D_SOURCES
${VERB4D_SOURCES}
src/MatrixOperations.cpp
src/CustomDate.cpp
src/DataAssimilationHelper.cpp
src/DataAssimilation.cpp)
if(MATLAB_FOUND)
set(VERB4D_SOURCES
${VERB4D_SOURCES}
src/PMF.cpp)
endif(MATLAB_FOUND)
if(DATA_ASSIMILATION_DEBUG)
message("Saving DA debug output!")
add_definitions(-DDATA_ASSIMILATION_DEBUG)
endif(DATA_ASSIMILATION_DEBUG)
endif(DATA_ASSIMILATION)
# Build and link
add_executable(VERB4D_Solver ${VERB4D_SOURCES} ${VERB4D_HEADERS})
# Apply different compiler options based on the compiler
if(MSVC)
# For MSVC, use /W4 for warnings and /WX to treat warnings as errors.
# /wd4804 - T should not be bool in some cases. TODO: solve later
# /wd4996 'fpclassify': ambiguous call to overloaded function [C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt/corecrt_math.h"]
# /wd4849 OpenMP 'collapse' clause ignored in 'parallel for' directive
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /permissive /wd4804 /wd4996 /wd4849")
else()
# For GCC/Clang, use -Wall -Wextra -Wpedantic (-Werror removed)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
# Add directories for include files
target_include_directories(VERB4D_Solver PUBLIC ${PROJECT_SOURCE_DIR}/src)
# Check if interprocedural optimization (link time optimization) is supported by the compiler
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if(NOT DEFINED BLAS_TYPE)
message("No BLAS_TYPE specified, choosing LAPACK")
set(BLAS_TYPE LAPACK)
endif()
string(TOUPPER ${BLAS_TYPE} BLAS_TYPE)
if(${BLAS_TYPE} STREQUAL "LAPACK")
if(WIN32)
# The libraries for lapack and BLAS for windows are in the lib folder
set(LAPACK_LIBRARIES ${CMAKE_SOURCE_DIR}/lib/clapack.lib)
set(BLAS_LIBRARIES ${CMAKE_SOURCE_DIR}/lib/blas.lib)
set(F2C_LIBRARIES ${CMAKE_SOURCE_DIR}/lib/libf2c.lib)
list(APPEND DEPLIBS ${F2C_LIBRARIES})
else(WIN32)
# Installed by distribution's package manager
find_package(LAPACK REQUIRED)
endif(WIN32)
list(APPEND DEPLIBS ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
elseif(${BLAS_TYPE} STREQUAL "OPENBLAS")
add_library(openblas SHARED IMPORTED)
if(WIN32)
if(NOT DEFINED OPENBLAS_LIBPATH)
set(OPENBLAS_LIBPATH $ENV{HOMEPATH}/AppData/Local/OpenBLAS/openblas.lib)
message("No OPENBLAS_LIBPATH specified, choosing ${OPENBLAS_LIBPATH}")
endif()
set_target_properties(openblas PROPERTIES IMPORTED_IMPLIB ${OPENBLAS_LIBPATH})
else()
if(NOT DEFINED OPENBLAS_LIBPATH)
set(OPENBLAS_LIBPATH $ENV{HOME}/.local/lib/libopenblas.so)
message("No OPENBLAS_LIBPATH specified, choosing ${OPENBLAS_LIBPATH}")
endif()
set_target_properties(openblas PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIBPATH})
endif()
list(APPEND DEPLIBS openblas)
elseif(${BLAS_TYPE} STREQUAL "MKL")
set(MKL_THREADING sequential)
set(MKL_INTERFACE lp64)
find_package(MKL CONFIG REQUIRED)
list(APPEND DEPLIBS ${MKL_IMPORTED_TARGETS})
target_include_directories(VERB4D_Solver PUBLIC ${MKL_INCLUDE})
add_definitions(-DMKL_FOUND)
else()
message( FATAL_ERROR "Unknown BLAS_TYPE. Choose either LAPACK, OPENBLAS or MKL" )
endif()
# Find OpenMP
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
# Find Matlab
find_package(Matlab COMPONENTS ENG_LIBRARY MAT_LIBRARY)
if(Matlab_FOUND)
include_directories(${Matlab_INCLUDE_DIRS})
list(APPEND DEPLIBS
${Matlab_MAT_LIBRARY}
${Matlab_MX_LIBRARY}
${Matlab_ENG_LIBRARY})
# Set the definition for MATLAB_CAPABLE
add_definitions(-DMATLAB_CAPABLE=true)
endif()
# use interprocidural optimization if supported
if( ipo_supported )
message(STATUS "IPO enabled")
set_property(TARGET VERB4D_Solver PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO not supported: <${ipo_error}>")
endif()
target_link_libraries(VERB4D_Solver ${DEPLIBS})
# Flag compile type feedback
if(DEFINED CMAKE_BUILD_TYPE)
if(CMAKE_BUILD_TYPE STREQUAL "")
message(WARNING "\nCMAKE_BUILD_TPYE not specified. Run cmake with -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug")
else(CMAKE_BUILD_TYPE STREQUAL "")
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_upper)
if(CMAKE_BUILD_TYPE_upper STREQUAL "RELEASE")
add_definitions(-DRELEASE)
endif()
endif()
endif()
# Flag to decide convection step size in Convection_2D.cpp
if(${FAST_CONVECTION})
add_definitions(-DFAST_CONVECTION)
endif()
unset(FAST_CONVECTION CACHE)
# Python bindings
if (${PYTHON_BINDINGS})
include_directories(${PROJECT_SOURCE_DIR}/extern/pybind11/include ${PROJECT_SOURCE_DIR}/src/python_bindings ${PROJECT_SOURCE_DIR}/src)
add_subdirectory(extern/pybind11)
pybind11_add_module(verb4d_solver src/python_bindings/Define_python_modules.cpp ${VERB4D_SOURCES})
target_link_libraries(verb4d_solver PUBLIC ${DEPLIBS})
endif()
unset(PYTHON_BINDINGS CACHE)
# save lost PSD during Convection_2D
if(${SAVE_PSD_LOST_CONV})
add_definitions(-DSAVE_PSD_LOST_CONV)
endif()
unset(SAVE_PSD_LOST CACHE)
# cache LU decomposition during Lapack call in Diffusion_2D.cpp
if(${LU_CACHING})
add_definitions(-DLU_CACHING)
endif()
unset(SAVE_PSD_LOST CACHE)