From 7df409b66a7b3910fbb74fbbb5460b43a2fd6019 Mon Sep 17 00:00:00 2001 From: SSE4 Date: Tue, 9 Nov 2021 19:18:20 +0700 Subject: [PATCH 1/4] - [MesonToolchain] add backend support Signed-off-by: SSE4 --- conan/tools/meson/toolchain.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index e6294bb06fc..aebafc519e2 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -41,6 +41,7 @@ class MesonToolchain(object): {% if b_ndebug %}b_ndebug = {{b_ndebug}}{% endif %} {% if b_staticpic %}b_staticpic = {{b_staticpic}}{% endif %} {% if cpp_std %}cpp_std = {{cpp_std}}{% endif %} + {% if backend %}backend = {{backend}}{% endif %} c_args = {{c_args}} + preprocessor_definitions c_link_args = {{c_link_args}} cpp_args = {{cpp_args}} + preprocessor_definitions @@ -66,8 +67,9 @@ class MesonToolchain(object): endian = {{endian}} """) - def __init__(self, conanfile): + def __init__(self, conanfile, backend=None): self._conanfile = conanfile + self._backend = self._get_backend(backend) self._build_type = self._conanfile.settings.get_safe("build_type") self._base_compiler = self._conanfile.settings.get_safe("compiler.base") or \ self._conanfile.settings.get_safe("compiler") @@ -99,6 +101,7 @@ def from_build_env(name): self.buildtype = self._to_meson_build_type(self._build_type) if self._build_type else None self.default_library = self._to_meson_shared(self._shared) \ if self._shared is not None else None + self.backend = self._to_meson_value(self._backend) # https://mesonbuild.com/Builtin-options.html#base-options self.b_vscrt = self._to_meson_vscrt(self._vscrt) @@ -117,6 +120,19 @@ def from_build_env(name): check_using_build_profile(self._conanfile) + def _get_backend(self, recipe_backend): + # Returns the name of the backend used by Meson + conanfile = self._conanfile + # Downstream consumer always higher priority + backend_conf = conanfile.conf["tools.meson.mesontoolchain:backend"] + if backend_conf: + return backend_conf + # second priority: the recipe one: + if recipe_backend: + return recipe_backend + # if not defined, deduce automatically the default one (ninja) + return 'ninja' + @staticmethod def _to_meson_value(value): # https://mesonbuild.com/Machine-files.html#data-types @@ -211,6 +227,7 @@ def _context(self): # https://mesonbuild.com/Builtin-options.html#core-options "buildtype": self.buildtype, "default_library": self.default_library, + "backend": self.backend, # https://mesonbuild.com/Builtin-options.html#base-options "b_vscrt": self.b_vscrt, "b_staticpic": self.b_staticpic, From 7b05987314392e6ce3d26daa3bf1fa5cfbf62ae4 Mon Sep 17 00:00:00 2001 From: SSE4 Date: Wed, 10 Nov 2021 18:13:07 +0700 Subject: [PATCH 2/4] - add test Signed-off-by: SSE4 --- .../toolchains/meson/test_backend.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 conans/test/functional/toolchains/meson/test_backend.py diff --git a/conans/test/functional/toolchains/meson/test_backend.py b/conans/test/functional/toolchains/meson/test_backend.py new file mode 100644 index 00000000000..7aef0a10210 --- /dev/null +++ b/conans/test/functional/toolchains/meson/test_backend.py @@ -0,0 +1,55 @@ +import os +import platform +import sys +import textwrap + +import pytest + +from conans.test.assets.sources import gen_function_cpp +from conans.test.utils.tools import TestClient + +@pytest.mark.tool_meson +@pytest.mark.skipif(sys.version_info.major == 2, reason="Meson not supported in Py2") +@pytest.mark.skipif(platform.system() != "Windows", reason="requires Windows") +def test_cross_x86(): + conanfile_py = textwrap.dedent(""" + from conans import ConanFile, tools + from conan.tools.meson import Meson, MesonToolchain + + + class App(ConanFile): + settings = "os", "arch", "compiler", "build_type" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def generate(self): + tc = MesonToolchain(self, backend='vs') + tc.generate() + + def build(self): + meson = Meson(self) + meson.configure() + meson.build() + """) + meson_build = textwrap.dedent(""" + project('tutorial', 'cpp') + executable('demo', 'main.cpp') + """) + main_cpp = gen_function_cpp(name="main") + client = TestClient() + client.save({"conanfile.py": conanfile_py, + "meson.build": meson_build, + "main.cpp": main_cpp}) + client.run("install .") + content = client.load("conan_meson_native.ini") + assert "backend = 'vs'" in content + client.run("build .") + client.run_command(os.path.join("build", "demo")) + + assert "main _M_X64 defined" in client.out + assert "main _MSC_VER19" in client.out + assert "main _MSVC_LANG2014" in client.out From 2d00e36bfdd073e284150cfc2a716e7e7a8e82bb Mon Sep 17 00:00:00 2001 From: SSE4 Date: Tue, 16 Nov 2021 22:16:48 +0700 Subject: [PATCH 3/4] - move Signed-off-by: SSE4 --- conans/test/integration/toolchains/meson/__init__.py | 0 .../toolchains/meson/test_backend.py | 6 ------ 2 files changed, 6 deletions(-) create mode 100644 conans/test/integration/toolchains/meson/__init__.py rename conans/test/{functional => integration}/toolchains/meson/test_backend.py (87%) diff --git a/conans/test/integration/toolchains/meson/__init__.py b/conans/test/integration/toolchains/meson/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/test/functional/toolchains/meson/test_backend.py b/conans/test/integration/toolchains/meson/test_backend.py similarity index 87% rename from conans/test/functional/toolchains/meson/test_backend.py rename to conans/test/integration/toolchains/meson/test_backend.py index 7aef0a10210..6469c3bffcd 100644 --- a/conans/test/functional/toolchains/meson/test_backend.py +++ b/conans/test/integration/toolchains/meson/test_backend.py @@ -47,9 +47,3 @@ def build(self): client.run("install .") content = client.load("conan_meson_native.ini") assert "backend = 'vs'" in content - client.run("build .") - client.run_command(os.path.join("build", "demo")) - - assert "main _M_X64 defined" in client.out - assert "main _MSC_VER19" in client.out - assert "main _MSVC_LANG2014" in client.out From db86de26adafd13a8efd1fce3ae02fe679b58f53 Mon Sep 17 00:00:00 2001 From: memsharded Date: Tue, 16 Nov 2021 17:30:57 +0100 Subject: [PATCH 4/4] fixed wrong develop2 merge, added test check for VS backend --- conans/test/integration/toolchains/meson/test_backend.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/conans/test/integration/toolchains/meson/test_backend.py b/conans/test/integration/toolchains/meson/test_backend.py index 6469c3bffcd..8f3f6024ab4 100644 --- a/conans/test/integration/toolchains/meson/test_backend.py +++ b/conans/test/integration/toolchains/meson/test_backend.py @@ -8,6 +8,7 @@ from conans.test.assets.sources import gen_function_cpp from conans.test.utils.tools import TestClient + @pytest.mark.tool_meson @pytest.mark.skipif(sys.version_info.major == 2, reason="Meson not supported in Py2") @pytest.mark.skipif(platform.system() != "Windows", reason="requires Windows") @@ -47,3 +48,10 @@ def build(self): client.run("install .") content = client.load("conan_meson_native.ini") assert "backend = 'vs'" in content + client.run("build .") + assert "Auto detected Visual Studio backend" in client.out + client.run_command(os.path.join("build", "demo")) + + assert "main _M_X64 defined" in client.out + assert "main _MSC_VER19" in client.out + assert "main _MSVC_LANG2014" in client.out