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
|
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 14:07:49 +02:00
|
|
|
from conans.errors import ConanInvalidConfiguration
|
2022-05-12 17:10:11 +02:00
|
|
|
|
2022-07-26 09:38:04 +02:00
|
|
|
required_conan_version = ">=1.50.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"
|
2020-09-06 00:00:06 +02:00
|
|
|
homepage = "https://github.com/mpusz/units"
|
2018-09-28 07:47:37 -07:00
|
|
|
description = "Physical 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",
|
|
|
|
"cpp23",
|
|
|
|
"cpp20",
|
|
|
|
"library",
|
|
|
|
"quantity-manipulation",
|
|
|
|
)
|
2020-09-06 00:00:06 +02:00
|
|
|
license = "MIT"
|
|
|
|
url = "https://github.com/mpusz/units"
|
2021-03-05 12:12:01 +01:00
|
|
|
settings = "os", "compiler", "build_type", "arch"
|
2022-05-12 13:58:32 +02:00
|
|
|
requires = "gsl-lite/0.40.0"
|
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",
|
|
|
|
]
|
2022-05-05 11:54:23 +02:00
|
|
|
no_copy_source = True
|
2021-01-28 18:51:48 +01:00
|
|
|
generators = "cmake_paths"
|
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):
|
|
|
|
return bool(self.conf["user.build:all"])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _skip_docs(self):
|
|
|
|
return bool(self.conf["user.build:skip_docs"])
|
2019-11-20 16:33:50 -03: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)
|
2022-05-12 13:58:32 +02:00
|
|
|
std_support = (
|
|
|
|
compiler == "Visual Studio" and version >= 17 and compiler.cppstd == 23
|
|
|
|
) or (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
|
|
|
|
2022-01-26 18:18:51 -06:00
|
|
|
@property
|
|
|
|
def _use_range_v3(self):
|
|
|
|
compiler = self.settings.compiler
|
|
|
|
version = Version(self.settings.compiler.version)
|
2022-04-15 16:56:48 +02:00
|
|
|
return "clang" in compiler and compiler.libcxx == "libc++" and version < 14
|
2022-01-26 18:18:51 -06:00
|
|
|
|
2022-03-14 19:25:59 +01:00
|
|
|
@property
|
|
|
|
def _msvc_version(self):
|
|
|
|
compiler = self.settings.compiler
|
2022-04-15 16:56:48 +02:00
|
|
|
if compiler.update:
|
2022-03-14 19:25:59 +01:00
|
|
|
return int(f"{compiler.version}{compiler.update}")
|
|
|
|
else:
|
|
|
|
return int(f"{compiler.version}0")
|
|
|
|
|
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):
|
2021-09-20 15:01:58 +02:00
|
|
|
if self._use_libfmt:
|
2022-01-26 18:22:54 -06:00
|
|
|
self.requires("fmt/8.1.1")
|
2021-09-20 15:01:58 +02:00
|
|
|
|
2022-01-26 18:18:51 -06:00
|
|
|
if self._use_range_v3:
|
2021-04-29 08:35:58 +02:00
|
|
|
self.requires("range-v3/0.11.0")
|
|
|
|
|
|
|
|
def build_requirements(self):
|
2022-08-02 17:09:05 +02:00
|
|
|
if self._build_all:
|
2022-09-01 16:19:51 +02:00
|
|
|
self.test_requires("catch2/3.1.0")
|
2022-02-28 18:25:20 +01:00
|
|
|
self.test_requires("wg21-linear_algebra/0.7.2")
|
2022-08-02 17:09:05 +02:00
|
|
|
if not self._skip_docs:
|
2022-05-12 17:09:38 +02:00
|
|
|
self.tool_requires("doxygen/1.9.4")
|
2021-04-29 08:35:58 +02:00
|
|
|
|
2022-04-15 16:57:38 +02:00
|
|
|
# TODO Replace with `valdate()` for Conan 2.0 (https://github.com/conan-io/conan/issues/10723)
|
|
|
|
def configure(self):
|
2020-12-16 18:40:42 +01:00
|
|
|
compiler = self.settings.compiler
|
|
|
|
version = Version(self.settings.compiler.version)
|
|
|
|
if compiler == "gcc":
|
2022-03-14 19:26:43 +01:00
|
|
|
if version < 10:
|
2020-12-16 18:40:42 +01:00
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least g++-10")
|
2021-02-21 00:40:56 +01:00
|
|
|
elif compiler == "clang":
|
2022-03-14 19:26:43 +01:00
|
|
|
if version < 12:
|
2021-02-21 00:40:56 +01:00
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least clang++-12")
|
2022-01-26 18:18:51 -06:00
|
|
|
elif compiler == "apple-clang":
|
2022-03-14 19:26:43 +01:00
|
|
|
if version < 13:
|
2022-05-12 13:58:32 +02:00
|
|
|
raise ConanInvalidConfiguration(
|
|
|
|
"mp-units requires at least AppleClang 13"
|
|
|
|
)
|
2020-12-16 18:40:42 +01:00
|
|
|
elif compiler == "Visual Studio":
|
2022-03-14 19:26:43 +01:00
|
|
|
if version < 16:
|
2022-05-12 13:58:32 +02:00
|
|
|
raise ConanInvalidConfiguration(
|
|
|
|
"mp-units requires at least Visual Studio 16.9"
|
|
|
|
)
|
2021-11-15 17:50:54 +01:00
|
|
|
elif compiler == "msvc":
|
2022-03-14 19:25:59 +01:00
|
|
|
if self._msvc_version < 1928:
|
2021-11-15 17:50:54 +01:00
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least MSVC 19.28")
|
2020-12-16 18:40:42 +01:00
|
|
|
else:
|
2021-02-21 00:40:56 +01:00
|
|
|
raise ConanInvalidConfiguration("Unsupported compiler")
|
2022-03-14 19:26:43 +01:00
|
|
|
check_min_cppstd(self, 20)
|
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)
|
2022-08-02 17:09:05 +02:00
|
|
|
tc.variables["UNITS_BUILD_DOCS"] = self._build_all and not self._skip_docs
|
2021-09-20 15:01:58 +02:00
|
|
|
tc.variables["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"]
|
2021-03-19 07:58:30 +01:00
|
|
|
if compiler == "Visual Studio":
|
|
|
|
self.cpp_info.components["core"].cxxflags = ["/utf-8"]
|
2022-01-26 18:18:51 -06:00
|
|
|
if self._use_range_v3:
|
2021-03-19 08:41:11 +01:00
|
|
|
self.cpp_info.components["core"].requires.append("range-v3::range-v3")
|
2021-03-19 07:58:30 +01:00
|
|
|
|
|
|
|
# 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")
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["isq"].requires = ["core"]
|
|
|
|
self.cpp_info.components["isq-natural"].requires = ["isq"]
|
|
|
|
self.cpp_info.components["si"].requires = ["isq"]
|
|
|
|
self.cpp_info.components["si-cgs"].requires = ["si"]
|
2022-05-10 11:40:54 +02:00
|
|
|
self.cpp_info.components["si-fps"].requires = ["si-international"]
|
2021-08-14 19:57:32 +02:00
|
|
|
self.cpp_info.components["si-hep"].requires = ["si"]
|
2021-03-19 06:36:26 +01:00
|
|
|
self.cpp_info.components["si-iau"].requires = ["si"]
|
|
|
|
self.cpp_info.components["si-imperial"].requires = ["si"]
|
|
|
|
self.cpp_info.components["si-international"].requires = ["si"]
|
|
|
|
self.cpp_info.components["si-typographic"].requires = ["si"]
|
2021-04-16 12:40:52 +02:00
|
|
|
self.cpp_info.components["si-uscs"].requires = ["si"]
|
2021-03-19 23:04:52 +01:00
|
|
|
self.cpp_info.components["isq-iec80000"].requires = ["si"]
|
2022-04-15 17:01:47 +02:00
|
|
|
self.cpp_info.components["systems"].requires = [
|
|
|
|
"isq",
|
|
|
|
"isq-natural",
|
|
|
|
"si",
|
|
|
|
"si-cgs",
|
|
|
|
"si-fps",
|
|
|
|
"si-hep",
|
|
|
|
"si-iau",
|
|
|
|
"si-imperial",
|
|
|
|
"si-international",
|
|
|
|
"si-typographic",
|
|
|
|
"si-uscs",
|
|
|
|
"isq-iec80000",
|
|
|
|
]
|