This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
conanfile.py
82 lines (69 loc) · 3.36 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
import os
from conans import tools, CMake
from conanfile_base import ConanFileBase
from conans.tools import Version
from conans.errors import ConanInvalidConfiguration
class ConanFileDefault(ConanFileBase):
name = ConanFileBase._base_name
version = ConanFileBase.version
exports = ConanFileBase.exports + ["protobuf.patch"]
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"with_zlib": [True, False],
"fPIC": [True, False],
"lite": [True, False]}
default_options = {"with_zlib": False,
"shared": False,
"fPIC": True,
"lite": False}
@property
def _is_clang_x86(self):
return self.settings.compiler == "clang" and self.settings.arch == "x86"
def configure(self):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
del self.options.fPIC
compiler_version = Version(self.settings.compiler.version.value)
if compiler_version < "14":
raise ConanInvalidConfiguration("On Windows Protobuf can only be built with "
"Visual Studio 2015 or higher.")
def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11")
def _configure_cmake(self):
cmake = CMake(self, set_cmake_flags=True)
cmake.definitions["protobuf_BUILD_TESTS"] = False
cmake.definitions["protobuf_WITH_ZLIB"] = self.options.with_zlib
cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = not self.options.lite
cmake.definitions["protobuf_BUILD_PROTOBUF_LITE"] = self.options.lite
if self.settings.compiler == "Visual Studio":
cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in self.settings.compiler.runtime
cmake.configure(build_folder=self._build_subfolder)
return cmake
def build(self):
tools.patch(base_path=self._source_subfolder, patch_file="protobuf.patch")
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
self.copy("*.pdb", dst="lib", src=self._build_subfolder, keep_path=False)
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs.sort(reverse=True)
if self.settings.os == "Linux":
self.cpp_info.libs.append("pthread")
if self._is_clang_x86 or "arm" in str(self.settings.arch):
self.cpp_info.libs.append("atomic")
if self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.defines = ["PROTOBUF_USE_DLLS"]
cmakedir = "cmake" if self.settings.os == "Windows" else os.path.join("lib", "cmake", "protobuf")
self.cpp_info.builddirs = [cmakedir]
self.cpp_info.build_modules = [
os.path.join(cmakedir, "protobuf-config.cmake"),
os.path.join(cmakedir, "protobuf-module.cmake"),
os.path.join(cmakedir, "protobuf-options.cmake"),
os.path.join(cmakedir, "protobuf-targets.cmake"),
os.path.join(cmakedir, "protobuf-targets-{}.cmake".format(str(self.settings.build_type).lower()))
]