From da353db5129c8315220b75e9917c902d9c1fdb0a Mon Sep 17 00:00:00 2001 From: Tom Schoonjans Date: Thu, 8 Aug 2024 06:43:50 +0200 Subject: [PATCH] Simplify python build --- python/meson.build | 106 +++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 61 deletions(-) diff --git a/python/meson.build b/python/meson.build index adb2009c..b51c7b1e 100644 --- a/python/meson.build +++ b/python/meson.build @@ -20,76 +20,60 @@ python_error_flags = [ python_error_flags = cc.get_supported_arguments(python_error_flags) -numpy_cflags = ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'] +# We cannot set this until cython 3 is adopted everywhere +# numpy_cflags = ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'] pydir = meson.current_build_dir() -if not get_option('python-bindings').disabled() - swig = find_program(get_option('swig'), 'swig', required : get_option('python-bindings')) - if swig.found() - xraylib_wrap_c = custom_target('xraylib_wrap_c', - output : ['xraylib_wrap.c', 'xraylib.py'], - input : swig_interface, - depend_files : xraylib_headers, - command : [ - swig, - '-DVERSION=\'@0@\''.format(meson.project_version()), - '-includeall', - '-I@0@'.format(meson.current_source_dir()), - '-I@0@'.format(include_source_dir), - '-I@0@'.format(src_source_dir), - '-o', '@OUTPUT0@', - '-python', - '-py3', - '@INPUT@', - ], - install_dir: [false, python.get_install_dir(pure: false)], - install: true, - install_tag: [false, 'python-runtime'] +swig = find_program(get_option('swig'), 'swig', required : get_option('python-bindings')) - ) - xraylib_ext = python.extension_module('_xraylib', xraylib_wrap_c[0], - dependencies : [python_dep, xraylib_lib_dep], - include_directories: extra_include_dirs, - install: true, - install_dir: python.get_install_dir(pure: false), - c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags + numpy_cflags, - install_tag: ['python-runtime'] - ) - subdir('tests') - endif +if swig.found() + xraylib_wrap_c = custom_target('xraylib_wrap_c', + output : ['xraylib_wrap.c', 'xraylib.py'], + input : swig_interface, + depend_files : xraylib_headers, + command : [ + swig, + '-DVERSION=\'@0@\''.format(meson.project_version()), + '-includeall', + '-I@0@'.format(meson.current_source_dir()), + '-I@0@'.format(include_source_dir), + '-I@0@'.format(src_source_dir), + '-o', '@OUTPUT0@', + '-python', + '-py3', + '@INPUT@', + ], + install_dir: [false, python.get_install_dir(pure: false)], + install: true, + install_tag: [false, 'python-runtime'] + ) + xraylib_ext = python.extension_module('_xraylib', xraylib_wrap_c[0], + dependencies : [python_dep, xraylib_lib_dep], + include_directories: extra_include_dirs, + install: true, + install_dir: python.get_install_dir(pure: false), + c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags, + install_tag: ['python-runtime'] + ) + subdir('tests') endif -if not get_option('python-numpy-bindings').disabled() - cython = find_program('cython', 'cython3', 'cython-3', 'cython' + python.language_version(), 'cython-' + python.language_version(), required : get_option('python-numpy-bindings')) +if add_languages('cython', required: get_option('python-numpy-bindings'), native: false) deps = [python_dep, xraylib_lib_dep] # lld-link doesnt find the openmp import libraries if cc.get_id() != 'clang-cl' - deps += [dependency('openmp', language: 'c', required: false)] - endif - if cython.found() - xraylib_np_c = custom_target('xraylib_np_c', - output : 'xraylib_np.c', - input : 'xraylib_np.pyx', - depend_files : 'xraylib_np_c.pxd', - command : [ - cython, - '-X', - 'language_level=3,boundscheck=False,wraparound=False,cdivision=True', - '@INPUT@', - '-o', - '@OUTPUT@', - ], - ) - xraylib_np_ext = python.extension_module('xraylib_np', xraylib_np_c, - dependencies : deps, - include_directories: extra_include_dirs, - install: true, - install_dir: python.get_install_dir(pure: false), - c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags + numpy_cflags, - install_tag: ['python-runtime'], - ) - + deps += [dependency('openmp', language: 'c', required: false)] endif + xraylib_np_ext = python.extension_module('xraylib_np', + 'xraylib_np.pyx', + dependencies : deps, + include_directories: extra_include_dirs, + install: true, + install_dir: python.get_install_dir(pure: false), + c_args: core_c_args + ['-I' + numpy_header_location] + python_error_flags, + cython_args: '-Xlanguage_level=3,boundscheck=False,wraparound=False,cdivision=True', + install_tag: ['python-runtime'], + ) endif