Repository navigation
Expand file tree
/
Copy pathconanfile.py
More file actions
107 lines (93 loc) · 3.96 KB
/
Copy pathconanfile.py
File metadata and controls
107 lines (93 loc) · 3.96 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
import os
import re
from typing import Optional
from conan import ConanFile
from conan.errors import ConanException
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.scm import Git
required_conan_version = ">=2.4"
class VanetzaConan(ConanFile):
name = "vanetza"
url = "https://github.com/riebl/vanetza"
description = "Open-source implementation of the ETSI C-ITS protocol stack"
license = "LGPL-3.0-or-later"
package_type = "library"
languages = "C", "C++"
settings = "os", "compiler", "build_type", "arch"
implements = ["auto_shared_fpic"]
options = {
"fPIC": [True, False],
"shared": [True, False],
"with_cryptopp": [True, False],
"with_openssl": [True, False],
}
default_options = {
"fPIC": True,
"shared": False,
"with_cryptopp": False,
"with_openssl": True,
}
exports_sources = "CMakeLists.txt", "cmake/*", "gtest/CMakeLists.txt", "vanetza/*"
test_package_folder = "tools/conan_test"
def read_project_version(self) -> Optional[str]:
version_re = re.compile(r"project\(Vanetza VERSION ([\d.]+)\)")
with open(os.path.join(self.recipe_folder, "CMakeLists.txt")) as f:
for line in f:
match = version_re.search(line)
if match:
return match.group(1)
return None
def set_version(self):
project_version = self.read_project_version()
if not project_version:
raise ConanException("Could not read version from CMakeLists.txt")
self.version = project_version
git = Git(self, folder=self.recipe_folder)
try:
count = int(git.run(f"rev-list --count v{project_version}..HEAD"))
if count > 0:
short_hash = git.run("rev-parse --short HEAD")
self.version = f"{project_version}-dev+{count}.{short_hash}"
except Exception:
pass
def layout(self):
cmake_layout(self)
def requirements(self):
# Boost is part of Vanetza's public headers and exported link interface
self.requires("boost/[>=1.70]", transitive_headers=True, transitive_libs=True)
self.requires("geographiclib/[>=1.37]")
if self.options.with_cryptopp:
self.requires("cryptopp/[>=5.6.1]")
if self.options.with_openssl:
self.requires("openssl/[>=1.1.1 <4]")
def validate(self):
check_min_cppstd(self, "14")
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["BUILD_TESTS"] = not self.conf.get("tools.build:skip_test", default=False, check_type=bool)
tc.cache_variables["VANETZA_WITH_CRYPTOPP"] = bool(self.options.with_cryptopp)
tc.cache_variables["VANETZA_WITH_OPENSSL"] = bool(self.options.with_openssl)
# pin auto-detected dependencies so libraries outside of Conan are never picked up
tc.cache_variables["VANETZA_WITH_GEOGRAPHICLIB"] = True
tc.cache_variables["VANETZA_WITH_RPC"] = False
# hybrid PQC requires liboqs, which is not available on ConanCenter
tc.cache_variables["VANETZA_WITH_PQC"] = False
tc.generate()
deps = CMakeDeps(self)
# Vanetza states minimum versions, but Conan's version files only accept the same major version by default
for dep in ("geographiclib", "cryptopp"):
deps.set_property(dep, "cmake_config_version_compat", "AnyNewerVersion")
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.test()
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
# use Vanetza's CMake package configuration instead of one generated by Conan
self.cpp_info.set_property("cmake_find_mode", "none")
self.cpp_info.builddirs = [os.path.join("lib", "cmake", "Vanetza")]