forked from sdmg15/conan-grpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
155 lines (131 loc) · 5.99 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
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
class grpcConan(ConanFile):
name = "grpc"
version = "1.26.0"
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"
options = {
# "shared": [True, False],
"fPIC": [True, False],
"build_codegen": [True, False],
"build_csharp_ext": [True, False]
}
default_options = {
"fPIC": True,
"build_codegen": True,
"build_csharp_ext": False
}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
requires = (
"zlib/1.2.11",
"openssl/1.1.1d",
"protobuf/3.9.1@bincrafters/stable",
"protoc_installer/3.9.1@bincrafters/stable",
"c-ares/1.15.0"
)
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")
# See https://github.com/grpc/grpc/issues/21293 - OpenSSL 1.1.1+ doesn't work without
tools.replace_in_file(
cmake_path, "set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)", "set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32 crypt32)")
# cmake_find_package_multi is producing a c-ares::c-ares target, grpc is looking for c-ares::cares
tools.replace_in_file(
os.path.join(self._source_subfolder, "cmake", "cares.cmake"), "c-ares::cares", "c-ares::c-ares")
# Parts which should be options:
# grpc_cronet
# grpc++_cronet
# grpc_unsecure (?)
# grpc++_unsecure (?)
# grpc++_reflection
# gen_hpack_tables (?)
# gen_legal_metadata_characters (?)
# grpc_csharp_plugin
# grpc_node_plugin
# grpc_objective_c_plugin
# grpc_php_plugin
# grpc_python_plugin
# grpc_ruby_plugin
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
# non_cpp_plugins=False # Enables plugins such as --java-out and --py-out (if False, only --cpp-out is possible)
#
# cmake.definitions['CONAN_ADDITIONAL_PLUGINS'] = "ON" if self.options.build_csharp_ext else "OFF"
#
# Doesn't work yet for the same reason as above
#
# 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_CARES_PROVIDER'] = "package"
cmake.definitions['gRPC_ZLIB_PROVIDER'] = "package"
cmake.definitions['gRPC_SSL_PROVIDER'] = "package"
cmake.definitions['gRPC_PROTOBUF_PROVIDER'] = "package"
# Compilation on minGW GCC requires to set _WIN32_WINNTT to at least 0x600
# https://github.com/grpc/grpc/blob/109c570727c3089fef655edcdd0dd02cc5958010/include/grpc/impl/codegen/port_platform.h#L44
if self.settings.os == "Windows" and self.settings.compiler == "gcc":
cmake.definitions["CMAKE_CXX_FLAGS"] = "-D_WIN32_WINNT=0x600"
cmake.definitions["CMAKE_C_FLAGS"] = "-D_WIN32_WINNT=0x600"
cmake.configure(build_folder=self._build_subfolder)
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
cmake = self._configure_cmake()
cmake.install()
self.copy(pattern="LICENSE", dst="licenses")
self.copy('*', dst='include', src='{}/include'.format(self._source_subfolder))
self.copy('*.cmake', dst='lib', src='{}/lib'.format(self._build_subfolder), keep_path=True)
self.copy("*.lib", dst="lib", src="", keep_path=False)
self.copy("*.a", dst="lib", src="", keep_path=False)
self.copy("*", dst="bin", src="bin")
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
def package_info(self):
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
self.cpp_info.libs = [
"grpc++_unsecure",
"grpc++_reflection",
"grpc++_error_details",
"grpc++",
"grpc_unsecure",
"grpc_plugin_support",
"grpc_cronet",
"grpcpp_channelz",
"grpc",
"gpr",
"address_sorting",
"upb",
]
if self.settings.compiler == "Visual Studio":
self.cpp_info.system_libs += ["wsock32", "ws2_32"]