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-01-28 18:51:48 +01:00
|
|
|
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps
|
2019-04-10 17:12:24 +01:00
|
|
|
from conans.errors import ConanInvalidConfiguration
|
|
|
|
import re
|
|
|
|
|
2021-01-27 17:48:53 +01:00
|
|
|
required_conan_version = ">=1.33.0"
|
2019-04-10 17:12:24 +01:00
|
|
|
|
|
|
|
def get_version():
|
|
|
|
try:
|
2020-01-31 17:02:27 +01:00
|
|
|
content = tools.load("src/CMakeLists.txt")
|
2019-04-10 17:12:24 +01:00
|
|
|
version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1)
|
|
|
|
return version.strip()
|
|
|
|
except Exception:
|
|
|
|
return None
|
|
|
|
|
2019-04-04 10:34:58 +02:00
|
|
|
class UnitsConan(ConanFile):
|
2019-04-07 08:33:13 +02:00
|
|
|
name = "mp-units"
|
2019-04-10 17:12:24 +01:00
|
|
|
version = get_version()
|
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-01-27 17:12:27 +01:00
|
|
|
"fmt/7.1.3",
|
2021-01-05 17:47:07 +01:00
|
|
|
"gsl-lite/0.37.0"
|
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
|
|
|
|
2021-02-15 17:06:09 +01:00
|
|
|
_cmake = None
|
|
|
|
|
2019-11-20 16:33:50 -03:00
|
|
|
@property
|
|
|
|
def _run_tests(self):
|
|
|
|
return tools.get_env("CONAN_RUN_TESTS", False)
|
|
|
|
|
2020-12-21 22:38:27 +01:00
|
|
|
def _configure_cmake(self):
|
2021-02-15 17:06:09 +01:00
|
|
|
if not self._cmake:
|
|
|
|
self._cmake = CMake(self)
|
|
|
|
if self._run_tests:
|
|
|
|
# developer's mode (unit tests, examples, documentation, restrictive compilation warnings, ...)
|
|
|
|
self._cmake.configure()
|
|
|
|
else:
|
|
|
|
# consumer's mode (library sources only)
|
|
|
|
self._cmake.configure(source_folder="src")
|
|
|
|
return self._cmake
|
2020-01-31 17:02:27 +01: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")
|
|
|
|
elif compiler == "Visual Studio":
|
|
|
|
if version < "16":
|
|
|
|
raise ConanInvalidConfiguration("mp-units requires at least Visual Studio 16.7")
|
|
|
|
else:
|
|
|
|
raise ConanInvalidConfiguration("mp-units is supported only by gcc and Visual Studio so far")
|
|
|
|
if compiler.get_safe("cppstd"):
|
|
|
|
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-01-31 17:02:27 +01:00
|
|
|
def build_requirements(self):
|
|
|
|
if self._run_tests:
|
2021-01-27 17:10:14 +01:00
|
|
|
self.build_requires("catch2/2.13.4")
|
2020-09-05 12:17:36 +01:00
|
|
|
self.build_requires("linear_algebra/0.7.0@public-conan/stable")
|
2020-11-05 16:51:42 +01:00
|
|
|
if self.options.build_docs:
|
2020-11-04 18:26:03 +01:00
|
|
|
self.build_requires("doxygen/1.8.20")
|
2020-01-31 17:02:27 +01:00
|
|
|
|
2020-12-21 22:38:27 +01:00
|
|
|
def generate(self):
|
|
|
|
tc = CMakeToolchain(self)
|
|
|
|
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
|
|
|
|
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):
|
|
|
|
cmake = self._configure_cmake()
|
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")
|
2019-05-08 09:52:46 -06:00
|
|
|
cmake = self._configure_cmake()
|
|
|
|
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
|
|
|
|
if compiler == "gcc":
|
2021-02-15 17:06:09 +01:00
|
|
|
self.cpp_info.cxxflags = ["-Wno-non-template-friend"]
|
2020-09-06 00:00:06 +02:00
|
|
|
elif compiler == "Visual Studio":
|
2021-02-15 17:06:09 +01:00
|
|
|
self.cpp_info.cxxflags = ["/utf-8"]
|