-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconanfile.py
More file actions
129 lines (113 loc) · 4.75 KB
/
Copy pathconanfile.py
File metadata and controls
129 lines (113 loc) · 4.75 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
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMakeToolchain, cmake_layout
from conan.tools.files import copy
class XrplRpcSpecConan(ConanFile):
name = "xrpl-rpc-spec"
license = "ISC"
author = "the XRP Ledger developers"
url = "https://github.com/XRPLF/rpc-spec"
description = "Consteval RPC spec DSL for XRPL — shared by Clio and xrpld"
settings = "os", "compiler", "build_type", "arch"
package_type = "header-library"
no_copy_source = True
# The headers travel with the recipe so consumers get a real package (not a
# source build). CMakeLists/tests are exported too for local `conan create`.
exports_sources = (
"include/*",
"cmake/*",
"CMakeLists.txt",
"tests/*",
"LICENSE.md",
"README.md",
)
# Build-time consumers (Clio, xrpld) provide their own xrpl/ripple headers;
# the only direct dependency of the headers is Boost::json. Keep this aligned
# with xrpld's boost version to avoid a clash when consumed there.
requires = [
"boost/1.91.0",
]
options = {
"server": [None, "clio", "xrpld"],
"tests": [True, False],
}
default_options = {
# Defaults to None so that consumers are forced to override
"server": None,
"tests": False,
# boost 1.91's cobalt_io_ssl component fails package_info() unless cobalt
# is disabled (it expects an OpenSSL-backed build we don't pull in).
# We only need Boost::json, so drop cobalt. Mirrors xrpld.
"boost/*:without_cobalt": True,
}
def configure(self):
# Match what Clio and xrpld request, so the prebuilt Boost on the xrplf remote is
# reused instead of rebuilt from source. Both set this for apple-clang.
if self.settings.compiler == "apple-clang":
self.options["boost"].visibility = "global"
def requirements(self):
if self.options.tests:
# Tests run against the xrpld (xrpl::) backend, but mock the small
# libxrpl protocol surface they touch (see tests/stubs), so the only
# real test dependency is gtest. Boost::json comes from the main
# `requires` above.
self.test_requires("gtest/1.17.0")
def validate(self):
if self.options.server is None:
raise ConanInvalidConfiguration(
"xrpl-rpc-spec: the 'server' option must be set to 'clio' or 'xrpld'; "
'add \'"xrpl-rpc-spec/*:server": "clio"\' to your conanfile\'s default_options'
)
def layout(self):
cmake_layout(self)
# In editable mode there is no packaged folder; point consumers at the working
# tree so `conan editable add .` just works. cmake/ holds the instantiation
# generator, which package() would otherwise have copied to lib/cmake/rpcspec.
self.cpp.source.includedirs = ["include"]
self.cpp.source.builddirs = ["cmake"]
# Header-only: the binary is identical across settings, so don't rebuild
# per compiler/arch/build_type.
def package_id(self):
self.info.clear()
# Only used for local standalone test builds (cmake -Drpcspec_tests=ON);
# consumers never run this.
def generate(self):
tc = CMakeToolchain(self)
tc.variables["rpcspec_tests"] = bool(self.options.tests)
tc.generate()
def package(self):
copy(
self,
"*",
src=os.path.join(self.source_folder, "include"),
dst=os.path.join(self.package_folder, "include"),
)
copy(
self,
"*",
src=os.path.join(self.source_folder, "cmake"),
dst=os.path.join(self.package_folder, "cmake"),
)
copy(
self,
"LICENSE.md",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
self.cpp_info.includedirs = ["include"]
self.cpp_info.set_property("cmake_target_name", "rpcspec::rpcspec")
self.cpp_info.requires = ["boost::json"]
self.cpp_info.defines = [f"RPCSPEC_IS_{str(self.options.server).upper()}=1"]
# Deliberately cmake/ rather than lib/cmake/rpcspec: the same relative path then
# resolves for a normal package and for `conan editable add`, where package() has
# not run and consumers read straight from the working tree.
cmake_dir = "cmake"
self.cpp_info.builddirs = [cmake_dir]
self.cpp_info.set_property(
"cmake_build_modules",
[os.path.join(cmake_dir, "RpcSpecInstantiations.cmake")],
)