-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmeson.build
More file actions
244 lines (209 loc) · 8.51 KB
/
Copy pathmeson.build
File metadata and controls
244 lines (209 loc) · 8.51 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
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
bits = get_option('realbits')
real_bits = '-DREALBITS=' + bits
arith = get_option('arith')
nomalloc_env = environment({'MALLOC_PERTURB_': '0'})
# === get compiler and OS
fc = meson.get_compiler('fortran')
os = host_machine.system()
# === compiler options
oldflags = fc.get_supported_arguments(['-std=legacy', '-w', '-fno-implicit-none', '-Wno-error=array-bounds', '-fcheck=no-all',
'-nocheck', '/nocheck', '-nowarn', '/nowarn', '-nostand', '/nowarn'])
std18 = fc.first_supported_argument(['-std=f2018', '-stand=f18', '/stand:f18'])
if fc.get_id() == 'gcc'
add_project_arguments('-Wno-unused-variable', '-Wno-maybe-uninitialized', '-Wno-unused-dummy-argument', '-Wno-unused-function',
'-fimplicit-none', std18, language : 'fortran')
if get_option('buildtype').contains('debug')
add_project_arguments('-Werror=array-bounds', '-fcheck=all', language: 'fortran')
endif
elif fc.get_id() == 'intel'
add_project_arguments('-warn', '-diag-disable 5268', '-diag-disable 7712', std18, language: 'fortran')
if get_option('buildtype').contains('debug')
# -heap-arrays didn't appear to be needed on Linux?
add_project_arguments('-check bounds', language: 'fortran')
endif
elif fc.get_id() == 'intel-cl'
# /fpp is necessary for any Fortran preprocessing statement with Intel ifort on Windows
# https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-fpp
add_project_arguments('/warn', '/Qdiag-disable:5268', '/Qdiag-disable:7712', '/fpp', std18, language: 'fortran')
if get_option('buildtype').contains('debug')
add_project_arguments('/check:bounds', '/heap-arrays', language: 'fortran')
endif
elif ['pgi', 'flang'].contains(fc.get_id())
if get_option('buildtype').contains('debug')
add_project_arguments('-Mbounds', language: 'fortran')
endif
endif
# -- MKL (in general, MKL can be used with intel, intel-cl, gcc or PGI)
mklroot = get_option('mklroot')
if ['intel', 'intel-cl'].contains(fc.get_id()) and mklroot == ''
missing_opt = os == 'windows' ? '-Dmklroot=%MKLROOT% or -Dmklroot=$env:mklroot' : '-Dmklroot=$MKLROOT'
error('Intel compiler needs MKL via MKLROOT environment variable. Please use option ' + missing_opt)
endif
mkllib_root = mklroot/'lib/intel64'
# os == 'windows' ? mklroot/'lib/intel64_win' : mklroot/'lib/intel64'
# == threads
threads = dependency('threads')
# == MPI
mpiexec = find_program('mpiexec')
mpi = dependency('mpi', language : 'fortran')
# this test needs to be .RUN() to catch some MPI configuration errors
if fc.run(files('../tests/test_mpi.f90'), dependencies : mpi, name: 'Fortran MPI').returncode() != 0
error('mpi was not able to run a simple program')
endif
# == Intel OpenMP
intelMP_lib = []
if mklroot != ''
n = os == 'windows' ? 'iomp5md' : 'iomp5'
intelMP_lib = fc.find_library(n, dirs: mklroot / '../compiler/lib/intel64')
endif
# == Lapack
if mklroot == ''
blas = dependency('blas', required: false, disabler: true)
if not blas.found() # necessary for some systems incl. CentOS 7
blas = fc.find_library('blas', required: false, disabler: true)
endif
if not fc.links('x=dnrm2(1, [2.], 1); end', dependencies: blas, name: 'BLAS')
blas = disabler()
endif
lapack = dependency('lapack', required: false, disabler: true)
if not lapack.found()
lapack = fc.find_library('lapack', required: false, disabler: true)
endif
if not fc.links('print *,disnan(0.); end', dependencies: lapack, name: 'LAPACK')
lapack = disabler()
endif
if not lapack.found() or not blas.found()
lapack_proj = subproject('lapack')
lapack = lapack_proj.get_variable('lapack')
blas = lapack_proj.get_variable('blas')
endif
else
# MKL
lapack = []
n1 = fc.get_id() == 'gcc' ? 'mkl_gf_lp64' : 'mkl_intel_lp64'
names = [n1, 'mkl_intel_thread', 'mkl_core']
foreach n : names
lapack += fc.find_library(n, dirs: mkllib_root)
endforeach
lapack += intelMP_lib
blas = lapack
endif
# --- intel MPI lib for Windows
intelmpi_lib = []
if mklroot != '' and os == 'windows'
intelmpi_lib = fc.find_library('impi', dirs: mklroot / '../mpi/intel64/lib/release')
endif
# --- Find BLACS
# some systems need Blacs explicitly, but most don't, so don't pass disabler() if not found.
blacs = []
if mklroot == ''
blacs = fc.find_library('blacs-openmpi', required: false)
if not blacs.found()
blacs = []
endif
else
blacs += fc.find_library('mkl_blacs_intelmpi_lp64', dirs: mkllib_root)
blacs += intelmpi_lib
endif
# --- Find Scalapack
scalapack = dependency('scalapack', cmake_module_path: meson.source_root() /'cmake/Modules', required: false, disabler: true)
if not scalapack.found()
foreach n : ['scalapack-openmpi', 'scalapack']
scalapack = fc.find_library(n, required: false, disabler: true)
if scalapack.found()
break
endif
endforeach
endif
if fc.run(files('../tests/test_scalapack.f90'), dependencies: [scalapack, mpi], name: 'SCALAPACK').returncode() != 0
# .links() is NOT an adequate test
scalapack = disabler()
endif
if not scalapack.found()
scalapack_proj = subproject('scalapack')
scalapack = declare_dependency(link_with: scalapack_proj.get_variable('scalapack_lib'))
endif
# --- find Mumps
mumps = disabler()
if mklroot == ''
if bits == '64'
mumps_name = 'dmumps'
elif bits == '32'
mumps_name = 'smumps'
else
error('unknown precision ' + bits)
endif
mumps_root = get_option('MUMPS_ROOT')
if mumps_root == ''
if os == 'linux'
mumps_root = '/usr'
mumpslib = [fc.find_library(mumps_name, required : false, disabler: true),
fc.find_library('mumps_common', required: false, disabler: true)]
elif os == 'darwin'
# assuming homebrew
mumps_root = '/usr/local/opt/mumps'
mumpslib = [fc.find_library(mumps_name, dirs: mumps_root / 'lib', required : false, disabler: true),
fc.find_library('mumps_common', dirs: mumps_root / 'lib', required: false, disabler: true)]
else
mumpslib = [disabler(), disabler()]
endif
else
mumpslib = [fc.find_library(mumps_name, dirs : mumps_root, required : false, disabler: true),
fc.find_library('mumps_common', dirs : mumps_root, required : false, disabler: true)]
endif
mumpsinc = mumps_root / 'include'
if mumpslib[0].found() and mumpslib[1].found()
mumps = declare_dependency(include_directories: include_directories(mumpsinc), dependencies: mumpslib)
endif
code='''
include 'dmumps_struc.h'
type(DMUMPS_STRUC) :: mumps_par
end'''
# NOTE: leave this "if mumps.found()" so that mumpsinc is sure to be defined
if mumps.found() and not fc.links(code, include_directories: include_directories(mumpsinc), dependencies: mumpslib, name: 'MUMPS')
mumps = disabler()
endif
endif
if not mumps.found()
# MKL will always build MUMPS too
mumps_proj = subproject('mumps')
mumps = mumps_proj.get_variable('mumps')
endif
# --- NetCDF4
if get_option('netcdf').enabled()
netcdf_proj = subproject('nc4fortran')
netcdf_interface = netcdf_proj.get_variable('netcdf_interface')
assert(netcdf_interface.found(), 'NetCDF I/O requested but NetCDF library not available')
else
netcdf_interface = disabler()
endif
# --- HDF5
if not netcdf_interface.found() and get_option('hdf5').enabled()
hdf5_proj = subproject('h5fortran')
hdf5_interface = hdf5_proj.get_variable('hdf5_interface')
assert(hdf5_interface.found(), 'HDF5 I/O requested but HDF5 library not available')
else
hdf5_interface = disabler()
endif
# --- Python
pymod = import('python')
python = pymod.find_installation('python3')
message('Using Python ' + python.language_version())
if python.language_version().version_compare('< 3.6')
error('Python ' + python.language_version() + ' is too old, you must have at least Python 3.6. Try "conda activate" or "module load python3" or similar.')
endif
# not needed at the moment
# is_ci = run_command(python, meson.source_root() / 'script_utils/meson_get_environment_variable.py', 'CI').stdout().to_lower() == 'true'
if run_command(python, '-c', 'import gemini').returncode() != 0
warning('Please install PyGemini by "pip install -e ' + meson.source_root() + '"')
endif
#--- Octave
octave = find_program('octave', required: false, disabler: true)
# must do .found check since run_command(disabler()) has undefined returncode.
if run_command(octave, '--eval', 'assert(exist("validateattributes", "file")==2)').returncode() != 0
message('SKIP: Octave version is too old for comparison tests.')
octave = disabler()
endif
#--- Matlab
# buggy for Matlab < R2019a, may hang "meson setup" silently for two minutes
matlab = find_program('matlab', required: get_option('matlab'), disabler: true)