mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 18:37:15 +02:00
build: recipes updated to Conan 2.0
This commit is contained in:
101
conanfile.py
101
conanfile.py
@ -24,19 +24,19 @@ import os
|
||||
import re
|
||||
|
||||
from conan import ConanFile
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.build import check_min_cppstd
|
||||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
|
||||
from conan.tools.files import copy, load, rmdir
|
||||
from conan.tools.scm import Version
|
||||
from conans.errors import ConanInvalidConfiguration
|
||||
|
||||
required_conan_version = ">=1.50.0"
|
||||
required_conan_version = ">=2.0.0"
|
||||
|
||||
|
||||
class MPUnitsConan(ConanFile):
|
||||
name = "mp-units"
|
||||
homepage = "https://github.com/mpusz/units"
|
||||
description = "Physical Units library for C++"
|
||||
description = "Physical Quantities and Units library for C++"
|
||||
topics = (
|
||||
"units",
|
||||
"dimensions",
|
||||
@ -45,14 +45,15 @@ class MPUnitsConan(ConanFile):
|
||||
"physical-quantities",
|
||||
"physical-units",
|
||||
"system-of-units",
|
||||
"cpp23",
|
||||
"cpp20",
|
||||
"system-of-quantities",
|
||||
"isq",
|
||||
"si",
|
||||
"library",
|
||||
"quantity-manipulation",
|
||||
)
|
||||
license = "MIT"
|
||||
url = "https://github.com/mpusz/units"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
requires = "gsl-lite/0.40.0"
|
||||
options = {"downcast_mode": ["off", "on", "auto"]}
|
||||
default_options = {"downcast_mode": "on"}
|
||||
@ -66,23 +67,39 @@ class MPUnitsConan(ConanFile):
|
||||
"CMakeLists.txt",
|
||||
]
|
||||
no_copy_source = True
|
||||
generators = "cmake_paths"
|
||||
|
||||
@property
|
||||
def _min_cppstd(self):
|
||||
return "20"
|
||||
|
||||
@property
|
||||
def _minimum_compilers_version(self):
|
||||
return {"gcc": "10.3", "clang": "12", "apple-clang": "13", "msvc": "1928"}
|
||||
|
||||
@property
|
||||
def _full_compiler_version(self):
|
||||
compiler = self.settings.compiler
|
||||
if compiler == "msvc":
|
||||
if compiler.update:
|
||||
return int(f"{compiler.version}{compiler.update}")
|
||||
else:
|
||||
return int(f"{compiler.version}0")
|
||||
else:
|
||||
return compiler.version
|
||||
|
||||
@property
|
||||
def _build_all(self):
|
||||
return bool(self.conf["user.build:all"])
|
||||
return bool(self.conf.get("user.build:all", default=True))
|
||||
|
||||
@property
|
||||
def _skip_docs(self):
|
||||
return bool(self.conf["user.build:skip_docs"])
|
||||
return bool(self.conf.get("user.build:skip_docs", default=True))
|
||||
|
||||
@property
|
||||
def _use_libfmt(self):
|
||||
compiler = self.settings.compiler
|
||||
version = Version(self.settings.compiler.version)
|
||||
std_support = (
|
||||
compiler == "Visual Studio" and version >= 17 and compiler.cppstd == 23
|
||||
) or (compiler == "msvc" and version >= 193 and compiler.cppstd == 23)
|
||||
std_support = compiler == "msvc" and version >= 193 and compiler.cppstd == 23
|
||||
return not std_support
|
||||
|
||||
@property
|
||||
@ -91,14 +108,6 @@ class MPUnitsConan(ConanFile):
|
||||
version = Version(self.settings.compiler.version)
|
||||
return "clang" in compiler and compiler.libcxx == "libc++" and version < 14
|
||||
|
||||
@property
|
||||
def _msvc_version(self):
|
||||
compiler = self.settings.compiler
|
||||
if compiler.update:
|
||||
return int(f"{compiler.version}{compiler.update}")
|
||||
else:
|
||||
return int(f"{compiler.version}0")
|
||||
|
||||
def set_version(self):
|
||||
content = load(self, os.path.join(self.recipe_folder, "src/CMakeLists.txt"))
|
||||
version = re.search(
|
||||
@ -109,43 +118,35 @@ class MPUnitsConan(ConanFile):
|
||||
def requirements(self):
|
||||
if self._use_libfmt:
|
||||
self.requires("fmt/8.1.1")
|
||||
|
||||
if self._use_range_v3:
|
||||
self.requires("range-v3/0.11.0")
|
||||
|
||||
def build_requirements(self):
|
||||
if self._build_all:
|
||||
self.test_requires("catch2/3.1.0")
|
||||
self.test_requires("wg21-linear_algebra/0.7.2")
|
||||
if not self._skip_docs:
|
||||
self.tool_requires("doxygen/1.9.4")
|
||||
# TODO uncomment the below when recipes in ConanCenter are fixed
|
||||
# self.test_requires("wg21-linear_algebra/0.7.2")
|
||||
# if not self._skip_docs:
|
||||
# self.tool_requires("doxygen/1.9.4")
|
||||
|
||||
def validate(self):
|
||||
if self.settings.get_safe("compiler.cppstd"):
|
||||
check_min_cppstd(self, self._min_cppstd)
|
||||
|
||||
def loose_lt_semver(v1, v2):
|
||||
lv1 = [int(v) for v in v1.split(".")]
|
||||
lv2 = [int(v) for v in v2.split(".")]
|
||||
min_length = min(len(lv1), len(lv2))
|
||||
return lv1[:min_length] < lv2[:min_length]
|
||||
|
||||
# TODO Replace with `valdate()` for Conan 2.0 (https://github.com/conan-io/conan/issues/10723)
|
||||
def configure(self):
|
||||
compiler = self.settings.compiler
|
||||
version = Version(self.settings.compiler.version)
|
||||
if compiler == "gcc":
|
||||
if version < 10:
|
||||
raise ConanInvalidConfiguration("mp-units requires at least g++-10")
|
||||
elif compiler == "clang":
|
||||
if version < 12:
|
||||
raise ConanInvalidConfiguration("mp-units requires at least clang++-12")
|
||||
elif compiler == "apple-clang":
|
||||
if version < 13:
|
||||
raise ConanInvalidConfiguration(
|
||||
"mp-units requires at least AppleClang 13"
|
||||
)
|
||||
elif compiler == "Visual Studio":
|
||||
if version < 16:
|
||||
raise ConanInvalidConfiguration(
|
||||
"mp-units requires at least Visual Studio 16.9"
|
||||
)
|
||||
elif compiler == "msvc":
|
||||
if self._msvc_version < 1928:
|
||||
raise ConanInvalidConfiguration("mp-units requires at least MSVC 19.28")
|
||||
else:
|
||||
raise ConanInvalidConfiguration("Unsupported compiler")
|
||||
check_min_cppstd(self, 20)
|
||||
min_version = self._minimum_compilers_version.get(str(compiler))
|
||||
if min_version and loose_lt_semver(
|
||||
str(self._full_compiler_version), min_version
|
||||
):
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.ref} requires at least {compiler} {min_version}"
|
||||
)
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
@ -187,7 +188,7 @@ class MPUnitsConan(ConanFile):
|
||||
|
||||
# core
|
||||
self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"]
|
||||
if compiler == "Visual Studio":
|
||||
if compiler == "msvc":
|
||||
self.cpp_info.components["core"].cxxflags = ["/utf-8"]
|
||||
if self._use_range_v3:
|
||||
self.cpp_info.components["core"].requires.append("range-v3::range-v3")
|
||||
|
@ -23,28 +23,26 @@
|
||||
import os
|
||||
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import cross_building
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv"
|
||||
apply_env = False
|
||||
test_type = "explicit" # TODO Remove for Conan 2.0
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def test(self):
|
||||
if not cross_building(self):
|
||||
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(cmd, env="conanrun")
|
||||
if can_run(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(bin_path, env="conanrun")
|
||||
|
Reference in New Issue
Block a user