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