Skip to content

Commit

Permalink
(#4682) feat(protobuf): Add an option to remove RTTI from binaries
Browse files Browse the repository at this point in the history
* In the protobuf recipe, add an option to remove RTTI from binaries (#4682)

* In the protobuf recipe, display one option per line and sort them

* In the protobuf recipe, if we aren't in a version that supports the removal of RTTI, remove it

That also means there will be no CMake definition, and that Conan will
crash if you request it.

* Warn that versions of Protobuf between 3.15.4 and 4 are not buildable with clang < 4

This change comes from #4776
  • Loading branch information
floriansimon1 committed Mar 10, 2021
1 parent 5e60890 commit 2fd5a64
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions recipes/protobuf/all/conandata.yml
Expand Up @@ -11,6 +11,9 @@ sources:
3.13.0:
sha256: 9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a
url: https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz
3.15.5:
sha256: bc3dbf1f09dba1b2eb3f2f70352ee97b9049066c9040ce0c9b67fb3294e91e4b
url: https://github.com/protocolbuffers/protobuf/archive/v3.15.5.tar.gz
patches:
3.12.4:
- patch_file: "patches/upstream-pr-7761-cmake-regex-fix.patch"
Expand Down
31 changes: 27 additions & 4 deletions recipes/protobuf/all/conanfile.py
@@ -1,5 +1,4 @@
import os
import glob
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
Expand All @@ -17,8 +16,20 @@ class ProtobufConan(ConanFile):
generators = "cmake"
short_paths = True
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}
options = {
"fPIC": [True, False],
"lite": [True, False],
"shared": [True, False],
"with_rtti": [True, False],
"with_zlib": [True, False]
}
default_options = {
"fPIC": True,
"lite": False,
"shared": False,
"with_rtti": True,
"with_zlib": False
}

_cmake = None

Expand All @@ -34,15 +45,20 @@ def _build_subfolder(self):
def _is_clang_x86(self):
return self.settings.compiler == "clang" and self.settings.arch == "x86"

@property
def _can_disable_rtti(self):
return tools.Version(self.version) >= "3.15.4"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = self.name + "-" + self.version
os.rename(extracted_folder, self._source_subfolder)


def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if not self._can_disable_rtti:
del self.options.with_rtti

def configure(self):
if self.options.shared:
Expand All @@ -58,6 +74,11 @@ def configure(self):
if Version(self.settings.compiler.version) < "14":
raise ConanInvalidConfiguration("On Windows Protobuf can only be built with "
"Visual Studio 2015 or higher.")

if self.settings.compiler == "clang":
if tools.Version(self.version) >= "3.15.4" and tools.Version(self.settings.compiler.version) < "4":
raise ConanInvalidConfiguration("protobuf {} doesn't support clang < 4".format(self.version))

def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11")
Expand All @@ -74,6 +95,8 @@ def _configure_cmake(self):
self._cmake.definitions["protobuf_BUILD_TESTS"] = False
self._cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = True
self._cmake.definitions["protobuf_BUILD_LIBPROTOC"] = True
if self._can_disable_rtti:
self._cmake.definitions["protobuf_DISABLE_RTTI"] = not self.options.with_rtti
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in str(self.settings.compiler.runtime)
self._cmake.configure(build_folder=self._build_subfolder)
Expand Down
2 changes: 2 additions & 0 deletions recipes/protobuf/config.yml
Expand Up @@ -7,3 +7,5 @@ versions:
folder: all
3.13.0:
folder: all
3.15.5:
folder: all

0 comments on commit 2fd5a64

Please sign in to comment.