From 2fd5a648b4af79b68269b9dffa4e32271a2840e8 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Wed, 10 Mar 2021 17:01:15 -0500 Subject: [PATCH] (#4682) feat(protobuf): Add an option to remove RTTI from binaries * 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 --- recipes/protobuf/all/conandata.yml | 3 +++ recipes/protobuf/all/conanfile.py | 31 ++++++++++++++++++++++++++---- recipes/protobuf/config.yml | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/recipes/protobuf/all/conandata.yml b/recipes/protobuf/all/conandata.yml index c3ba8d116ec39..04f1bd41cb0b0 100644 --- a/recipes/protobuf/all/conandata.yml +++ b/recipes/protobuf/all/conandata.yml @@ -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" diff --git a/recipes/protobuf/all/conanfile.py b/recipes/protobuf/all/conanfile.py index 55acec5195834..f34f30dec5d7b 100644 --- a/recipes/protobuf/all/conanfile.py +++ b/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 @@ -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 @@ -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: @@ -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") @@ -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) diff --git a/recipes/protobuf/config.yml b/recipes/protobuf/config.yml index 0899537fde3dc..6f75a293b3fd8 100644 --- a/recipes/protobuf/config.yml +++ b/recipes/protobuf/config.yml @@ -7,3 +7,5 @@ versions: folder: all 3.13.0: folder: all + 3.15.5: + folder: all