From 55bf9a9c1d5cba98e24457d0ba62e77f88852def Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 12 Jan 2024 14:20:27 +0100 Subject: [PATCH] feat: `use_fmtlib` Conan option added --- conanfile.py | 15 +++++---------- docs/getting_started/installation_and_usage.md | 13 +++++++++++-- test_package/conanfile.py | 11 +++-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/conanfile.py b/conanfile.py index b2a8938a..d5f1e0df 100644 --- a/conanfile.py +++ b/conanfile.py @@ -56,9 +56,11 @@ class MPUnitsConan(ConanFile): settings = "os", "arch", "compiler", "build_type" options = { "cxx_modules": [True, False], + "use_fmtlib": [True, False], } default_options = { "cxx_modules": False, + "use_fmtlib": True, } tool_requires = "cmake/[>=3.28.1]" exports = ["LICENSE.md"] @@ -94,13 +96,6 @@ class MPUnitsConan(ConanFile): def _skip_la(self): return bool(self.conf.get("user.build:skip_la", default=False)) - @property - def _use_libfmt(self): - compiler = self.settings.compiler - version = Version(self.settings.compiler.version) - std_support = compiler == "msvc" and version >= 193 and compiler.cppstd == 23 - return not std_support - def set_version(self): content = load(self, os.path.join(self.recipe_folder, "src/CMakeLists.txt")) version = re.search( @@ -110,7 +105,7 @@ class MPUnitsConan(ConanFile): def requirements(self): self.requires("gsl-lite/0.41.0") - if self._use_libfmt: + if self.options.use_fmtlib: self.requires("fmt/10.2.1") def build_requirements(self): @@ -146,7 +141,7 @@ class MPUnitsConan(ConanFile): tc.variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True tc.variables["MP_UNITS_BUILD_CXX_MODULES"] = True tc.variables["MP_UNITS_BUILD_LA"] = self._build_all and not self._skip_la - tc.variables["MP_UNITS_USE_FMTLIB"] = self._use_libfmt + tc.variables["MP_UNITS_USE_FMTLIB"] = bool(self.options.use_fmtlib) tc.generate() deps = CMakeDeps(self) deps.generate() @@ -176,7 +171,7 @@ class MPUnitsConan(ConanFile): def package_info(self): compiler = self.settings.compiler self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"] - if self._use_libfmt: + if self.options.use_fmtlib: self.cpp_info.components["core"].requires.append("fmt::fmt") if compiler == "msvc": self.cpp_info.components["core"].cxxflags = ["/utf-8"] diff --git a/docs/getting_started/installation_and_usage.md b/docs/getting_started/installation_and_usage.md index c8c3730d..6e36413b 100644 --- a/docs/getting_started/installation_and_usage.md +++ b/docs/getting_started/installation_and_usage.md @@ -181,7 +181,16 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} Configures CMake to add C++ modules to the list of default targets. -[cxx modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 + [cxx modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 + +[use_fmtlib](#use_fmtlib){ #use_fmtlib } + +: [:octicons-tag-24: 2.2.0][use fmtlib support] ยท :octicons-milestone-24: `True`/`False` (Default: `True`) + + Forces usage of [{fmt}](https://github.com/fmtlib/fmt) library instead of the C++20 Standard + Library features. + + [use fmtlib support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 ### Conan configuration properties @@ -195,7 +204,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [`tools.build:skip_test`](https://docs.conan.io/2/reference/commands/config.html?highlight=tools.build:skip_test#conan-config-list) configuration property is set to `True`). -[build all support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0 + [build all support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0 [`user.build:skip_la`](#user-skip-la){ #user-skip-la } diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 0a870a02..4234d8cd 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -32,13 +32,6 @@ class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" generators = "CMakeDeps" - @property - def _use_libfmt(self): - compiler = self.settings.compiler - version = Version(self.settings.compiler.version) - std_support = compiler == "msvc" and version >= 193 and compiler.cppstd == 23 - return not std_support - def requirements(self): self.requires(self.tested_reference_str) @@ -47,7 +40,9 @@ class TestPackageConan(ConanFile): def generate(self): tc = CMakeToolchain(self) - tc.variables["MP_UNITS_USE_FMTLIB"] = self._use_libfmt + tc.variables["MP_UNITS_USE_FMTLIB"] = bool( + self.dependencies["mp-units"].options.use_fmtlib + ) tc.generate() def build(self):