diff options
| author | gjaeger1 <jaegergeorg@web.de> | 2019-07-10 23:30:58 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-07-11 00:30:58 +0300 |
| commit | 30e42009c03cbb53e3462e1c4ee29af666474742 (patch) | |
| tree | aaae8ad451e31b7ff72a685bdbb3525616241005 /test cases/frameworks | |
| parent | 748c9d817d8b6a0bb79eeba6256370db777754f4 (diff) | |
| download | meson-30e42009c03cbb53e3462e1c4ee29af666474742.tar.gz | |
Adapting Boost Python library detection to Boost >= 1.67. Closes #4288.
Diffstat (limited to 'test cases/frameworks')
| -rw-r--r-- | test cases/frameworks/1 boost/meson.build | 53 | ||||
| -rw-r--r-- | test cases/frameworks/1 boost/python_module.cpp | 22 | ||||
| -rw-r--r-- | test cases/frameworks/1 boost/test_python_module.py | 27 |
3 files changed, 102 insertions, 0 deletions
diff --git a/test cases/frameworks/1 boost/meson.build b/test cases/frameworks/1 boost/meson.build index 1d2945587..8f45dc7fe 100644 --- a/test cases/frameworks/1 boost/meson.build +++ b/test cases/frameworks/1 boost/meson.build @@ -26,18 +26,71 @@ testdep = dependency('boost', modules : ['unit_test_framework']) nomoddep = dependency('boost') extralibdep = dependency('boost', modules : ['thread', 'system', 'log_setup', 'log']) +pymod = import('python') +python2 = pymod.find_installation('python2', required: host_machine.system() == 'linux', disabler: true) +python3 = pymod.find_installation('python3', required: host_machine.system() == 'linux', disabler: true) +python2dep = python2.dependency(required: host_machine.system() == 'linux', disabler: true) +python3dep = python3.dependency(required: host_machine.system() == 'linux', disabler: true) + +# compile python 2/3 modules only if we found a corresponding python version +if(python2dep.found() and host_machine.system() == 'linux') + if(dep.version().version_compare('>=1.67')) + # if we have a new version of boost, we need to construct the module name based + # on the installed version of python (and hope that they match the version boost + # was compiled against) + py2version_string = ''.join(python2dep.version().split('.')) + bpython2dep = dependency('boost', modules : ['python' + py2version_string]) + else + # if we have an older version of boost, we need to use the old module names + bpython2dep = dependency('boost', modules : ['python']) + endif + + if not (bpython2dep.found()) + bpython2dep = disabler() + endif +else + python2dep = disabler() + bpython2dep = disabler() +endif + +if(python3dep.found() and host_machine.system() == 'linux') + if(dep.version().version_compare('>=1.67')) + py3version_string = ''.join(python3dep.version().split('.')) + bpython3dep = dependency('boost', modules : ['python' + py3version_string]) + else + bpython3dep = dependency('boost', modules : ['python3']) + endif + + if not (bpython3dep.found()) + bpython3dep = disabler() + endif +else + python3dep = disabler() + bpython3dep = disabler() +endif + linkexe = executable('linkedexe', 'linkexe.cc', dependencies : linkdep) staticexe = executable('staticlinkedexe', 'linkexe.cc', dependencies : staticdep) unitexe = executable('utf', 'unit_test.cpp', dependencies: testdep) nomodexe = executable('nomod', 'nomod.cpp', dependencies : nomoddep) extralibexe = executable('extralibexe', 'extralib.cpp', dependencies : extralibdep) +# python modules are shared libraries +python2module = shared_library('python2_module', ['python_module.cpp'], dependencies: [python2dep, bpython2dep], name_prefix: '', cpp_args: ['-DMOD_NAME=python2_module']) +python3module = shared_library('python3_module', ['python_module.cpp'], dependencies: [python3dep, bpython3dep], name_prefix: '', cpp_args: ['-DMOD_NAME=python3_module']) + test('Boost linktest', linkexe) test('Boost statictest', staticexe) test('Boost UTF test', unitexe) test('Boost nomod', nomodexe) test('Boost extralib test', extralibexe) +# explicitly use the correct python interpreter so that we don't have to provide two different python scripts that have different shebang lines +python2interpreter = find_program(python2.path(), required: false, disabler: true) +test('Boost Python2', python2interpreter, args: ['./test_python_module.py', meson.current_build_dir()], workdir: meson.current_source_dir(), depends: python2module) +python3interpreter = find_program(python3.path(), required: false, disabler: true) +test('Boost Python3', python3interpreter, args: ['./test_python_module.py', meson.current_build_dir()], workdir: meson.current_source_dir(), depends: python2module) + subdir('partial_dep') # check we can apply a version constraint diff --git a/test cases/frameworks/1 boost/python_module.cpp b/test cases/frameworks/1 boost/python_module.cpp new file mode 100644 index 000000000..a0f010b51 --- /dev/null +++ b/test cases/frameworks/1 boost/python_module.cpp @@ -0,0 +1,22 @@ +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include <boost/python.hpp> + +struct World +{ + void set(std::string msg) { this->msg = msg; } + std::string greet() { return msg; } + std::string version() { return std::to_string(PY_MAJOR_VERSION) + "." + std::to_string(PY_MINOR_VERSION); } + std::string msg; +}; + + +BOOST_PYTHON_MODULE(MOD_NAME) +{ + using namespace boost::python; + class_<World>("World") + .def("greet", &World::greet) + .def("set", &World::set) + .def("version", &World::version) + ; +} diff --git a/test cases/frameworks/1 boost/test_python_module.py b/test cases/frameworks/1 boost/test_python_module.py new file mode 100644 index 000000000..acf6e42d6 --- /dev/null +++ b/test cases/frameworks/1 boost/test_python_module.py @@ -0,0 +1,27 @@ +import sys +sys.path.append(sys.argv[1]) + +# import compiled python module depending on version of python we are running with +if sys.version_info[0] == 2: + import python2_module + +if sys.version_info[0] == 3: + import python3_module + + +def run(): + msg = 'howdy' + if sys.version_info[0] == 2: + w = python2_module.World() + + if sys.version_info[0] == 3: + w = python3_module.World() + + w.set(msg) + + assert(msg == w.greet()) + version_string = str(sys.version_info[0]) + "." + str(sys.version_info[1]) + assert(version_string == w.version()) + +if __name__ == '__main__': + run() |
