forked from johnmcfarlane/cnl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
executable file
·98 lines (82 loc) · 3.34 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake
from conans import tools
class CnlConan(ConanFile):
name = "cnl"
license = "Boost Software License 1.0"
author = "John McFarlane <[email protected]>"
url = "https://github.com/johnmcfarlane/cnl"
homepage = "https://johnmcfarlane.github.io/cnl/"
description = "A Compositional Numeric Library for C++"
topics = ("fixed-point", "value-types")
settings = "os", "compiler", "build_type", "arch"
options = {
"clang_tidy": [False, True],
"enable_exceptions": [False, True],
"int128": [False, True],
"sanitize": [False, True],
"target": [None, "test-all", "test-benchmark", "test-unit"],
"test_pattern": [None, "^test-", "test-benchmark", "^test-unit-"],
}
default_options = {
"clang_tidy": False,
"enable_exceptions": True,
"int128": True,
"sanitize": False,
"target": None,
"test_pattern": None,
}
generators = "cmake_find_package"
no_copy_source = True
requires = "gtest/1.10.0", "benchmark/1.5.2"
scm = {
"revision": "main",
"type": "git",
"url": "https://github.com/johnmcfarlane/cnl.git",
}
def build(self):
cmake = CMake(self, set_cmake_flags=True)
if self.should_configure:
self.configure_phase(cmake)
if self.should_build and self.options.target:
self.build_phase(cmake)
if self.options.target:
cmake.install()
if self.should_test and self.options.test_pattern:
self.test_phase();
def package(self):
self.copy("include/*.h")
self.copy("LICENSE_1_0.txt", "licenses")
def package_id(self):
self.info.header_only()
def configure_phase(self, cmake):
def conan_option_to_cmake_boolean(conan_option: bool):
return {
True: "ON",
False: "OFF"
}[bool(conan_option)]
std = " -DCMAKE_CXX_STANDARD={}".format(
self.settings.compiler.cppstd) if self.settings.compiler.cppstd else ""
module_path = "-DCMAKE_MODULE_PATH:FILEPATH={}".format(
self.build_folder)
gtest_hack = "-DCNL_GTEST_MAIN_TARGET:STRING=GTest::gtest_main"
clang_tidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy" if self.options.clang_tidy else ""
exceptions = "-DCNL_EXCEPTIONS={}".format(
conan_option_to_cmake_boolean(self.options.enable_exceptions))
int128 = "-DCNL_INT128={}".format(
conan_option_to_cmake_boolean(self.options.int128))
sanitize = "-DCNL_SANITIZE={}".format(
conan_option_to_cmake_boolean(self.options.sanitize))
self.run(f'cmake {cmake.command_line}{std} {module_path} {gtest_hack} {clang_tidy} {exceptions} {int128} {sanitize} {self.source_folder}')
def build_phase(self, cmake):
assert(self.options.target)
build = "--build {}".format(self.build_folder)
target = "--target {}".format(self.options.target)
self.run(f'cmake {build} {target} {cmake.build_config}')
def test_phase(self):
assert(self.options.test_pattern)
self.run("ctest --output-on-failure --parallel {} --tests-regex {}".format(
tools.cpu_count(),
self.options.test_pattern
))