Open ignatenkobrain opened 8 years ago
Basic support for swig could start with something like this:
swig = find_program('swig')
swig_gen = generator(
swig,
output: ['@BASENAME@.cxx'],
arguments: ['-c++', '-python', '-py3', '-o', './@OUTPUT@',
'-outdir', '.', '-I../src', '-MMD',
'@INPUT@'],
depfile: '@BASENAME@.d',
)
swig_sources = [
'wrapper/src/dataset.i',
'wrapper/src/commondata.i',
]
wrapper_deps = [
dependency('python'),
]
foreach swig_source: swig_sources
cpp_source = swig_gen.process(swig_source)
shared_library(
swig_source.split('.').get(-2),
cpp_source,
dependencies: dependencies + wrapper_deps,
install: true,
install_dir: 'lib/',
)
endforeach
But this has the following limitations:
-outdir .
. Could there be some os.path functions such as basename, dirname and so on?Hello, What is the current status of SWIG support in meson? Couldn't find much info in the documentation, and googling it wasn't helpful either. 3 years later, is Zaharid's suggestion still the best way to implement it?
I'm also using swig here, and I want to ask the same question but in a more pointed sense. I got the build steps for swig working fine, but the one thing I have not been able to avoid yet is embedding a list of the generated .java
files in my meson.build
, for telling javac
what to compile.
The problem is that it is impossible to know in advance the names of all the .java
files generated by swig. I mean, you can know them as they are deterministic, but it is really cumbersome to maintain this list since they change as I work on the binding code.
So, to the question, is there a way to get Meson to dynamically determine a list of output files of a given command? All it needs is a way to glob the output files in @PRIVATE_DIR@
so that they can be passed to another command (javac
in this case). This is not the same as globbing input files and would not have the same effect on performance when checking for changes. I can imagine for instance,
swig_output = custom_target('swig',
input: 'myfile.i',
output: ['@BASENAME@.cpp', '@PRIVATE_DIR@/*.java'],
command: [swig, '-c++',
'-o', '@OUTPUT0@',
'-outdir', '@PRIVATE_DIR@']
'-java', '-package', java_package_name, '@INPUT@'])
By the way there is a similar problem with javac
as it generates more .class
files than .java
input files, if there are any inner classes. This need to dynamically determine output files seems general enough that I was wondering if there is any existing thought to how to support it.
I just ran into this in https://github.com/scikit-umfpack/scikit-umfpack/pull/91. A key problem with using SWIG is that it wants -I/path/to/incdir
arguments for where to find other SWIG files and headers to parse. So when you do something like:
foo_dep = cc.find_library('foo', has_headers : ['foo.h']
then that typically succeeds when foo
is installed (say <prefix>/lib/libfoo.so
and <prefix>/include/foo.h
). But the <prefix>/include
is then on the compiler search path, and there is no way to retrieve it (xref gh-8334).
The best I could come up with to get at that <prefix>/include
location is the -print-sysroot'
hack below, but that's of course not going to be very robust:
# SWIG needs to find umfpack.h, so add all potential candidates
swig_inc_args = []
foreach _dir : suitesparse_incdirs # a bunch of hardcoded locations
swig_inc_args += '-I' + _dir
endforeach
# This is a hack that gets at the location for conda envs, when building with conda compilers.
_cc_incdir = run_command([cc, '-print-sysroot'], check: true).stdout().strip()
if _cc_incdir.contains('bin/../')
swig_inc_args += '-I' + _cc_incdir.split('bin/../')[0] / 'include'
endif
# The above took care of all fixed directories. We also need the default
# compiler search directories, but Meson doesn't expose those.
_umfpack_swig = custom_target('_umfpack_swig',
output: [
'_umfpack_wrap.c',
'_umfpack.py',
],
input: 'umfpack.i',
command: [swig, '-python'] + swig_inc_args + [
'-o', '@OUTPUT0@', '-outdir', '@OUTDIR@', '@INPUT@'],
install: true,
install_dir: py.get_install_dir() / 'scikits/umfpack', # need to install _umfpack.py
install_tag: 'python-runtime',
)
Another way would be to do a compile check like:
#include <umfpack.h>
int main(void) {
return 0;
}
with the compiler-specific flag to echo include paths to stdout, e.g. for GCC the `-H flag (see https://stackoverflow.com/questions/5834778/how-to-tell-where-a-header-file-is-included-from):
$ gcc -H tmp.c $CFLAGS
. /home/rgommers/mambaforge/envs/scipy-dev/include/umfpack.h
.. /home/rgommers/mambaforge/envs/scipy-dev/include/SuiteSparse_config.h
.....
but that's very verbose:
I am using swig I'd like to get support of it in meson. It is not so trivial, but it is possible. I am using it in way: https://github.com/ignatenkobrain/libsmartcols-bindings/blob/master/CMakeLists.txt