mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
build(conan): Environment variables replaced with Conan configuration properties
This commit is contained in:
32
conanfile.py
32
conanfile.py
@@ -30,9 +30,6 @@ from conan.tools.files import copy, load, rmdir
|
||||
from conan.tools.scm import Version
|
||||
from conans.errors import ConanInvalidConfiguration
|
||||
|
||||
# TODO remove when `CONAN_RUN_TESTS` will be replaced with a `[conf]` variable
|
||||
from conans.tools import get_env
|
||||
|
||||
required_conan_version = ">=1.50.0"
|
||||
|
||||
|
||||
@@ -57,8 +54,8 @@ class MPUnitsConan(ConanFile):
|
||||
url = "https://github.com/mpusz/units"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
requires = "gsl-lite/0.40.0"
|
||||
options = {"downcast_mode": ["off", "on", "auto"], "build_docs": [True, False]}
|
||||
default_options = {"downcast_mode": "on", "build_docs": True}
|
||||
options = {"downcast_mode": ["off", "on", "auto"]}
|
||||
default_options = {"downcast_mode": "on"}
|
||||
exports = ["LICENSE.md"]
|
||||
exports_sources = [
|
||||
"docs/*",
|
||||
@@ -72,8 +69,12 @@ class MPUnitsConan(ConanFile):
|
||||
generators = "cmake_paths"
|
||||
|
||||
@property
|
||||
def _run_tests(self):
|
||||
return get_env("CONAN_RUN_TESTS", False)
|
||||
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):
|
||||
@@ -113,10 +114,10 @@ class MPUnitsConan(ConanFile):
|
||||
self.requires("range-v3/0.11.0")
|
||||
|
||||
def build_requirements(self):
|
||||
if self._run_tests:
|
||||
if self._build_all:
|
||||
self.test_requires("catch2/2.13.9")
|
||||
self.test_requires("wg21-linear_algebra/0.7.2")
|
||||
if self.options.build_docs:
|
||||
if not self._skip_docs:
|
||||
self.tool_requires("doxygen/1.9.4")
|
||||
|
||||
# TODO Replace with `valdate()` for Conan 2.0 (https://github.com/conan-io/conan/issues/10723)
|
||||
@@ -146,20 +147,13 @@ class MPUnitsConan(ConanFile):
|
||||
raise ConanInvalidConfiguration("Unsupported compiler")
|
||||
check_min_cppstd(self, 20)
|
||||
|
||||
# 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
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
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"] = bool(self.options.build_docs)
|
||||
tc.variables["UNITS_BUILD_DOCS"] = self._build_all and not self._skip_docs
|
||||
tc.variables["UNITS_USE_LIBFMT"] = self._use_libfmt
|
||||
tc.generate()
|
||||
deps = CMakeDeps(self)
|
||||
@@ -167,9 +161,9 @@ class MPUnitsConan(ConanFile):
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure(build_script_folder=None if self._run_tests else "src")
|
||||
cmake.configure(build_script_folder=None if self._build_all else "src")
|
||||
cmake.build()
|
||||
if self._run_tests:
|
||||
if self._build_all:
|
||||
cmake.test()
|
||||
|
||||
def package_id(self):
|
||||
|
Reference in New Issue
Block a user