-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconanfile.py
More file actions
224 lines (182 loc) · 8.8 KB
/
Copy pathconanfile.py
File metadata and controls
224 lines (182 loc) · 8.8 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python3
"""
Conan package recipe for AlgebraicHashing library.
This is a modern C++20 header-only library for algebraic hash function composition.
It provides an elegant DSL for combining hash functions and exploring their mathematical properties.
"""
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout, CMake
from conan.tools.files import copy, save, load
from conan.tools.scm import Version
import os
import textwrap
class AlgebraicHashingConan(ConanFile):
"""
Conan package for AlgebraicHashing - Modern C++ library for algebraic hash function composition.
This header-only library provides:
- Modern C++20 concepts for type-safe hash function composition
- Elegant DSL for algebraic operations on hash functions
- Educational framework for understanding hash function mathematics
- High-performance implementations with zero-cost abstractions
"""
name = "algebraic_hashing"
version = "2.0.0"
# Package Metadata
description = "Modern C++20 library for algebraic hash function composition"
license = "MIT"
author = "Algebraic Hashing Project"
url = "https://github.com/queelius/algebraic_hashing"
homepage = "https://github.com/queelius/algebraic_hashing"
topics = ("hash-functions", "cryptography", "algorithms", "cpp20", "header-only", "mathematics")
# Binary Configuration
package_type = "header-library"
settings = "os", "compiler", "build_type", "arch"
options = {
"build_tests": [True, False],
"build_examples": [True, False],
"build_benchmarks": [True, False],
"enable_concepts_checking": [True, False],
"enable_statistics": [True, False]
}
default_options = {
"build_tests": False,
"build_examples": True,
"build_benchmarks": False,
"enable_concepts_checking": True,
"enable_statistics": True
}
# Exports
exports = "LICENSE.md"
exports_sources = (
"CMakeLists.txt",
"cmake/*",
"include/*",
"examples/*",
"tests/*",
"README.md",
"LICENSE.md"
)
# No binary dependencies for header-only library
# But we need build dependencies for testing
def requirements(self):
"""Define runtime dependencies (none for header-only library)."""
pass
def build_requirements(self):
"""Define build-time dependencies."""
if self.options.build_tests:
self.test_requires("gtest/1.14.0")
def layout(self):
"""Define the layout for the package."""
cmake_layout(self)
def validate(self):
"""Validate the configuration."""
# Check C++20 support
min_cpp_standard = 20
if hasattr(self.settings, "compiler") and hasattr(self.settings.compiler, "cppstd"):
if Version(str(self.settings.compiler.cppstd)) < min_cpp_standard:
raise ConanInvalidConfiguration(f"AlgebraicHashing requires C++{min_cpp_standard}")
# Check compiler versions for C++20 concepts support
compiler = self.settings.compiler
if compiler == "gcc":
if Version(self.settings.compiler.version) < "10":
raise ConanInvalidConfiguration("AlgebraicHashing requires GCC 10+ for C++20 concepts support")
elif compiler == "clang":
if Version(self.settings.compiler.version) < "12":
raise ConanInvalidConfiguration("AlgebraicHashing requires Clang 12+ for C++20 concepts support")
elif compiler == "Visual Studio":
if Version(self.settings.compiler.version) < "16":
raise ConanInvalidConfiguration("AlgebraicHashing requires Visual Studio 2019+ for C++20 concepts support")
elif compiler == "msvc":
if Version(self.settings.compiler.version) < "192":
raise ConanInvalidConfiguration("AlgebraicHashing requires MSVC 19.2+ for C++20 concepts support")
def generate(self):
"""Generate the necessary files for the build."""
# Generate CMake toolchain
tc = CMakeToolchain(self)
# Set C++20 standard
tc.variables["CMAKE_CXX_STANDARD"] = "20"
tc.variables["CMAKE_CXX_STANDARD_REQUIRED"] = "ON"
tc.variables["CMAKE_CXX_EXTENSIONS"] = "OFF"
# Configure build options
tc.variables["BUILD_TESTING"] = self.options.build_tests
tc.variables["BUILD_EXAMPLES"] = self.options.build_examples
tc.variables["BUILD_BENCHMARKS"] = self.options.build_benchmarks
tc.variables["ENABLE_CONCEPTS_CHECKING"] = self.options.enable_concepts_checking
tc.variables["ENABLE_STATISTICS"] = self.options.enable_statistics
# Platform-specific optimizations
if self.settings.build_type == "Release":
tc.variables["CMAKE_INTERPROCEDURAL_OPTIMIZATION"] = "ON" # Enable LTO
tc.generate()
# Generate CMake dependencies
deps = CMakeDeps(self)
deps.generate()
def build(self):
"""Build the package (mostly validation and examples for header-only)."""
cmake = CMake(self)
cmake.configure()
# Build examples to validate the library
if self.options.build_examples:
cmake.build(target="algebraic_hashing_tutorial")
# Build and run tests if requested
if self.options.build_tests:
cmake.build(target="test_modern_architecture")
cmake.build(target="test_comprehensive_coverage")
# Run tests during build to validate the package
if not self.conf.get("tools.build:skip_test", False):
self.run(os.path.join(self.build_folder, "test_modern_architecture"))
self.run(os.path.join(self.build_folder, "test_comprehensive_coverage"))
# Build benchmarks if requested
if self.options.build_benchmarks:
cmake.build(target="benchmarks")
def package(self):
"""Package the library files."""
# Copy license
copy(self, "LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
# Install using CMake
cmake = CMake(self)
cmake.install()
# Copy additional documentation
copy(self, "README.md", dst=os.path.join(self.package_folder, "docs"), src=self.source_folder)
copy(self, "REFACTORING_SUMMARY.md", dst=os.path.join(self.package_folder, "docs"), src=self.source_folder)
# Copy examples
if self.options.build_examples:
copy(self, "*.cpp", dst=os.path.join(self.package_folder, "examples"),
src=os.path.join(self.source_folder, "examples"))
def package_info(self):
"""Define how consumers should use this package."""
# Header-only library - no compiled libraries to link
self.cpp_info.libs = []
# Set component name for modern CMake usage
self.cpp_info.set_property("cmake_module_name", "AlgebraicHashing")
self.cpp_info.set_property("cmake_target_name", "AlgebraicHashing::algebraic_hashing")
self.cpp_info.set_property("cmake_file_name", "AlgebraicHashing")
# Legacy CMake support
self.cpp_info.names["cmake_find_package"] = "AlgebraicHashing"
self.cpp_info.names["cmake_find_package_multi"] = "AlgebraicHashing"
# Include directories
self.cpp_info.includedirs = ["include"]
# Required C++20 features
self.cpp_info.cppstd = "20"
# System libraries (threading)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
# Compiler-specific flags
# No additional compiler flags needed - let consumers handle optimization
# Header-only library should not impose specific optimization flags
# Preprocessor definitions based on options
if self.options.enable_concepts_checking:
self.cpp_info.defines.append("ALGEBRAIC_HASHING_ENABLE_CONCEPTS_CHECKING")
if self.options.enable_statistics:
self.cpp_info.defines.append("ALGEBRAIC_HASHING_ENABLE_STATISTICS")
# Package metadata for tools
self.cpp_info.set_property("component_version", self.version)
def package_id(self):
"""Define what affects the package binary compatibility."""
# Header-only library - clear all settings/requirements
self.info.clear()
# For header-only library, no specific package ID customization needed
def ConanInvalidConfiguration(message):
"""Helper for invalid configuration exception."""
class InvalidConfig(Exception):
pass
return InvalidConfig(message)