Files
mp-units/conanfile.py
Uilian Ries 7b19559dfc Update Conan recipe
Signed-off-by: Uilian Ries <uilianries@gmail.com>
2020-02-25 15:32:12 +01:00

101 lines
3.7 KiB
Python

# 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.
from conans import ConanFile, CMake, tools
from conans.tools import load, Version
from conans.errors import ConanInvalidConfiguration
import re
import os
def get_version():
try:
content = load("src/CMakeLists.txt")
version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1)
return version.strip()
except Exception:
return None
class UnitsConan(ConanFile):
name = "mp-units"
version = get_version()
author = "Mateusz Pusz"
license = "https://github.com/mpusz/units/blob/master/LICENSE.md"
url = "https://github.com/mpusz/units"
description = "Physical Units library for C++"
exports = ["LICENSE.md"]
exports = ["*"]
settings = "os", "compiler", "build_type", "arch"
requires = (
"range-v3/0.9.1@ericniebler/stable",
"Catch2/2.10.0@catchorg/stable",
"fmt/6.0.0"
)
generators = "cmake"
@property
def _run_tests(self):
return tools.get_env("CONAN_RUN_TESTS", False)
def configure(self):
if self.settings.compiler != "gcc":
raise ConanInvalidConfiguration("Library works only with gcc")
if Version(self.settings.compiler.version) < "9":
raise ConanInvalidConfiguration("Library requires at least gcc-9")
if self.settings.compiler.cppstd not in [None, "20", "gnu20"]:
raise ConanInvalidConfiguration("Library requires at least C++20 support")
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_TESTS"] = self._run_tests
cmake.definitions["BUILD_EXAMPLES"] = self._run_tests
cmake.configure()
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
if self._run_tests:
self.run(os.path.join("bin", "unit_tests_runtime"), run_environment=True)
def package(self):
self.copy(pattern="*license*", dst="licenses", excludes="cmake/common/*", ignore_case=True, keep_path=False)
cmake = self._configure_cmake()
cmake.install()
def package_info(self):
self.cpp_info.includedirs = ['include']
if self.settings.compiler == "gcc":
self.cpp_info.cxxflags = [
"-fconcepts",
"-Wno-literal-suffix",
"-Wno-non-template-friend",
"-Wno-stringop-overflow",
"-Wno-pedantic"
]
def package_id(self):
self.info.settings.clear()
self.info.settings.compiler = self.settings.compiler
self.info.settings.compiler.version = self.settings.compiler.version