-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
executable file
·89 lines (76 loc) · 3.59 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from conans import ConanFile, CMake, tools
from conans.model.version import Version
from conans.errors import ConanInvalidConfiguration
class ProtobufConan(ConanFile):
name = "protobuf"
version = "3.11.2"
url = "https://github.com/zinnion/conan-protobuf"
homepage = "https://github.com/protocolbuffers/protobuf"
topics = ("conan", "protobuf", "protocol-buffers", "protocol-compiler", "serialization", "rpc")
author = "Zinnion <mauro@zinnion.com>"
description = "Protocol Buffers - Google's data interchange format"
license = "BSD-3-Clause"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
short_paths = True
options = {"shared": [True, False],
"with_zlib": [True, False],
"fPIC": [True, False],
"lite": [True, False]}
default_options = {"with_zlib": True,
"shared": False,
"fPIC": True,
"lite": True}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
@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, the protobuf/3.6.x package can only be built with the "
"Visual Studio 2015 or higher.")
def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11@zinnion/stable")
def source(self):
tools.get("{0}/archive/v{1}.tar.gz".format(self.homepage, self.version))
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
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"] = True
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):
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
def package_info(self):
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
protoc = "protoc.exe" if self.settings.os == "Windows" else "protoc"
self.env_info.protobuf_BUILD_PROTOC_BINARIES = os.path.normpath(os.path.join(self.package_folder, "bin", protoc))
self.cpp_info.libs = tools.collect_libs(self)
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"]