Files
mp-units/conanfile.py

92 lines
3.3 KiB
Python
Raw Permalink 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.
2019-04-09 22:09:21 +01:00
from conans import ConanFile, CMake, tools
from conans.tools import load
from conans.errors import ConanInvalidConfiguration
import re
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
2018-08-22 12:11:19 +02:00
2019-04-04 10:34:58 +02:00
class UnitsConan(ConanFile):
name = "mp-units"
version = get_version()
2018-08-22 12:11:19 +02:00
author = "Mateusz Pusz"
license = "https://github.com/mpusz/units/blob/master/LICENSE.md"
2018-08-22 12:11:19 +02:00
url = "https://github.com/mpusz/units"
2018-09-28 07:47:37 -07:00
description = "Physical Units library for C++"
exports = ["LICENSE.md"]
2019-05-08 15:09:42 -06:00
settings = "os", "compiler", "build_type", "arch"
requires = (
"range-v3/0.9.1@ericniebler/stable"
)
scm = {
"type": "git",
"url": "auto",
2019-04-10 19:38:34 +01:00
"revision": "auto",
"submodule": "recursive"
}
generators = "cmake"
2018-08-22 12:11:19 +02:00
2019-04-10 17:19:55 +01:00
def configure(self):
if self.settings.compiler != "gcc":
2019-05-08 15:09:42 -06:00
raise ConanInvalidConfiguration("Library works only with gcc")
if int(self.settings.compiler.version.value) < 9:
raise ConanInvalidConfiguration("Library requires at least gcc-9")
2019-05-08 15:09:42 -06:00
if self.settings.compiler.cppstd not in ["20", "gnu20"]:
raise ConanInvalidConfiguration("Library requires at least C++20 support")
2019-04-10 17:19:55 +01:00
2019-05-08 09:52:46 -06:00
def _configure_cmake(self):
2018-08-22 12:11:19 +02:00
cmake = CMake(self)
2019-04-09 13:33:59 +02:00
if tools.get_env("CONAN_RUN_TESTS", False):
cmake.configure()
else:
cmake.configure(source_dir="%s/src" % self.source_folder)
2019-05-08 09:52:46 -06:00
return cmake
def build(self):
cmake = self._configure_cmake()
2018-08-22 12:11:19 +02:00
cmake.build()
def package(self):
self.copy(pattern="*license*", dst="licenses", excludes="cmake/common/*", ignore_case=True, keep_path=False)
2019-05-08 09:52:46 -06:00
cmake = self._configure_cmake()
cmake.install()
2018-08-22 12:11:19 +02:00
def package_info(self):
self.cpp_info.includedirs = ['include']
if self.settings.compiler == "gcc":
self.cpp_info.cxxflags = ["-fconcepts"]
def package_id(self):
self.info.settings.clear()
self.info.settings.compiler = self.settings.compiler
self.info.settings.compiler.version = self.settings.compiler.version