Files
mp-units/conanfile.py

221 lines
7.7 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.
2022-05-12 14:00:18 +02:00
import os
import re
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
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
required_conan_version = ">=1.50.0"
2022-04-15 16:56:48 +02:00
2022-03-14 19:26:43 +01:00
class MPUnitsConan(ConanFile):
name = "mp-units"
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",
)
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"
exports = ["LICENSE.md"]
2022-05-12 13:58:32 +02:00
exports_sources = [
"docs/*",
"src/*",
"test/*",
"cmake/*",
"example/*",
"CMakeLists.txt",
]
no_copy_source = True
2021-01-28 18:51:48 +01:00
generators = "cmake_paths"
2018-08-22 12:11:19 +02:00
@property
def _build_all(self):
return bool(self.conf["user.build:all"])
@property
def _skip_docs(self):
return bool(self.conf["user.build:skip_docs"])
@property
def _use_libfmt(self):
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)
return not std_support
@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-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")
def set_version(self):
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)
self.version = version.strip()
2021-04-29 08:35:58 +02:00
def requirements(self):
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._build_all:
2022-09-01 16:19:51 +02:00
self.test_requires("catch2/3.1.0")
self.test_requires("wg21-linear_algebra/0.7.2")
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
# 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")
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
def layout(self):
cmake_layout(self)
2020-12-21 22:38:27 +01:00
def generate(self):
tc = CMakeToolchain(self)
tc.variables["UNITS_BUILD_DOCS"] = self._build_all and not self._skip_docs
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)
cmake.configure(build_script_folder=None if self._build_all else "src")
2018-08-22 12:11:19 +02:00
cmake.build()
if self._build_all:
2022-03-10 18:55:40 +01:00
cmake.test()
def package_id(self):
self.info.clear()
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()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
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-international"]
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",
]