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 | |
parent | 748c9d817d8b6a0bb79eeba6256370db777754f4 (diff) | |
download | meson-30e42009c03cbb53e3462e1c4ee29af666474742.zip meson-30e42009c03cbb53e3462e1c4ee29af666474742.tar.gz meson-30e42009c03cbb53e3462e1c4ee29af666474742.tar.bz2 |
Adapting Boost Python library detection to Boost >= 1.67. Closes #4288.
-rw-r--r-- | ciimage/Dockerfile | 1 | ||||
-rw-r--r-- | mesonbuild/dependencies/boost.py | 29 | ||||
-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 |
5 files changed, 120 insertions, 12 deletions
diff --git a/ciimage/Dockerfile b/ciimage/Dockerfile index dc66854..585a6ef 100644 --- a/ciimage/Dockerfile +++ b/ciimage/Dockerfile @@ -23,6 +23,7 @@ RUN sed -i '/^#\sdeb-src /s/^#//' "/etc/apt/sources.list" \ && apt-get -y install libgcrypt11-dev \ && apt-get -y install libgpgme-dev \ && apt-get -y install libhdf5-dev \ +&& apt-get -y install libboost-python-dev \ && dub fetch urld && dub build urld --compiler=gdc \ && dub fetch dubtestproject \ && dub build dubtestproject:test1 --compiler=ldc2 \ diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 5c9e0b5..340a5a9 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -134,22 +134,31 @@ class BoostDependency(ExternalDependency): else: self.incdir = self.detect_nix_incdir() - if self.check_invalid_modules(): - return - mlog.debug('Boost library root dir is', mlog.bold(self.boost_root)) mlog.debug('Boost include directory is', mlog.bold(self.incdir)) # 1. check if we can find BOOST headers. self.detect_headers_and_version() + if not self.is_found: + return # if we can not find 'boost/version.hpp' + # 2. check if we can find BOOST libraries. - if self.is_found: - self.detect_lib_modules() - mlog.debug('Boost library directory is', mlog.bold(self.libdir)) + self.detect_lib_modules() + mlog.debug('Boost library directory is', mlog.bold(self.libdir)) + + mlog.debug('Installed Boost libraries: ') + for key in sorted(self.lib_modules.keys()): + mlog.debug(key, self.lib_modules[key]) + + # 3. check if requested modules are valid, that is, either found or in the list of known boost libraries + self.check_invalid_modules() + + # 4. final check whether or not we find all requested and valid modules + self.check_find_requested_modules() def check_invalid_modules(self): - invalid_modules = [c for c in self.requested_modules if 'boost_' + c not in BOOST_LIBS] + invalid_modules = [c for c in self.requested_modules if 'boost_' + c not in self.lib_modules and 'boost_' + c not in BOOST_LIBS] # previous versions of meson allowed include dirs as modules remove = [] @@ -273,6 +282,7 @@ class BoostDependency(ExternalDependency): else: self.detect_lib_modules_nix() + def check_find_requested_modules(self): # 3. Check if we can find the modules for m in self.requested_modules: if 'boost_' + m not in self.lib_modules: @@ -491,7 +501,6 @@ class BoostDependency(ExternalDependency): def get_sources(self): return [] - # Generated with boost_names.py BOOST_LIBS = [ 'boost_atomic', @@ -547,10 +556,6 @@ BOOST_LIBS = [ 'boost_math_c99l', 'boost_mpi', 'boost_program_options', - 'boost_python', - 'boost_python3', - 'boost_numpy', - 'boost_numpy3', 'boost_random', 'boost_regex', 'boost_serialization', diff --git a/test cases/frameworks/1 boost/meson.build b/test cases/frameworks/1 boost/meson.build index 1d29455..8f45dc7 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 0000000..a0f010b --- /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 0000000..acf6e42 --- /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() |