text: import os
  from conans import ConanFile, CMake, tools
  from conans.errors import ConanInvalidConfiguration
  from conans.tools import Version
  
  
  class ProtobufConan(ConanFile):
      name = "protobuf"
      description = "Protocol Buffers - Google's data interchange format"
      topics = ("conan", "protobuf", "protocol-buffers", "protocol-compiler", "serialization", "rpc", "protocol-compiler")
      url = "https://github.com/conan-io/conan-center-index"
      homepage = "https://github.com/protocolbuffers/protobuf"
      license = "BSD-3-Clause"
      exports_sources = ["CMakeLists.txt", "protobuf.patch"]
      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}
  
      @property
      def _source_subfolder(self):
          return "source_subfolder"
  
      @property
      def _build_subfolder(self):
          return "build_subfolder"
  
      @property
      def _is_clang_x86(self):
          return self.settings.compiler == "clang" and self.settings.arch == "x86"
  
      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 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)
          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()
          tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
          tools.rmdir(os.path.join(self.package_folder, "cmake"))
          tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
  
  
      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"]
          self.cpp_info.name = "Protobuf"
  