-
Notifications
You must be signed in to change notification settings - Fork 84
/
meson.build
199 lines (186 loc) · 6.58 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
project(
'turbodbc', 'cpp',
license: 'MIT',
meson_version: '>= 1.1.0',
default_options: [
'buildtype=release',
'cpp_std=c++17',
'warning_level=3',
'build_testing=false',
]
)
fs = import('fs')
cpp = meson.get_compiler('cpp')
add_global_arguments('-DBOOST_NO_CXX98_FUNCTION_BASE', language: 'cpp')
add_global_arguments('-DGTEST_LINKED_AS_SHARED_LIBRARY=1', language: 'cpp')
if target_machine.system() == 'windows'
add_global_arguments('-DNOMINMAX', language: 'cpp')
endif
simdutf = dependency('simdutf')
arrow = dependency('arrow')
build_testing = get_option('build_testing')
if build_testing
gtest = dependency('gtest')
gtest_main = dependency('gtest_main')
gmock = dependency('gmock')
endif
# unixodbc = dependency('unixodbc')
py = import('python').find_installation()
# Taken from https://github.com/scipy/scipy/blob/e2ce1a57639dbfa5d1439cb542b67e3cbeda5d29/scipy/meson.build#L30
# The chdir is needed because within numpy there's an `import signal`
# statement, and we don't want that to pick up scipy's signal module rather
# than the stdlib module. The try-except is needed because when things are
# split across drives on Windows, there is no relative path and an exception
# gets raised. There may be other such cases, so add a catch-all and switch to
# an absolute path. Relative paths are needed when for example a virtualenv is
# placed inside the source tree; Meson rejects absolute paths to places inside
# the source tree.
# For cross-compilation it is often not possible to run the Python interpreter
# in order to retrieve numpy's include directory. It can be specified in the
# cross file instead:
# [properties]
# numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include
#
# This uses the path as is, and avoids running the interpreter.
incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
if incdir_numpy == 'not-given'
incdir_numpy = run_command(py,
[
'-c',
'''import os
import numpy as np
try:
incdir = os.path.relpath(np.get_include())
except Exception:
incdir = np.get_include()
print(incdir)
'''
],
check: true
).stdout().strip()
# We do need an absolute path to feed to `cc.find_library` below
_incdir_numpy_abs = run_command(py,
['-c', 'import numpy; print(numpy.get_include())'],
check: true
).stdout().strip()
else
_incdir_numpy_abs = incdir_numpy
endif
inc_np = include_directories(incdir_numpy)
# Don't use the deprecated NumPy C API. Define this to a fixed version instead of
# NPY_API_VERSION in order not to break compilation for released SciPy versions
# when NumPy introduces a new deprecation.
numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_21_API_VERSION']
np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api)
incdir_pyarrow = meson.get_external_property('pyarrow-include-dir', 'not-given')
if incdir_pyarrow == 'not-given'
incdir_pyarrow = run_command(py,
[
'-c',
'''import os
import sysconfig
try:
incdir = os.path.relpath(sysconfig.get_path('platlib'))
except Exception:
incdir = sysconfig.get_path('platlib')
print(incdir + "/pyarrow/include")
'''
],
check: true
).stdout().strip()
# We do need an absolute path to feed to `cc.find_library` below
_incdir_pyarrow_abs = run_command(py,
[
'-c',
'''import os
import sysconfig
print(os.path.abspath(sysconfig.get_path("platlib")) + "/pyarrow/include")
'''
],
check: true
).stdout().strip()
# We would rather like to use the following code, but sadly pyarrow (in contrast to numpy)
# does not name the correct directory in a cross-compilation setting.
# incdir_pyarrow = run_command(py,
# [
# '-c',
# '''import os
#import pyarrow as pa
#try:
# incdir = os.path.relpath(pa.get_include())
#except Exception:
# incdir = pa.get_include()
#print(incdir)
# '''
# ],
# check: true
# ).stdout().strip()
#
# # We do need an absolute path to feed to `cc.find_library` below
# _incdir_pyarrow_abs = run_command(py,
# ['-c', 'import pyarrow; print(pyarrow.get_include())'],
# check: true
# ).stdout().strip()
else
_incdir_pyarrow_abs = incdir_pyarrow
endif
inc_pa = include_directories(incdir_pyarrow)
pa_dep = declare_dependency(include_directories: inc_pa)
arrow_python = cpp.find_library('arrow_python', dirs: [fs.parent(_incdir_pyarrow_abs)])
deps = [np_dep, pa_dep, arrow, arrow_python, simdutf]
if target_machine.system() == 'windows'
odbc32 = cpp.find_library('odbc32')
deps += odbc32
else
unixodbc = cpp.find_library('odbc')
deps += unixodbc
endif
subdir('cpp/cpp_odbc')
subdir('cpp/turbodbc')
subdir('cpp/turbodbc_arrow')
turbodbc_sources = [
'cpp/turbodbc_python/Library/src/determine_parameter_type.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/buffer_size.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/column_info.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/connect.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/connection.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/cursor.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/error.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/module.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/options.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/python_parameter_set.cpp',
'cpp/turbodbc_python/Library/src/python_bindings/python_result_set.cpp',
'cpp/turbodbc_python/Library/src/python_parameter_set.cpp',
'cpp/turbodbc_python/Library/src/python_result_set.cpp',
'cpp/turbodbc_numpy/Library/src/binary_column.cpp',
'cpp/turbodbc_numpy/Library/src/datetime_column.cpp',
'cpp/turbodbc_numpy/Library/src/make_numpy_array.cpp',
'cpp/turbodbc_numpy/Library/src/masked_column.cpp',
'cpp/turbodbc_numpy/Library/src/numpy_result_set.cpp',
'cpp/turbodbc_numpy/Library/src/numpy_type.cpp',
'cpp/turbodbc_numpy/Library/src/set_numpy_parameters.cpp',
'cpp/turbodbc_numpy/Library/src/string_column.cpp',
'cpp/turbodbc_numpy/Library/src/unicode_column.cpp',
]
py.extension_module(
'turbodbc_intern',
turbodbc_sources,
dependencies: deps,
link_with: [cpp_odbc, turbodbc, turbodbc_arrow],
include_directories: include_directories('cpp/cpp_odbc/Library', 'cpp/turbodbc/Library', 'cpp/turbodbc_python/Library', 'cpp/turbodbc_numpy/Library', 'cpp/turbodbc_arrow/Library'),
install: true
)
py.install_sources(
[
'turbodbc/options.py',
'turbodbc/connect.py',
'turbodbc/__init__.py',
'turbodbc/data_types.py',
'turbodbc/api_constants.py',
'turbodbc/connection.py',
'turbodbc/exceptions.py',
'turbodbc/constructors.py',
'turbodbc/cursor.py',
],
subdir: 'turbodbc',
)