forked from inexorgame-obsolete/conan-grpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
161 lines (136 loc) · 6.24 KB
/
conanfile.py
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
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
import os
class grpcConan(ConanFile):
name = "grpc"
description = "Google's RPC library and framework."
topics = ("conan", "grpc", "rpc")
url = "https://github.com/inexorgame/conan-grpc"
homepage = "https://github.com/grpc/grpc"
license = "Apache-2.0"
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "cmake_find_package_multi"
short_paths = True
settings = "os", "arch", "compiler", "build_type"
# TODO: Add shared option
options = {
"fPIC": [True, False],
"build_codegen": [True, False],
"build_csharp_ext": [True, False],
"build_cpp_plugin": [True, False],
"build_csharp_plugin": [True, False],
"build_node_plugin": [True, False],
"build_objective_c_plugin": [True, False],
"build_php_plugin": [True, False],
"build_python_plugin": [True, False],
"build_ruby_plugin": [True, False]
}
default_options = {
"fPIC": True,
"build_codegen": True,
"build_csharp_ext": False,
"build_cpp_plugin": True,
"build_csharp_plugin": True,
"build_node_plugin": True,
"build_objective_c_plugin": True,
"build_php_plugin": True,
"build_python_plugin": True,
"build_ruby_plugin": True,
}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
requires = (
"zlib/1.2.11",
"openssl/1.1.1h",
"protobuf/3.13.0",
"c-ares/1.15.0",
"abseil/20200225.3",
"re2/20201101"
)
def configure(self):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
del self.options.fPIC
compiler_version = tools.Version(self.settings.compiler.version)
if compiler_version < 14:
raise ConanInvalidConfiguration("gRPC can only be built with Visual Studio 2015 or higher.")
def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
cmake_path = os.path.join(self._source_subfolder, "CMakeLists.txt")
# See #5
tools.replace_in_file(cmake_path, "_gRPC_PROTOBUF_LIBRARIES", "CONAN_LIBS_PROTOBUF")
def _configure_cmake(self):
cmake = CMake(self)
# This doesn't work yet as one would expect, because the install target builds everything
# and we need the install target because of the generated CMake files
#
# enable_mobile=False # Enables iOS and Android support
#
# cmake.definitions["CONAN_ENABLE_MOBILE"] = "ON" if self.options.build_csharp_ext else "OFF"
cmake.definitions["gRPC_BUILD_CODEGEN"] = "ON" if self.options.build_codegen else "OFF"
cmake.definitions["gRPC_BUILD_CSHARP_EXT"] = "ON" if self.options.build_csharp_ext else "OFF"
cmake.definitions["gRPC_BUILD_TESTS"] = "OFF"
# We need the generated cmake/ files (bc they depend on the list of targets, which is dynamic)
cmake.definitions["gRPC_INSTALL"] = "ON"
# cmake.definitions["CMAKE_INSTALL_PREFIX"] = self._build_subfolder
# tell grpc to use the find_package versions
cmake.definitions["gRPC_ABSL_PROVIDER"] = "package"
cmake.definitions["gRPC_CARES_PROVIDER"] = "package"
cmake.definitions["gRPC_ZLIB_PROVIDER"] = "package"
cmake.definitions["gRPC_SSL_PROVIDER"] = "package"
cmake.definitions["gRPC_PROTOBUF_PROVIDER"] = "package"
cmake.definitions["gRPC_RE2_PROVIDER"] = "package"
cmake.definitions["gRPC_BUILD_GRPC_CPP_PLUGIN"] = self.options.build_cpp_plugin
cmake.definitions["gRPC_BUILD_GRPC_CSHARP_PLUGIN"] = self.options.build_csharp_plugin
cmake.definitions["gRPC_BUILD_GRPC_NODE_PLUGIN"] = self.options.build_node_plugin
cmake.definitions["gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN"] = self.options.build_objective_c_plugin
cmake.definitions["gRPC_BUILD_GRPC_PHP_PLUGIN"] = self.options.build_php_plugin
cmake.definitions["gRPC_BUILD_GRPC_PYTHON_PLUGIN"] = self.options.build_python_plugin
cmake.definitions["gRPC_BUILD_GRPC_RUBY_PLUGIN"] = self.options.build_ruby_plugin
# see https://github.com/inexorgame/conan-grpc/issues/39
if self.settings.os == "Windows":
if not self.options["protobuf"].shared:
cmake.definitions["Protobuf_USE_STATIC_LIBS"] = "ON"
else:
cmake.definitions["PROTOBUF_USE_DLLS"] = "ON"
cmake.configure(build_folder=self._build_subfolder)
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
# tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
# tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
def package_info(self):
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
self.cpp_info.names["cmake_find_package"] = "gRPC"
self.cpp_info.names["cmake_find_package_multi"] = "gRPC"
self.cpp_info.libs = [
"grpc++_unsecure",
"grpc++_reflection",
"grpc++_error_details",
"grpc++",
"grpc_unsecure",
"grpc_plugin_support",
"grpcpp_channelz",
"grpc",
"gpr",
"address_sorting",
"upb",
]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["wsock32", "ws2_32", "crypt32"]
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["dl", "rt", "m", "pthread"]
if tools.is_apple_os(self.settings.os):
self.cpp_info.system_libs = ["m", "pthread"]
if self.settings.os == "Android":
self.cpp_info.system_libs = ["m"]