Files
mp-units/conanfile.py

181 lines
7.5 KiB
Python
Raw Normal View History

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
from conans.tools import Version, check_min_cppstd
2021-04-29 08:35:58 +02:00
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conans.errors import ConanInvalidConfiguration
import os, re
required_conan_version = ">=1.43.0"
2019-04-04 10:34:58 +02:00
class UnitsConan(ConanFile):
name = "mp-units"
homepage = "https://github.com/mpusz/units"
2018-09-28 07:47:37 -07:00
description = "Physical Units library for C++"
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"
requires = (
"gsl-lite/0.38.1"
)
options = {
"downcast_mode": ["off", "on", "auto"],
"build_docs": [True, False]
}
default_options = {
"downcast_mode": "on",
"build_docs": True
}
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
@property
def _run_tests(self):
return tools.get_env("CONAN_RUN_TESTS", False)
@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 == "19.3" or version >= "19.30") and compiler.cppstd == 23)
return not std_support
@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")
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
version = Version(self.settings.compiler.version)
if self._use_libfmt:
self.requires("fmt/8.1.1")
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:
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")
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":
raise ConanInvalidConfiguration("mp-units requires at least Visual Studio 16.9")
2021-11-15 17:50:54 +01:00
elif compiler == "msvc":
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
# 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-12-21 22:38:27 +01:00
def generate(self):
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
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()
if self._run_tests:
cmake.test(output_on_failure=True)
def package(self):
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
def package_id(self):
self.info.header_only()
2018-08-22 12:11:19 +02:00
def package_info(self):
compiler = self.settings.compiler
2021-03-19 07:58:30 +01:00
# core
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"]
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
self.cpp_info.components["core-io"].requires = ["core"]
self.cpp_info.components["core-fmt"].requires = ["core"]
if self._use_libfmt:
self.cpp_info.components["core-fmt"].requires.append("fmt::fmt")
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"]
self.cpp_info.components["si-hep"].requires = ["si"]
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"]
self.cpp_info.components["isq-iec80000"].requires = ["si"]
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"]