-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconanfile.py
More file actions
154 lines (129 loc) · 5.02 KB
/
conanfile.py
File metadata and controls
154 lines (129 loc) · 5.02 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
#
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain, CMakeDeps
from conan.tools.files import copy
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from pathlib import Path
required_conan_version = ">=2.2.0"
class strong_ptr_conan(ConanFile):
name = "strong_ptr"
license = "Apache-2.0"
url = "https://github.com/libhal/strong_ptr"
homepage = "https://github.com/libhal/strong_ptr"
description = (
"A non-null alternative to std::shared_ptr for memory constrained systems and fewer footguns.")
topics = ("memory", "dynamic", "polymorphic_allocator",
"pointer", "pointers")
settings = "compiler", "build_type", "os", "arch"
exports_sources = ("modules/*", "tests/*",
"CMakeLists.txt", "LICENSE", ".clang-tidy")
shared = False
options = {
"enable_clang_tidy": [True, False],
"clang_tidy_fix": [True, False],
}
default_options = {
"enable_clang_tidy": False,
"clang_tidy_fix": False,
}
@property
def _min_cppstd(self):
return "23"
@property
def _compilers_minimum_version(self):
# We may reduce these in the future.
return {
"gcc": ("14", "GCC 14+ required for strong_ptr"),
"clang": (
"19",
"Clang 19+ required for strong_ptr"
),
"apple-clang": (
"19.0.0",
"Apple Clang 19+ for strong_ptr"
),
"msvc": (
"193.4",
"MSVC 14.34+ (Visual Studio 17.4+) for strong_ptr"
)
}
def _validate_compiler_version(self):
"""Validate compiler version against minimum requirements"""
compiler = str(self.settings.compiler)
version = str(self.settings.compiler.version)
# Map Visual Studio to msvc for consistency
compiler_key = "msvc" if compiler == "Visual Studio" else compiler
min_versions = self._compilers_minimum_version
if compiler_key not in min_versions:
raise ConanInvalidConfiguration(
f"Compiler {compiler} is not supported for C++20 modules")
min_version, error_msg = min_versions[compiler_key]
if Version(version) < min_version:
raise ConanInvalidConfiguration(error_msg)
def set_version(self):
# Use latest if not specified via command line
if not self.version:
self.version = "latest"
def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)
self._validate_compiler_version()
def build_requirements(self):
self.tool_requires("cmake/[^4.0.0]")
self.tool_requires("ninja/[^1.3.0]")
self.test_requires("boost-ext-ut/2.3.1",
options={'disable_module': False})
self.requires("libhal-cmake-util/[^5.0.6]")
def requirements(self):
pass
def layout(self):
build_path = Path("build") / (
str(self.settings.arch) + "-" +
str(self.settings.os) + "-" +
str(self.settings.compiler) + "-" +
str(self.settings.compiler.version)
)
cmake_layout(self, build_folder=str(build_path))
def generate(self):
tc = CMakeToolchain(self)
tc.generator = "Ninja"
tc.variables["LIBHAL_ENABLE_CLANG_TIDY"] = self.options.enable_clang_tidy
tc.variables["LIBHAL_CLANG_TIDY_FIX"] = self.options.clang_tidy_fix
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if not self.conf.get("tools.build:skip_test", default=False):
cmake.ctest(["--output-on-failure"])
def package(self):
cmake = CMake(self)
cmake.install()
copy(self, "LICENSE",
dst=Path(self.package_folder) / "licenses",
src=self.source_folder)
def package_id(self):
self.info.options.clear()
def package_info(self):
# DISABLE Conan's config file generation
self.cpp_info.set_property("cmake_find_mode", "none")
# Tell CMake to include this directory in its search path
self.cpp_info.builddirs.append("lib/cmake")