-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconanfile.py
More file actions
135 lines (116 loc) · 5.05 KB
/
Copy pathconanfile.py
File metadata and controls
135 lines (116 loc) · 5.05 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.build import check_min_cppstd
import os
class HppProtoConan(ConanFile):
name = "hpp_proto"
version = "1.0.0"
license = "Apache-2.0"
url = "https://github.com/huangminghuang/hpp-proto"
description = "A modern C++23 implementation of Protocol Buffers."
topics = ("protobuf", "serialization", "codegen")
settings = ("os", "compiler", "build_type", "arch")
options = {
"tests": [True, False],
"with_protobuf": [True, False],
}
default_options = {
"tests": False,
"with_protobuf": False,
}
exports_sources = (
"CMakeLists.txt",
"cmake/*",
"hpp_proto-config.cmake.in",
"third-parties.cmake",
"include/*",
"src/*",
"tests/*",
"tutorial/*",
"LICENSE",
"README.md",
)
def _cmake_path(self, exe_path, add_exe_suffix=False):
if exe_path is None:
return None
suffix = ""
if add_exe_suffix and str(self.settings.os) == "Windows":
suffix = ".exe"
return (exe_path + suffix).replace("\\", "/")
def validate(self):
cppstd = self.settings.get_safe("compiler.cppstd")
if cppstd is not None:
check_min_cppstd(self, "23")
def requirements(self):
self.requires("glaze/7.8.4")
def build_requirements(self):
self.protoc_mode = self.conf.get("user.hpp_proto:protoc", default="find")
if self.options.with_protobuf:
self.tool_requires("protobuf/[>=3.21.12]")
def layout(self):
cmake_layout(self)
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.variables["HPP_PROTO_TESTS"] = "ON" if self.options.tests else "OFF"
tc.variables["HPP_PROTO_PROTOC"] = self.protoc_mode
self.protoc_executable = None
if self.options.with_protobuf:
protobuf_dep = self.dependencies.build.get("protobuf")
if protobuf_dep is not None:
protoc_path = os.path.join(protobuf_dep.package_folder, "bin", "protoc")
self.protoc_executable = self._cmake_path(protoc_path, add_exe_suffix=True)
if os.path.isfile(self.protoc_executable):
tc.variables["PROTOC_PROGRAM"] = self.protoc_executable
else:
self.protoc_executable = None
tc.variables["CPM_USE_LOCAL_PACKAGES"] = "ON"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
cmake_config_folder = os.path.join(self.package_folder, "lib", "cmake", "hpp_proto")
src_cmake_folder = os.path.join(self.source_folder, "cmake")
src = os.path.join(src_cmake_folder, "conan_protoc_target.cmake")
dest = os.path.join(cmake_config_folder, "conan_protoc_target.cmake")
with open(src, "r", encoding="utf-8") as handle:
existing = handle.read()
with open(dest, "w", encoding="utf-8") as handle:
content = []
if self.protoc_executable:
content.append(f"set(PROTOC_PROGRAM \"{self.protoc_executable}\")")
protoc_gen_hpp_path = os.path.join(
self.package_folder, "bin", "protoc-gen-hpp"
)
cmake_protoc_gen_hpp_path = self._cmake_path(protoc_gen_hpp_path, add_exe_suffix=True)
content.append(f"set(PROTOC_GEN_HPP_PROGRAM \"{cmake_protoc_gen_hpp_path}\")")
content.append(existing)
handle.write("\n".join(content))
def package_info(self):
self.cpp_info.set_property("cmake_target_name", "hpp_proto::hpp_proto")
core = self.cpp_info.components["core"]
core.libs = ["is_utf8"]
core.set_property("cmake_target_name", "hpp_proto::hpp_proto_core")
core.requires = ["glaze::glaze"]
well_known_types = self.cpp_info.components["well_known_types"]
well_known_types.set_property("cmake_target_name", "hpp_proto::well_known_types")
well_known_types.requires = ["core"]
descriptor_lib = self.cpp_info.components["descriptor_lib"]
descriptor_lib.set_property("cmake_target_name", "hpp_proto::descriptor_lib")
descriptor_lib.requires = ["core"]
self.cpp_info.requires = ["core", "well_known_types", "descriptor_lib"]
dynamic_message = self.cpp_info.components["dynamic_message"]
dynamic_message.libs = ["dynamic_message"]
dynamic_message.set_property("cmake_target_name", "hpp_proto::dynamic_message")
dynamic_message.requires = ["core", "well_known_types", "glaze::glaze"]
self.cpp_info.set_property(
"cmake_build_modules",
["lib/cmake/hpp_proto/conan_protoc_target.cmake",
"lib/cmake/hpp_proto/protobuf_generate_hpp.cmake"],
)
self.cpp_info.set_property("cmake_file_name", "hpp_proto")