Skip to content

Commit

Permalink
(conan-io#20645) Update meson test package
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jwillikers authored Oct 19, 2023
1 parent 5c336a5 commit 9b6a15f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 18 additions & 14 deletions docs/package_templates/meson_package/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -82,24 +86,22 @@ 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.")

# 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)
Expand All @@ -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()
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9b6a15f

Please sign in to comment.