diff options
Diffstat (limited to 'meson/test cases/frameworks/1 boost')
13 files changed, 321 insertions, 0 deletions
diff --git a/meson/test cases/frameworks/1 boost/extralib.cpp b/meson/test cases/frameworks/1 boost/extralib.cpp new file mode 100644 index 000000000..e5ab1b000 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/extralib.cpp @@ -0,0 +1,27 @@ +#define _XOPEN_SOURCE 500 + +#include <iostream> +#include <boost/log/trivial.hpp> +#include <boost/log/expressions.hpp> +#include <boost/log/utility/setup/console.hpp> +#include <boost/log/utility/setup/common_attributes.hpp> + +using namespace std; +namespace logging = boost::log; + +void InitLogger() { + logging::add_common_attributes(); + logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity"); + string log_format = "%TimeStamp% [%Severity%] - %Message%"; + + logging::add_console_log( + cout, + logging::keywords::format = log_format + ); +} + +int main(int argc, char **argv) { + InitLogger(); + BOOST_LOG_TRIVIAL(trace) << "SOMETHING"; + return 0; +} diff --git a/meson/test cases/frameworks/1 boost/linkexe.cc b/meson/test cases/frameworks/1 boost/linkexe.cc new file mode 100644 index 000000000..e00edee19 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/linkexe.cc @@ -0,0 +1,18 @@ +#define _XOPEN_SOURCE 500 + +#include<boost/thread.hpp> + +boost::recursive_mutex m; + +struct callable { + void operator()() { + boost::recursive_mutex::scoped_lock l(m); + }; +}; + +int main(int argc, char **argv) { + callable x; + boost::thread thr(x); + thr.join(); + return 0; +} diff --git a/meson/test cases/frameworks/1 boost/meson.build b/meson/test cases/frameworks/1 boost/meson.build new file mode 100644 index 000000000..83570f09f --- /dev/null +++ b/meson/test cases/frameworks/1 boost/meson.build @@ -0,0 +1,72 @@ +# this test requires the following on Ubuntu: libboost-{system,python,log,thread,test}-dev +project('boosttest', 'cpp', + default_options : ['cpp_std=c++14']) + +s = get_option('static') + +dep = dependency('boost', static: s, required: false) +if not dep.found() + error('MESON_SKIP_TEST boost not found.') +endif + +# We want to have multiple separate configurations of Boost +# within one project. The need to be independent of each other. +# Use one without a library dependency and one with it. + +linkdep = dependency('boost', static: s, modules : ['thread', 'system', 'date_time']) +testdep = dependency('boost', static: s, modules : ['unit_test_framework']) +nomoddep = dependency('boost', static: s) +extralibdep = dependency('boost', static: s, modules : ['thread', 'system', 'date_time', 'log_setup', 'log', 'filesystem', 'regex']) +notfound = dependency('boost', static: s, modules : ['this_should_not_exist_on_any_systen'], required: false) + +assert(not notfound.found()) + +pymod = import('python') +python2 = pymod.find_installation('python2', required: false , disabler: true) +python3 = pymod.find_installation('python3', required: host_machine.system() == 'linux', disabler: true) +python2dep = python2.dependency(required: false , embed: true, disabler: true) +python3dep = python3.dependency(required: host_machine.system() == 'linux', embed: true, disabler: true) + +# compile python 2/3 modules only if we found a corresponding python version +if(python2dep.found() and host_machine.system() == 'linux' and not s) + bpython2dep = dependency('boost', static: s, modules : ['python'], required: false, disabler: true) +else + python2dep = disabler() + bpython2dep = disabler() +endif + +if(python3dep.found() and host_machine.system() == 'linux' and not s) + bpython3dep = dependency('boost', static: s, modules : ['python3']) +else + python3dep = disabler() + bpython3dep = disabler() +endif + +linkexe = executable('linkedexe', 'linkexe.cc', dependencies : linkdep) +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, timeout: 60) +test('Boost UTF test', unitexe, timeout: 60) +test('Boost nomod', nomodexe) +if host_machine.system() != 'darwin' or s + # Segfaults on macOS with dynamic linking since Boost 1.73 + # https://github.com/mesonbuild/meson/issues/7535 + test('Boost extralib test', extralibexe) +endif + +# 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: python3module) + +subdir('partial_dep') + +# check we can apply a version constraint +dependency('boost', static: s, version: '>=@0@'.format(dep.version())) diff --git a/meson/test cases/frameworks/1 boost/meson_options.txt b/meson/test cases/frameworks/1 boost/meson_options.txt new file mode 100644 index 000000000..019feaf38 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/meson_options.txt @@ -0,0 +1 @@ +option('static', type: 'boolean', value: false) diff --git a/meson/test cases/frameworks/1 boost/nomod.cpp b/meson/test cases/frameworks/1 boost/nomod.cpp new file mode 100644 index 000000000..55c95b25c --- /dev/null +++ b/meson/test cases/frameworks/1 boost/nomod.cpp @@ -0,0 +1,18 @@ +#include<boost/any.hpp> +#include<iostream> + +boost::any get_any() { + boost::any foobar = 3; + return foobar; +} + +int main(int argc, char **argv) { + boost::any result = get_any(); + if(boost::any_cast<int>(result) == 3) { + std::cout << "Everything is fine in the world.\n"; + return 0; + } else { + std::cout << "Mathematics stopped working.\n"; + return 1; + } +} diff --git a/meson/test cases/frameworks/1 boost/partial_dep/foo.cpp b/meson/test cases/frameworks/1 boost/partial_dep/foo.cpp new file mode 100644 index 000000000..da5870386 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/partial_dep/foo.cpp @@ -0,0 +1,20 @@ +/* Copyright © 2018 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo.hpp" + +vec Foo::vector() { + return myvec; +} diff --git a/meson/test cases/frameworks/1 boost/partial_dep/foo.hpp b/meson/test cases/frameworks/1 boost/partial_dep/foo.hpp new file mode 100644 index 000000000..393d3f69e --- /dev/null +++ b/meson/test cases/frameworks/1 boost/partial_dep/foo.hpp @@ -0,0 +1,27 @@ +/* Copyright © 2018 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <boost/fusion/container/vector.hpp> + +typedef boost::fusion::vector<int> vec; + + +class Foo { + public: + Foo() {}; + vec vector(); + private: + const vec myvec = vec(4); +}; diff --git a/meson/test cases/frameworks/1 boost/partial_dep/main.cpp b/meson/test cases/frameworks/1 boost/partial_dep/main.cpp new file mode 100644 index 000000000..f31c5ec75 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/partial_dep/main.cpp @@ -0,0 +1,28 @@ +/* Copyright © 2018 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <iostream> +#include <boost/fusion/include/at_c.hpp> +#include "foo.hpp" + + +int main(void) { + auto foo = Foo(); + vec v = foo.vector(); + std::cout << boost::fusion::at_c<0>(v) << std::endl; + + return 0; +} + diff --git a/meson/test cases/frameworks/1 boost/partial_dep/meson.build b/meson/test cases/frameworks/1 boost/partial_dep/meson.build new file mode 100644 index 000000000..9d481bbfe --- /dev/null +++ b/meson/test cases/frameworks/1 boost/partial_dep/meson.build @@ -0,0 +1,31 @@ +# Copyright © 2018 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +dep_boost = dependency('boost') +dep_boost_headers = dep_boost.partial_dependency(compile_args : true) + +libfoo = static_library( + 'foo', + 'foo.cpp', + dependencies : dep_boost_headers, +) + +exe_external_dep = executable( + 'external_dep', + 'main.cpp', + dependencies : dep_boost, + link_with : libfoo +) + +test('External Dependency', exe_external_dep) diff --git a/meson/test cases/frameworks/1 boost/python_module.cpp b/meson/test cases/frameworks/1 boost/python_module.cpp new file mode 100644 index 000000000..a0f010b51 --- /dev/null +++ b/meson/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/meson/test cases/frameworks/1 boost/test.json b/meson/test cases/frameworks/1 boost/test.json new file mode 100644 index 000000000..3145c80d2 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/test.json @@ -0,0 +1,21 @@ +{ + "matrix": { + "options": { + "static": [ + { "val": "true", "skip_on_env": [ "SKIP_STATIC_BOOST" ] }, + { "val": "false" } + ], + "b_vscrt": [ + { "val": null }, + { "val": "md", "compilers": { "cpp": "msvc" } }, + { "val": "mdd", "compilers": { "cpp": "msvc" } }, + { "val": "mt", "compilers": { "cpp": "msvc" } }, + { "val": "mtd", "compilers": { "cpp": "msvc" } } + ] + }, + "exclude": [ + { "static": "false", "b_vscrt": "mt" }, + { "static": "false", "b_vscrt": "mtd" } + ] + } +} diff --git a/meson/test cases/frameworks/1 boost/test_python_module.py b/meson/test cases/frameworks/1 boost/test_python_module.py new file mode 100644 index 000000000..acf6e42d6 --- /dev/null +++ b/meson/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() diff --git a/meson/test cases/frameworks/1 boost/unit_test.cpp b/meson/test cases/frameworks/1 boost/unit_test.cpp new file mode 100644 index 000000000..fa1fbaa58 --- /dev/null +++ b/meson/test cases/frameworks/1 boost/unit_test.cpp @@ -0,0 +1,9 @@ +#define BOOST_TEST_MODULE "MesonTest" +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> + +BOOST_AUTO_TEST_CASE(m_test) { + int x = 2+2; + BOOST_CHECK(true); + BOOST_CHECK_EQUAL(x, 4); +} |