2019-04-04 10:34:58 +02:00
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018 Mateusz Pusz
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2022-05-12 14:00:18 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2022-05-05 09:46:35 +02:00
|
|
|
from conan import ConanFile
|
2023-05-26 13:53:52 +02:00
|
|
|
from conan.errors import ConanInvalidConfiguration
|
2022-07-26 09:53:26 +02:00
|
|
|
from conan.tools.build import check_min_cppstd
|
2022-08-01 18:29:03 +02:00
|
|
|
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
|
2022-05-05 19:18:19 +02:00
|
|
|
from conan.tools.files import copy, load, rmdir
|
|
|
|
from conan.tools.scm import Version
|
2022-05-12 17:10:11 +02:00
|
|
|
|
2023-05-26 13:53:52 +02:00
|
|
|
required_conan_version = ">=2.0.0"
|
2019-04-10 17:12:24 +01:00
|
|
|
|
2022-04-15 16:56:48 +02:00
|
|
|
|
2022-03-14 19:26:43 +01:00
|
|
|
class MPUnitsConan(ConanFile):
|
2019-04-07 08:33:13 +02:00
|
|
|
name = "mp-units"
|
2023-06-16 09:39:49 +03:00
|
|
|
homepage = "https://github.com/mpusz/mp-units"
|
2023-12-09 20:10:06 +01:00
|
|
|
description = "A Quantities and Units library for C++"
|
2022-04-15 16:56:48 +02:00
|
|
|
topics = (
|
|
|
|
"units",
|
|
|
|
"dimensions",
|
|
|
|
"quantities",
|
|
|
|
"dimensional-analysis",
|
|
|
|
"physical-quantities",
|
|
|
|
"physical-units",
|
|
|
|
"system-of-units",
|
2023-05-26 13:53:52 +02:00
|
|
|
"system-of-quantities",
|
|
|
|
"isq",
|
|
|
|
"si",
|
2022-04-15 16:56:48 +02:00
|
|
|
"library",
|
|
|
|
"quantity-manipulation",
|
|
|
|
)
|
2020-09-06 00:00:06 +02:00
|
|
|
license = "MIT"
|
2023-06-16 09:39:49 +03:00
|
|
|
url = "https://github.com/mpusz/mp-units"
|
2023-05-26 13:53:52 +02:00
|
|
|
settings = "os", "arch", "compiler", "build_type"
|
2020-09-06 00:00:06 +02:00
|
|
|
exports = ["LICENSE.md"]
|
2022-05-12 13:58:32 +02:00
|
|
|
exports_sources = [
|
|
|
|
"docs/*",
|
|
|
|
"src/*",
|
|
|
|
"test/*",
|
|
|
|
"cmake/*",
|
|
|
|
"example/*",
|
|
|
|
"CMakeLists.txt",
|
|
|
|
]
|
2023-05-26 13:53:52 +02:00
|
|
|
package_type = "header-library"
|
2022-05-05 11:54:23 +02:00
|
|
|
no_copy_source = True
|
2023-05-26 13:53:52 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def _min_cppstd(self):
|
|
|
|
return "20"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _minimum_compilers_version(self):
|
2023-08-26 20:05:09 +02:00
|
|
|
return {
|
2023-12-22 18:42:29 +01:00
|
|
|
"gcc": "12",
|
2023-12-08 14:29:24 +01:00
|
|
|
"clang": "16",
|
|
|
|
"apple-clang": "15"
|
|
|
|
# , "msvc": "192"
|
2023-08-26 20:05:09 +02:00
|
|
|
}
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2019-11-20 16:33:50 -03:00
|
|
|
@property
|
2022-08-02 17:09:05 +02:00
|
|
|
def _build_all(self):
|
2023-05-26 13:53:52 +02:00
|
|
|
return bool(self.conf.get("user.build:all", default=False))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _skip_la(self):
|
2023-06-12 11:47:30 +03:00
|
|
|
return bool(self.conf.get("user.build:skip_la", default=False))
|
2022-08-02 17:09:05 +02:00
|
|
|
|
2021-09-20 15:01:58 +02:00
|
|
|
@property
|
|
|
|
def _use_libfmt(self):
|
2021-11-15 16:28:26 +01:00
|
|
|
compiler = self.settings.compiler
|
|
|
|
version = Version(self.settings.compiler.version)
|
2023-05-26 13:53:52 +02:00
|
|
|
std_support = compiler == "msvc" and version >= 193 and compiler.cppstd == 23
|
2021-11-15 16:28:26 +01:00
|
|
|
return not std_support
|
2021-09-20 15:01:58 +02:00
|
|
|
|
2021-03-05 12:14:42 +01:00
|
|
|
def set_version(self):
|
2022-05-05 09:46:35 +02:00
|
|
|
content = load(self, os.path.join(self.recipe_folder, "src/CMakeLists.txt"))
|
2022-05-12 13:58:32 +02:00
|
|
|
version = re.search(
|
|
|
|
r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content
|
|
|
|
).group(1)
|
2021-03-05 12:14:42 +01:00
|
|
|
self.version = version.strip()
|
|
|
|
|
2021-04-29 08:35:58 +02:00
|
|
|
def requirements(self):
|
2023-05-26 13:53:52 +02:00
|
|
|
self.requires("gsl-lite/0.40.0")
|
2021-09-20 15:01:58 +02:00
|
|
|
if self._use_libfmt:
|
2023-08-23 20:01:23 +02:00
|
|
|
self.requires("fmt/10.1.0")
|
2021-04-29 08:35:58 +02:00
|
|
|
|
|
|
|
def build_requirements(self):
|
2022-08-02 17:09:05 +02:00
|
|
|
if self._build_all:
|
2023-05-26 15:56:43 +02:00
|
|
|
self.test_requires("catch2/3.3.2")
|
2023-05-26 13:53:52 +02:00
|
|
|
if not self._skip_la:
|
|
|
|
self.test_requires("wg21-linear_algebra/0.7.3")
|
2021-04-29 08:35:58 +02:00
|
|
|
|
2023-05-26 13:53:52 +02:00
|
|
|
def validate(self):
|
|
|
|
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]
|
|
|
|
|
2020-12-16 18:40:42 +01:00
|
|
|
compiler = self.settings.compiler
|
2023-05-26 13:53:52 +02:00
|
|
|
min_version = self._minimum_compilers_version.get(str(compiler))
|
|
|
|
if min_version and loose_lt_semver(str(compiler.version), min_version):
|
|
|
|
raise ConanInvalidConfiguration(
|
|
|
|
f"{self.ref} requires at least {compiler} {min_version} ({compiler.version} in use)"
|
|
|
|
)
|
2019-04-10 17:19:55 +01:00
|
|
|
|
2022-08-01 18:29:03 +02:00
|
|
|
def layout(self):
|
|
|
|
cmake_layout(self)
|
|
|
|
|
2020-12-21 22:38:27 +01:00
|
|
|
def generate(self):
|
2021-09-09 09:01:05 +02:00
|
|
|
tc = CMakeToolchain(self)
|
2023-06-21 18:05:21 +02:00
|
|
|
tc.variables["MP_UNITS_BUILD_LA"] = self._build_all and not self._skip_la
|
|
|
|
tc.variables["MP_UNITS_USE_LIBFMT"] = self._use_libfmt
|
2020-12-21 22:38:27 +01:00
|
|
|
tc.generate()
|
2021-01-28 18:51:48 +01:00
|
|
|
deps = CMakeDeps(self)
|
|
|
|
deps.generate()
|
2020-12-21 22:38:27 +01:00
|
|
|
|
2019-05-08 09:52:46 -06:00
|
|
|
def build(self):
|
2021-04-29 08:35:58 +02:00
|
|
|
cmake = CMake(self)
|
2022-08-02 17:09:05 +02:00
|
|
|
cmake.configure(build_script_folder=None if self._build_all else "src")
|
2018-08-22 12:11:19 +02:00
|
|
|
cmake.build()
|
2022-08-02 17:09:05 +02:00
|
|
|
if self._build_all:
|
2022-03-10 18:55:40 +01:00
|
|
|
cmake.test()
|
|
|
|
|
|
|
|
def package_id(self):
|
2022-07-26 09:38:04 +02:00
|
|
|
self.info.clear()
|
2019-04-06 23:25:35 +02:00
|
|
|
|
|
|
|
def package(self):
|
2022-05-12 13:58:32 +02:00
|
|
|
copy(
|
|
|
|
self,
|
|
|
|
"LICENSE.md",
|
|
|
|
self.source_folder,
|
|
|
|
os.path.join(self.package_folder, "licenses"),
|
|
|
|
)
|
2021-04-29 08:35:58 +02:00
|
|
|
cmake = CMake(self)
|
2019-05-08 09:52:46 -06:00
|
|
|
cmake.install()
|
2022-05-05 09:46:35 +02:00
|
|
|
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
|
2020-09-06 00:00:06 +02:00
|
|
|
|
2018-08-22 12:11:19 +02:00
|
|
|
def package_info(self):
|
2020-09-06 00:00:06 +02:00
|
|
|
compiler = self.settings.compiler
|
2021-03-19 06:36:26 +01:00
|
|
|
|
2021-03-19 07:58:30 +01:00
|
|
|
# core
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"]
|
2023-05-26 13:53:52 +02:00
|
|
|
if compiler == "msvc":
|
2021-03-19 07:58:30 +01:00
|
|
|
self.cpp_info.components["core"].cxxflags = ["/utf-8"]
|
|
|
|
|
|
|
|
# rest
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["core-io"].requires = ["core"]
|
2021-11-16 08:34:56 +01:00
|
|
|
self.cpp_info.components["core-fmt"].requires = ["core"]
|
|
|
|
if self._use_libfmt:
|
|
|
|
self.cpp_info.components["core-fmt"].requires.append("fmt::fmt")
|
2023-05-26 13:53:52 +02:00
|
|
|
self.cpp_info.components["utility"].requires = ["core", "isq", "si", "angular"]
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["isq"].requires = ["core"]
|
2023-05-26 13:53:52 +02:00
|
|
|
self.cpp_info.components["angular"].requires = ["isq"]
|
|
|
|
self.cpp_info.components["isq_angular"].requires = ["isq", "angular"]
|
|
|
|
self.cpp_info.components["natural"].requires = ["isq"]
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["si"].requires = ["isq"]
|
2023-05-26 13:53:52 +02:00
|
|
|
self.cpp_info.components["cgs"].requires = ["si"]
|
|
|
|
self.cpp_info.components["hep"].requires = ["si"]
|
|
|
|
self.cpp_info.components["iau"].requires = ["si"]
|
|
|
|
self.cpp_info.components["imperial"].requires = ["si"]
|
|
|
|
self.cpp_info.components["international"].requires = ["si"]
|
|
|
|
self.cpp_info.components["typographic"].requires = ["usc"]
|
|
|
|
self.cpp_info.components["usc"].requires = ["international"]
|
|
|
|
self.cpp_info.components["iec80000"].requires = ["isq", "si"]
|
2022-04-15 17:01:47 +02:00
|
|
|
self.cpp_info.components["systems"].requires = [
|
|
|
|
"isq",
|
2023-05-26 13:53:52 +02:00
|
|
|
"angular",
|
|
|
|
"isq_angular",
|
|
|
|
"natural",
|
2022-04-15 17:01:47 +02:00
|
|
|
"si",
|
2023-05-26 13:53:52 +02:00
|
|
|
"cgs",
|
|
|
|
"hep",
|
|
|
|
"iau",
|
|
|
|
"imperial",
|
|
|
|
"international",
|
|
|
|
"typographic",
|
|
|
|
"usc",
|
|
|
|
"iec80000",
|
2022-04-15 17:01:47 +02:00
|
|
|
]
|