|
| 1 | +# NumPy include directory - needed in all submodules |
| 2 | +# The try-except is needed because when things are split across drives on Windows, there |
| 3 | +# is no relative path and an exception gets raised. There may be other such cases, so add |
| 4 | +# a catch-all and switch to an absolute path. Relative paths are needed when for example |
| 5 | +# a virtualenv is placed inside the source tree; Meson rejects absolute paths to places |
| 6 | +# inside the source tree. |
| 7 | +# For cross-compilation it is often not possible to run the Python interpreter in order |
| 8 | +# to retrieve numpy's include directory. It can be specified in the cross file instead: |
| 9 | +# |
| 10 | +# [properties] |
| 11 | +# numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include |
| 12 | +# |
| 13 | +# This uses the path as is, and avoids running the interpreter. |
| 14 | +incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') |
| 15 | +if incdir_numpy == 'not-given' |
| 16 | + incdir_numpy = run_command(py3, |
| 17 | + [ |
| 18 | + '-c', |
| 19 | + '''import os |
| 20 | +import numpy as np |
| 21 | +try: |
| 22 | + incdir = os.path.relpath(np.get_include()) |
| 23 | +except Exception: |
| 24 | + incdir = np.get_include() |
| 25 | +print(incdir)''' |
| 26 | + ], |
| 27 | + check: true |
| 28 | + ).stdout().strip() |
| 29 | +endif |
| 30 | +numpy_dep = declare_dependency( |
| 31 | + compile_args: [ |
| 32 | + '-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION', |
| 33 | + # Allow NumPy's printf format specifiers in C++. |
| 34 | + '-D__STDC_FORMAT_MACROS=1', |
| 35 | + ], |
| 36 | + include_directories: include_directories(incdir_numpy), |
| 37 | + dependencies: py3_dep, |
| 38 | +) |
| 39 | + |
| 40 | +# For cross-compilation it is often not possible to run the Python interpreter in order |
| 41 | +# to retrieve the platform-specific /dev/null. It can be specified in the cross file |
| 42 | +# instead: |
| 43 | +# |
| 44 | +# [properties] |
| 45 | +# devnull = /dev/null |
| 46 | +# |
| 47 | +# This uses the value as is, and avoids running the interpreter. |
| 48 | +devnull = meson.get_external_property('devnull', 'not-given') |
| 49 | +if devnull == 'not-given' |
| 50 | + devnull = run_command(py3, '-c', 'import os; print(os.devnull)', |
| 51 | + capture: true, check: true).stdout().strip() |
| 52 | +endif |
| 53 | + |
| 54 | +# Will only exist on Linux with older glibc. |
| 55 | +dl = cc.find_library('dl', required: false) |
| 56 | + |
| 57 | +# With Meson >= 1.2.0, use cpp_winlibs instead of manually searching. |
| 58 | +if ['cygwin', 'windows'].contains(host_machine.system()) |
| 59 | + comctl32 = cc.find_library('comctl32') |
| 60 | + ole32 = cc.find_library('ole32') |
| 61 | + psapi = cc.find_library('psapi') |
| 62 | + shell32 = cc.find_library('shell32') |
| 63 | + user32 = cc.find_library('user32') |
| 64 | +else |
| 65 | + comctl32 = [] |
| 66 | + ole32 = [] |
| 67 | + psapi = [] |
| 68 | + shell32 = [] |
| 69 | + user32 = [] |
| 70 | +endif |
| 71 | + |
| 72 | +extension_data = { |
| 73 | + '_backend_agg': { |
| 74 | + 'subdir': 'matplotlib/backends', |
| 75 | + 'sources': files( |
| 76 | + 'py_converters.cpp', |
| 77 | + '_backend_agg.cpp', |
| 78 | + '_backend_agg_wrapper.cpp', |
| 79 | + ), |
| 80 | + 'dependencies': [agg_dep, numpy_dep, freetype_dep], |
| 81 | + }, |
| 82 | + '_c_internal_utils': { |
| 83 | + 'subdir': 'matplotlib', |
| 84 | + 'sources': files( |
| 85 | + '_c_internal_utils.c', |
| 86 | + ), |
| 87 | + 'dependencies': [py3_dep, dl, ole32, shell32, user32], |
| 88 | + }, |
| 89 | + 'ft2font': { |
| 90 | + 'subdir': 'matplotlib', |
| 91 | + 'sources': files( |
| 92 | + 'ft2font.cpp', |
| 93 | + 'ft2font_wrapper.cpp', |
| 94 | + 'py_converters.cpp', |
| 95 | + ), |
| 96 | + 'dependencies': [ |
| 97 | + freetype_dep, numpy_dep, agg_dep.partial_dependency(includes: true), |
| 98 | + ], |
| 99 | + }, |
| 100 | + '_image': { |
| 101 | + 'subdir': 'matplotlib', |
| 102 | + 'sources': files( |
| 103 | + '_image_wrapper.cpp', |
| 104 | + 'py_converters_11.cpp', |
| 105 | + ), |
| 106 | + 'dependencies': [ |
| 107 | + pybind11_dep, |
| 108 | + # Only need source code files agg_image_filters.cpp and agg_trans_affine.cpp |
| 109 | + agg_dep, |
| 110 | + ], |
| 111 | + }, |
| 112 | + '_path': { |
| 113 | + 'subdir': 'matplotlib', |
| 114 | + 'sources': files( |
| 115 | + 'py_converters.cpp', |
| 116 | + '_path_wrapper.cpp', |
| 117 | + ), |
| 118 | + 'dependencies': [numpy_dep, agg_dep], |
| 119 | + }, |
| 120 | + '_qhull': { |
| 121 | + 'subdir': 'matplotlib', |
| 122 | + 'sources': files( |
| 123 | + '_qhull_wrapper.cpp', |
| 124 | + ), |
| 125 | + 'dependencies': [numpy_dep, qhull_dep], |
| 126 | + 'c_args': [f'-DMPL_DEVNULL=@devnull@'], |
| 127 | + 'cpp_args': [f'-DMPL_DEVNULL=@devnull@'], |
| 128 | + }, |
| 129 | + '_tkagg': { |
| 130 | + 'subdir': 'matplotlib/backends', |
| 131 | + 'sources': files( |
| 132 | + '_tkagg.cpp', |
| 133 | + ), |
| 134 | + 'include_directories': include_directories('.'), |
| 135 | + # The dl/psapi libraries are needed for finding Tcl/Tk at run time. |
| 136 | + 'dependencies': [ |
| 137 | + numpy_dep, agg_dep.partial_dependency(includes: true), dl, comctl32, psapi, |
| 138 | + ], |
| 139 | + }, |
| 140 | + '_tri': { |
| 141 | + 'subdir': 'matplotlib', |
| 142 | + 'sources': files( |
| 143 | + 'tri/_tri.cpp', |
| 144 | + 'tri/_tri_wrapper.cpp', |
| 145 | + ), |
| 146 | + 'dependencies': [pybind11_dep], |
| 147 | + }, |
| 148 | + '_ttconv': { |
| 149 | + 'subdir': 'matplotlib', |
| 150 | + 'sources': files( |
| 151 | + '_ttconv.cpp', |
| 152 | + ), |
| 153 | + 'dependencies': [ttconv_dep, pybind11_dep], |
| 154 | + }, |
| 155 | +} |
| 156 | + |
| 157 | +cpp_special_arguments = [] |
| 158 | +if cpp.get_id() == 'msvc' and get_option('buildtype') != 'plain' |
| 159 | + # Disable FH4 Exception Handling implementation so that we don't require |
| 160 | + # VCRUNTIME140_1.dll. For more details, see: |
| 161 | + # https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/ |
| 162 | + # https://github.com/joerick/cibuildwheel/issues/423#issuecomment-677763904 |
| 163 | + cpp_special_arguments += ['/d2FH4-'] |
| 164 | +endif |
| 165 | + |
| 166 | +foreach ext, kwargs : extension_data |
| 167 | + # Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each extension. |
| 168 | + unique_array_api = '-DPY_ARRAY_UNIQUE_SYMBOL=MPL_@0@_ARRAY_API'.format(ext.replace('.', '_')) |
| 169 | + additions = { |
| 170 | + 'c_args': [unique_array_api] + kwargs.get('c_args', []), |
| 171 | + 'cpp_args': cpp_special_arguments + [unique_array_api] + kwargs.get('cpp_args', []), |
| 172 | + } |
| 173 | + py3.extension_module( |
| 174 | + ext, |
| 175 | + install: true, |
| 176 | + kwargs: kwargs + additions) |
| 177 | +endforeach |
| 178 | + |
| 179 | +if get_option('macosx') and host_machine.system() == 'darwin' |
| 180 | + add_languages('objc', native: false) |
| 181 | + py3.extension_module( |
| 182 | + '_macosx', |
| 183 | + subdir: 'matplotlib/backends', |
| 184 | + sources: files( |
| 185 | + '_macosx.m', |
| 186 | + ), |
| 187 | + dependencies: dependency('appleframeworks', modules: 'Cocoa'), |
| 188 | + override_options: ['werror=true'], |
| 189 | + install: true, |
| 190 | + ) |
| 191 | +endif |
0 commit comments