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.
|
|
|
|
|
2020-12-21 22:38:27 +01:00
|
|
|
from conans import ConanFile, tools
|
2020-09-06 00:00:06 +02:00
|
|
|
from conans.tools import Version, check_min_cppstd
|
2021-04-29 08:35:58 +02:00
|
|
|
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
|
2019-04-10 17:12:24 +01:00
|
|
|
from conans.errors import ConanInvalidConfiguration
|
2021-03-05 12:14:42 +01:00
|
|
|
import os, re
|
2019-04-10 17:12:24 +01:00
|
|
|
|
2022-02-28 18:25:20 +01:00
|
|
|
required_conan_version = ">=1.43.0"
|
2019-04-10 17:12:24 +01:00
|
|
|
|
2019-04-04 10:34:58 +02:00
|
|
|
class UnitsConan(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++"
|
2020-09-06 00:00:06 +02:00
|
|
|
topics = ("units", "dimensions", "quantities", "dimensional-analysis", "physical-quantities", "physical-units", "system-of-units", "cpp23", "cpp20", "library", "quantity-manipulation")
|
|
|
|
license = "MIT"
|
|
|
|
url = "https://github.com/mpusz/units"
|
2021-03-05 12:12:01 +01:00
|
|
|
settings = "os", "compiler", "build_type", "arch"
|
2019-04-05 17:46:01 +02:00
|
|
|
requires = (
|
2021-09-10 08:17:04 +02:00
|
|
|
"gsl-lite/0.38.1"
|
2019-04-05 17:46:01 +02:00
|
|
|
)
|
2020-05-08 10:50:34 +02:00
|
|
|
options = {
|
2020-11-04 18:26:03 +01:00
|
|
|
"downcast_mode": ["off", "on", "auto"],
|
2020-11-05 16:51:42 +01:00
|
|
|
"build_docs": [True, False]
|
2020-05-08 10:50:34 +02:00
|
|
|
}
|
|
|
|
default_options = {
|
2020-11-04 18:26:03 +01:00
|
|
|
"downcast_mode": "on",
|
2020-11-05 16:51:42 +01:00
|
|
|
"build_docs": True
|
2020-05-08 10:50:34 +02:00
|
|
|
}
|
2020-09-06 00:00:06 +02:00
|
|
|
exports = ["LICENSE.md"]
|
|
|
|
exports_sources = ["docs/*", "src/*", "test/*", "cmake/*", "example/*","CMakeLists.txt"]
|
2020-02-10 19:07:13 +01:00
|
|
|
# scm = {
|
|
|
|
# "type": "git",
|
|
|
|
# "url": "auto",
|
|
|
|
# "revision": "auto",
|
|
|
|
# "submodule": "recursive"
|
|
|
|
# }
|
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
|
|
|
|
def _run_tests(self):
|
|
|
|
return tools.get_env("CONAN_RUN_TESTS", False)
|
|
|
|
|
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)
|
|
|
|
std_support = \
|
|
|
|
(compiler == "Visual Studio" and version >= "17" and compiler.cppstd == 23) or \
|
|
|
|
(compiler == "msvc" and (version == "19.3" or version >= "19.30") and compiler.cppstd == 23)
|
|
|
|
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)
|
|
|
|
return ("clang" in compiler and compiler.libcxx == "libc++" and version < "14.0")
|
|
|
|
|
2021-03-05 12:14:42 +01:00
|
|
|
def set_version(self):
|
|
|
|
content = tools.load(os.path.join(self.recipe_folder, "src/CMakeLists.txt"))
|
|
|
|
version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1)
|
|
|
|
self.version = version.strip()
|
|
|
|
|
2021-04-29 08:35:58 +02:00
|
|
|
def requirements(self):
|
|
|
|
compiler = self.settings.compiler
|
2021-12-13 05:01:16 -04:00
|
|
|
version = Version(self.settings.compiler.version)
|
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):
|
|
|
|
if self._run_tests:
|
2022-02-28 18:25:20 +01:00
|
|
|
self.test_requires("catch2/2.13.7")
|
|
|
|
self.test_requires("wg21-linear_algebra/0.7.2")
|
2021-04-29 08:35:58 +02:00
|
|
|
if self.options.build_docs:
|
2021-08-29 22:23:45 +02:00
|
|
|
self.build_requires("doxygen/1.9.2")
|
2021-04-29 08:35:58 +02:00
|
|
|
|
2020-12-16 18:40:42 +01:00
|
|
|
def validate(self):
|
|
|
|
compiler = self.settings.compiler
|
|
|
|
version = Version(self.settings.compiler.version)
|
|
|
|
if compiler == "gcc":
|
|
|
|
if version < "10.0":
|
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least g++-10")
|
2021-02-21 00:40:56 +01:00
|
|
|
elif compiler == "clang":
|
|
|
|
if version < "12":
|
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least clang++-12")
|
2022-01-26 18:18:51 -06:00
|
|
|
elif compiler == "apple-clang":
|
|
|
|
if version < "13":
|
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least AppleClang 13")
|
2020-12-16 18:40:42 +01:00
|
|
|
elif compiler == "Visual Studio":
|
|
|
|
if version < "16":
|
2021-03-15 22:10:19 +01:00
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least Visual Studio 16.9")
|
2021-11-15 17:50:54 +01:00
|
|
|
elif compiler == "msvc":
|
2021-12-13 12:29:01 +01:00
|
|
|
if 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")
|
|
|
|
check_min_cppstd(self, "20")
|
2019-04-10 17:19:55 +01:00
|
|
|
|
2020-12-21 23:06:37 +01:00
|
|
|
# TODO Uncomment this when environment is supported in the Conan toolchain
|
|
|
|
# def config_options(self):
|
|
|
|
# if not self._run_tests:
|
|
|
|
# # build_docs has sense only in a development or CI build
|
|
|
|
# del self.options.build_docs
|
2020-11-04 18:26:03 +01:00
|
|
|
|
2020-12-21 22:38:27 +01:00
|
|
|
def generate(self):
|
2021-09-09 09:01:05 +02:00
|
|
|
tc = CMakeToolchain(self)
|
2020-12-21 22:38:27 +01:00
|
|
|
tc.variables["UNITS_DOWNCAST_MODE"] = str(self.options.downcast_mode).upper()
|
|
|
|
# if self._run_tests: # TODO Enable this when environment is supported in the Conan toolchain
|
2021-09-20 15:01:58 +02:00
|
|
|
tc.variables["UNITS_BUILD_DOCS"] = self.options.build_docs == "True"
|
|
|
|
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)
|
2021-09-09 10:12:14 +02:00
|
|
|
cmake.configure(build_script_folder=None if self._run_tests else "src")
|
2018-08-22 12:11:19 +02:00
|
|
|
cmake.build()
|
2019-11-20 16:33:50 -03:00
|
|
|
if self._run_tests:
|
2020-04-05 10:20:40 +02:00
|
|
|
cmake.test(output_on_failure=True)
|
2019-04-06 23:25:35 +02:00
|
|
|
|
|
|
|
def package(self):
|
2019-11-21 12:00:03 -03:00
|
|
|
self.copy(pattern="LICENSE.md", dst="licenses")
|
2021-04-29 08:35:58 +02:00
|
|
|
cmake = CMake(self)
|
2019-05-08 09:52:46 -06:00
|
|
|
cmake.install()
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2020-09-06 00:00:06 +02:00
|
|
|
def package_id(self):
|
2020-09-14 12:50:51 +02:00
|
|
|
self.info.header_only()
|
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"]
|
|
|
|
self.cpp_info.components["si-fps"].requires = ["si"]
|
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"]
|
2021-08-14 19:57:32 +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"]
|