From 9b6a15fd253b91aa1787faf2c8f31857136c2422 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Thu, 19 Oct 2023 02:22:17 -0500 Subject: [PATCH] (#20645) Update meson test package * Alphabetize a little * Update dependencies * Remove pkgconfig directory * Update compiler version checking * Add example for setting a feature in a Meson project * Simplify copy command * Fix fPIC option --- .../meson_package/all/conanfile.py | 32 +++++++++++-------- .../all/test_package/conanfile.py | 4 +-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/package_templates/meson_package/all/conanfile.py b/docs/package_templates/meson_package/all/conanfile.py index ef4bad7fd4d3b..b1861c3dc5b11 100644 --- a/docs/package_templates/meson_package/all/conanfile.py +++ b/docs/package_templates/meson_package/all/conanfile.py @@ -7,7 +7,7 @@ from conan.tools.gnu import PkgConfigDeps from conan.tools.layout import basic_layout from conan.tools.meson import Meson, MesonToolchain -from conan.tools.microsoft import check_min_vs, is_msvc +from conan.tools.microsoft import is_msvc from conan.tools.scm import Version import os @@ -35,10 +35,12 @@ class PackageConan(ConanFile): options = { "shared": [True, False], "fPIC": [True, False], + "feature": [True, False], } default_options = { "shared": False, "fPIC": True, + "feature": True, } @property @@ -49,9 +51,11 @@ def _min_cppstd(self): @property def _compilers_minimum_version(self): return { - "gcc": "7", - "clang": "7", "apple-clang": "10", + "clang": "7", + "gcc": "7", + "msvc": "191", + "Visual Studio": "15", } # no exports_sources attribute, but export_sources(self) method instead @@ -67,8 +71,8 @@ def configure(self): if self.options.shared: self.options.rm_safe("fPIC") # for plain C projects only - self.settings.rm_safe("compiler.libcxx") self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") def layout(self): # src_folder must use the same source folder name the project @@ -82,13 +86,11 @@ def validate(self): # validate the minimum cpp standard supported. For C++ projects only if self.settings.compiler.get_safe("cppstd"): check_min_cppstd(self, self._min_cppstd) - check_min_vs(self, 191) - if not is_msvc(self): - minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) - if minimum_version and Version(self.settings.compiler.version) < minimum_version: - raise ConanInvalidConfiguration( - f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." - ) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) # in case it does not work in another configuration, it should validated here too if is_msvc(self) and self.info.options.shared: raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") @@ -96,10 +98,10 @@ def validate(self): # if another tool than the compiler or Meson is required to build the project (pkgconf, bison, flex etc) def build_requirements(self): # CCI policy assumes that Meson may not be installed on consumers machine - self.tool_requires("meson/0.63.3") + self.tool_requires("meson/1.2.2") # pkgconf is largely used by Meson, it should be added in build requirement when there are dependencies if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str): - self.tool_requires("pkgconf/1.9.3") + self.tool_requires("pkgconf/2.0.3") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -110,6 +112,7 @@ def generate(self): tc = MesonToolchain(self) # In case need to pass definitions directly to the compiler tc.preprocessor_definitions["MYDEFINE"] = "MYDEF_VALUE" + tc.project_options["feature"] = "enabled" if self.options.get_safe("feature") else "disabled" # Meson project options may vary their types tc.project_options["tests"] = False tc.generate() @@ -133,11 +136,12 @@ def build(self): meson.build() def package(self): - copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) meson = Meson(self) meson.install() # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) diff --git a/docs/package_templates/meson_package/all/test_package/conanfile.py b/docs/package_templates/meson_package/all/test_package/conanfile.py index 61b7b28c28d9d..10b1dcc87c7f6 100644 --- a/docs/package_templates/meson_package/all/test_package/conanfile.py +++ b/docs/package_templates/meson_package/all/test_package/conanfile.py @@ -18,9 +18,9 @@ def requirements(self): self.requires(self.tested_reference_str) def build_requirements(self): - self.tool_requires("meson/0.63.3") + self.tool_requires("meson/1.2.2") if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str): - self.tool_requires("pkgconf/1.9.3") + self.tool_requires("pkgconf/2.0.3") def build(self): meson = Meson(self)