-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
133 lines (107 loc) · 3.98 KB
/
meson.build
File metadata and controls
133 lines (107 loc) · 3.98 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
# ---------------------------------------------------------------- #
# ---------------------- Gridmarthe build ------------------------ #
# ---------------------------------------------------------------- #
# https://numpy.org/doc/stable/f2py/buildtools/meson.html #
# ---------------------------------------------------------------- #
project('gridmarthe', ['fortran', 'c'],
version : run_command('meson_get_version.py').stdout().strip(),
license: 'GNU/GPL-V3',
meson_version: '>=1.1.0',
default_options : [
'warning_level=1',
'buildtype=release'
# 'fortran_std=legacy'
],
)
# add_languages('fortran')
subdir('src/gridmarthe/core')
core_sources = all_functions_sources
core_install_dir = 'gridmarthe/core/' # in python_install_dir
# ------ Get compiler and build options ------ #
fc = meson.get_compiler('fortran')
cc = meson.get_compiler('c')
deps = []
inc_dir = []
# Options de compilation Fortran
fargs = [] # compile args
largs = [] # link args
if fc.get_id() == 'gcc'
fargs += ['-cpp', '-fdefault-real-8']
# fargs += ['-O2'] # fix warning 'use builtin O3, deactivate this line"
fargs += ['-ffree-line-length-none']
if cc.version().version_compare('>=13.0')
fargs += ['-fallow-argument-mismatch', '-std=legacy']
endif
if host_machine.system() == 'windows'
fargs += ['-Wno-error']
if not get_option('condabuild')
largs += ['-static', '-static-libgfortran', '-static-libgcc', '-static-libquadmath']
else
fargs += ['-fPIC']
endif
quadmath_dep = fc.find_library('quadmath', required: false) # from `f2py --build-dir` meson.build generation
quadmath = declare_dependency(link_args : ['-lquadmath'])
deps += [quadmath_dep,quadmath]
else
fargs += ['-fPIC'] # , '-shared' not really necessary here
endif
elif fc.get_id() in ['llvm-flang', 'flang', 'flang-new']
# TODO add options for llvm-flang for conda-forge
fargs += ['-fdefault-real-8', '-ffree-form']
elif cc.get_id() in ['intel-llvm', 'intel', 'intel-llvm-cl', 'intel-cl']
fargs += ['-real-size 64', '-stand f95']
else
# 'msvc' ?
error('Build is recommended with GCC/gfortran')
endif
if get_option('english')
fargs += ['-DENGLISH']
endif
fortran_args = fc.get_supported_arguments(fargs)
link_args = fc.get_supported_link_arguments(largs)
add_project_arguments(fortran_args, language: 'fortran')
add_project_link_arguments(link_args, language: 'fortran')
# ----- Get Python linked ------ #
py = import('python').find_installation(pure: false)
py_dep = py.dependency()
python_install_dir = py.get_install_dir()
deps += [py_dep]
if get_option('pip_edit_mode')
# editable version, bug in CI build...
incdir_numpy = run_command(py,
['-c', 'import os; import numpy; print(os.path.relpath(numpy.get_include()))'],
check : true
).stdout().strip()
else
# classical, not functionnal in editable mode...
incdir_numpy = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()
endif
inc_np = include_directories(incdir_numpy)
np_dep = declare_dependency(include_directories: inc_np)
incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src'
inc_f2py = include_directories(incdir_f2py)
fortranobject_c = incdir_f2py / 'fortranobject.c'
inc_dir += [inc_np,inc_f2py]
# ---- Building interface for modgridmarthe functions ---- #
# subdir('src/gridmarthe/lecsem') # not functionnal yet, keep it here for now
core_interface = custom_target('coremodmodule.c',
input : core_sources,
output : ['coremodmodule.c', 'coremod-f2pywrappers.f', 'coremod-f2pywrappers2.f90'],
command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'coremod', '--lower']
)
py.extension_module('coremod',
[
core_sources,
core_interface,
fortranobject_c
],
include_directories: inc_dir,
dependencies: deps,
install: true,
install_dir: python_install_dir / core_install_dir,
)
# --------- Install pypackage ----------- #
install_subdir('src/gridmarthe', install_dir : python_install_dir)