This repository has been archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
conanfile.py
129 lines (109 loc) · 5.31 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
from conans import ConanFile, CMake, tools
import os
class grpcConan(ConanFile):
name = "grpc"
version = "1.16.0-pre1"
description = "Google's RPC library and framework."
url = "https://github.com/inexorgame/conan-grpc"
homepage = "https://github.com/grpc/grpc"
license = "Apache-2.0"
requires = "zlib/1.2.11@conan/stable", "OpenSSL/1.0.2p@conan/stable", "protobuf/3.6.1@bincrafters/stable", "c-ares/1.14.0@conan/stable"
settings = "os", "compiler", "build_type", "arch"
options = {
# "shared": [True, False],
"fPIC": [True, False],
"build_codegen": [True, False],
"build_csharp_ext": [True, False],
"build_tests": [True, False]
}
default_options = {
"fPIC": True,
"build_codegen": True,
"build_csharp_ext": False,
"build_tests": False
}
exports_sources = "CMakeLists.txt",
generators = "cmake"
short_paths = True # Otherwise some folders go out of the 260 chars path length scope rapidly (on windows)
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
def configure(self):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
del self.options.fPIC
compiler_version = int(str(self.settings.compiler.version))
if compiler_version < 14:
raise tools.ConanException("gRPC can only be built with Visual Studio 2015 or higher.")
def source(self):
archive_url = "https://github.com/grpc/grpc/archive/v{}.zip".format(self.version)
tools.get(archive_url, sha256="ee638c367747f0811a0ad05816ccb99d9e73cfa84d39727a3a4d63693036a89d")
os.rename("grpc-{!s}".format(self.version), self._source_subfolder)
# cmake_name = "{}/CMakeLists.txt".format(self._source_subfolder)
# 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 build_requirements(self):
if self.options.build_tests:
self.build_requires("benchmark/1.4.1@inexorgame/stable")
self.build_requires("gflags/2.2.1@bincrafters/stable")
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'] = "ON" if self.options.build_tests else "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"
# Workaround for https://github.com/grpc/grpc/issues/11068
if self.options.build_tests:
cmake.definitions['gRPC_GFLAGS_PROVIDER'] = "package"
cmake.definitions['gRPC_BENCHMARK_PROVIDER'] = "package"
else:
cmake.definitions['gRPC_GFLAGS_PROVIDER'] = "none"
cmake.definitions['gRPC_BENCHMARK_PROVIDER'] = "none"
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.cpp_info.libs = ["grpc", "grpc++", "grpc_unsecure", "grpc++_unsecure", "gpr", "address_sorting"]
if self.settings.compiler == "Visual Studio":
self.cpp_info.libs += ["wsock32", "ws2_32"]