Skip to content

Commit

Permalink
Simplify python build
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoonj committed Aug 8, 2024
1 parent 9a37a48 commit da353db
Showing 1 changed file with 45 additions and 61 deletions.
106 changes: 45 additions & 61 deletions python/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit da353db

Please sign in to comment.