forked from MODFLOW-USGS/modflow6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
228 lines (206 loc) · 7.79 KB
/
meson.build
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
project(
'MODFLOW 6',
'fortran',
version: '6.5.0.dev0',
license: 'CC0',
meson_version: '>= 1.1.0',
default_options : [
'b_vscrt=static_from_buildtype', # Link runtime libraries statically on Windows
'optimization=2',
'debug=false',
'fortran_std=f2008',
])
if get_option('optimization') == '3'
error('Only optimization levels <= 2 are supported')
endif
if get_option('optimization') == '2'
profile = 'release'
else
profile = 'develop'
endif
message('The used profile is:', profile)
# parse compiler options
fc = meson.get_compiler('fortran')
fc_id = fc.get_id()
message('The fc_id is:', fc_id)
compile_args = []
link_args = []
# Command line options for gfortran
if fc_id == 'gcc'
# General options
compile_args += [
'-fall-intrinsics',
'-pedantic',
'-cpp',
'-Wcharacter-truncation',
'-Wno-unused-dummy-argument', # This makes problems with OOP
'-Wno-intrinsic-shadow', # We shadow intrinsics with methods, which should be fine
'-Wno-maybe-uninitialized', # "Uninitialized" flags produce false positives with allocatables
'-Wno-uninitialized',
]
# Options specific to profile
if profile == 'release'
compile_args += ['-ffpe-summary=overflow', '-ffpe-trap=overflow,zero,invalid']
elif profile == 'develop'
compile_args += ['-fcheck=all', '-ffpe-trap=overflow,zero,invalid']
endif
# Define OS with gfortran for OS specific code
# These are identical to pre-defined macros available with ifort
system = build_machine.system()
if system == 'linux'
compile_args += '-D__linux__'
elif system == 'darwin'
compile_args += '-D__APPLE__'
elif system == 'windows'
compile_args += '-D_WIN32'
endif
endif
# Command line options for ifort
if fc_id == 'intel-cl'
# windows
compile_args += ['/fpe:0', # Activate all floating point exceptions
'/heap-arrays:0',
'/traceback',
'/fpp', # Activate preprocessing
'/Qdiag-disable:7416', # f2008 warning
'/Qdiag-disable:7025', # f2008 warning
'/Qdiag-disable:5268', # Line too long
]
link_args += ['/ignore:4217', # access through ddlimport might be inefficient
'/ignore:4286' # same as 4217, but more general
]
elif fc_id == 'intel'
# linux and macOS
compile_args += ['-fpe0', # Activate all floating point exceptions
'-no-heap-arrays',
'-traceback',
'-diag-disable:7416', # f2008 warning
'-diag-disable:7025', # f2008 warning
'-diag-disable:5268', # Line too long
]
link_args += '-static-intel'
# Command line options for ifx
elif fc_id == 'intel-llvm-cl'
# windows
compile_args += ['/fpe:0', # Activate all floating point exceptions
'/heap-arrays:0',
'/traceback',
'/fpp', # Activate preprocessing
'/Qdiag-disable:7416', # f2008 warning
'/Qdiag-disable:7025', # f2008 warning
'/Qdiag-disable:5268', # Line too long
]
link_args += ['/ignore:4217', # access through ddlimport might be inefficient
'/ignore:4286' # same as 4217, but more general
]
endif
# parallel build options
is_parallel_build = get_option('parallel')
is_cray = get_option('cray')
is_mpich = get_option('mpich')
if is_cray and build_machine.system() != 'linux'
error('cray=true only supported on linux systems')
endif
if is_cray and not is_parallel_build
is_parallel_build = true
is_mpich = true
endif
if is_mpich
if is_cray
mpifort_name = 'mpichf90'
else
mpifort_name = 'mpichfort'
endif
endif
message('Parallel build:', is_parallel_build)
# windows options for petsc
petsc_dir = meson.project_source_root() / '..' /'petsc-3.18.5'
petsc_arch = 'arch-ci-mswin-intel-modflow6'
# on windows only with intel
if build_machine.system() == 'windows' and is_parallel_build
if fc_id != 'intel-cl'
error('Parallel build on Windows only with intel compiler. Terminating...')
endif
endif
# lists for parallel dependencies and compiler arguments
dependencies = [ ]
extra_cmp_args = [ ]
# load petsc and mpi dependencies/libraries
if is_parallel_build
# find petsc
if build_machine.system() != 'windows'
petsc = dependency('PETSc', required : true)
else
# directly look for petsc
petsc_compiled = petsc_dir / petsc_arch
petsc = fc.find_library('libpetsc', dirs: petsc_compiled / 'lib', required : true)
endif
extra_cmp_args += [ '-D__WITH_PETSC__' ]
dependencies += petsc
with_petsc = true
# find mpi
if is_mpich
mpi = dependency('mpich', required : true)
mpifort = dependency(mpifort_name, required : mpi.found())
dependencies += [ mpi, mpifort ]
else
mpi = dependency('mpi', language : 'fortran', required : true)
dependencies += mpi
endif
extra_cmp_args += [ '-D__WITH_MPI__']
with_mpi = true
else
with_petsc = false
with_mpi = false
endif
compile_args += extra_cmp_args
add_project_arguments(fc.get_supported_arguments(compile_args), language: 'fortran')
add_project_link_arguments(fc.get_supported_arguments(link_args), language: 'fortran')
if is_parallel_build and build_machine.system() == 'windows'
message('Compiling PETSc Fortran modules')
petsc_incdir = include_directories([petsc_dir / 'include', petsc_compiled / 'include'])
petsc_src = petsc_dir / 'src'
sources_petsc = [petsc_src / 'dm/f90-mod/petscdmdamod.F90',
petsc_src / 'dm/f90-mod/petscdmmod.F90',
petsc_src / 'dm/f90-mod/petscdmplexmod.F90',
petsc_src / 'dm/f90-mod/petscdmswarmmod.F90',
petsc_src / 'ksp/f90-mod/petsckspdefmod.F90',
petsc_src / 'ksp/f90-mod/petsckspmod.F90',
petsc_src / 'ksp/f90-mod/petscpcmod.F90',
petsc_src / 'mat/f90-mod/petscmatmod.F90',
petsc_src / 'snes/f90-mod/petscsnesmod.F90',
petsc_src / 'sys/f90-mod/petscsysmod.F90',
petsc_src / 'sys/mpiuni/f90-mod/mpiunimod.F90',
petsc_src / 'tao/f90-mod/petsctaomod.F90',
petsc_src / 'ts/f90-mod/petsctsmod.F90',
petsc_src / 'vec/f90-mod/petscvecmod.F90',]
petsc_modules = static_library('petsc_modules',
sources_petsc,
dependencies: dependencies,
include_directories: petsc_incdir)
endif
# build mf6 and libmf6
buildname = get_option('buildname')
subdir('src')
subdir('srcbmi')
# build zbud6 and mf5to6 utility programs
subdir('utils')
# add unit test directory
# subdir('unittests')
# meson tests to evaluate installation success
testdir = meson.project_source_root() / '.mf6minsim'
if with_mpi
mpiexec = find_program('mpiexec', required : false)
if mpiexec.found()
test('Parallel version command line test', mpiexec, args : ['-n', '2', mf6exe, '-v', '-p'])
test('Parallel compiler command line test', mpiexec, args : ['-n', '2', mf6exe, '-c', '-p'])
test('Serial simulation test', mf6exe, workdir : testdir)
test('Parallel simulation test - 1 core', mpiexec, workdir : testdir, args : ['-n', '1', mf6exe, '-p'])
test('Parallel simulation test - 2 cores', mpiexec, workdir : testdir, args : ['-n', '2', mf6exe, '-p'])
endif
else
test('Version command line test', mf6exe, args : ['-v',])
test('Compiler command line test', mf6exe, args : ['-c',])
test('Test installation help', mf6exe, args : ['-h',])
test('Serial simulation test', mf6exe, workdir : testdir)
endif