Repository: conan-io/conan-center-index

Issue:
[package] <glog>/<0.5.0>: Linked with libunwind but missing from requirements
It seems that `glog` is linking with `libunwind` but does not include it in the requirements. I just recognized this after trying to build on a machine missing `libunwind` with `*:shared=True`.

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **glog/0.5.0**
  * Operating System+version: **Alma Linux 8.4**
  * Compiler+version: **Clang 10.0.1**
  * Conan version: **conan 1.41.0**
  * Python version: **Python 3.9.6**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
Configuration for profile default:

[settings]
os=Linux
os_build=Linux
os.kernel=4.18
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=10
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Release
[options]
pkgconf:shared=False
[conf]
[build_requires]
[env]
m4:LDFLAGS=['-rtlib=compiler-rt']
```


### Steps to reproduce (Include if Applicable)

Build a project using `glog/0.5.0` with `*:shared=True` and try to run the produced executable.

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
./bin/test: error while loading shared libraries: libunwind.so.8: cannot open shared object file: No such file or directory
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/glog/all/conanfile.py b/recipes/glog/all/conanfile.py
--- a/recipes/glog/all/conanfile.py
+++ b/recipes/glog/all/conanfile.py
@@ -1,7 +1,10 @@
-from conans import ConanFile, CMake, tools
+from conan import ConanFile
+from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
+from conan.tools.files import apply_conandata_patches, copy, get, replace_in_file, rmdir
+from conan.tools.scm import Version
 import os
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.51.1"
 
 
 class GlogConan(ConanFile):
@@ -18,25 +21,25 @@ class GlogConan(ConanFile):
         "fPIC": [True, False],
         "with_gflags": [True, False],
         "with_threads": [True, False],
+        "with_unwind": [True, False],
     }
     default_options = {
         "shared": False,
         "fPIC": True,
         "with_gflags": True,
         "with_threads": True,
+        "with_unwind": True,
     }
 
-    exports_sources = ["CMakeLists.txt", "patches/**"]
-    generators = "cmake", "cmake_find_package"
-    _cmake = None
-
-    @property
-    def _source_subfolder(self):
-        return "source_subfolder"
+    def export_sources(self):
+        for p in self.conan_data.get("patches", {}).get(self.version, []):
+            copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)
 
     def config_options(self):
         if self.settings.os == "Windows":
             del self.options.fPIC
+        if self.settings.os not in ["Linux", "FreeBSD"] or Version(self.version) < "0.5.0":
+            del self.options.with_unwind
 
     def configure(self):
         if self.options.shared:
@@ -44,62 +47,68 @@ def configure(self):
         if self.options.with_gflags:
             self.options["gflags"].shared = self.options.shared
 
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
     def requirements(self):
         if self.options.with_gflags:
             self.requires("gflags/2.2.2")
+        # 0.4.0 requires libunwind unconditionally
+        if self.options.get_safe("with_unwind") or (Version(self.version) < "0.5.0" and self.settings.os in ["Linux", "FreeBSD"]):
+            self.requires("libunwind/1.6.2")
 
     def build_requirements(self):
-        if tools.Version(self.version) >= "0.6.0":
+        if Version(self.version) >= "0.6.0":
             self.build_requires("cmake/3.22.3")
 
     def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-                  destination=self._source_subfolder, strip_root=True)
+        get(self, **self.conan_data["sources"][self.version],
+                  destination=self.source_folder, strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.variables["WITH_GFLAGS"] = self.options.with_gflags
+        tc.variables["WITH_THREADS"] = self.options.with_threads
+        tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
+        if Version(self.version) >= "0.5.0":
+            tc.variables["WITH_PKGCONFIG"] = True
+            if self.settings.os == "Emscripten":
+                tc.variables["WITH_SYMBOLIZE"] = False
+                tc.variables["HAVE_SYSCALL_H"] = False
+                tc.variables["HAVE_SYS_SYSCALL_H"] = False
+            else:
+                tc.variables["WITH_SYMBOLIZE"] = True
+            tc.variables["WITH_UNWIND"] = self.options.get_safe("with_unwind", default=False)
+        tc.variables["BUILD_TESTING"] = False
+        tc.variables["WITH_GTEST"] = False
+        tc.generate()
 
     def _patch_sources(self):
-        for patch in self.conan_data.get("patches", {}).get(self.version, []):
-            tools.patch(**patch)
+        apply_conandata_patches(self)
         # do not force PIC
-        if tools.Version(self.version) <= "0.5.0":
-            tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
+        if Version(self.version) <= "0.5.0":
+            replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
                                   "set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)",
                                   "")
 
-    def _configure_cmake(self):
-        if self._cmake:
-            return self._cmake
-        self._cmake = CMake(self)
-        self._cmake.definitions["WITH_GFLAGS"] = self.options.with_gflags
-        self._cmake.definitions["WITH_THREADS"] = self.options.with_threads
-        if tools.Version(self.version) >= "0.5.0":
-            self._cmake.definitions["WITH_PKGCONFIG"] = True
-            if self.settings.os == "Emscripten":
-                self._cmake.definitions["WITH_SYMBOLIZE"] = False
-                self._cmake.definitions["HAVE_SYSCALL_H"] = False
-                self._cmake.definitions["HAVE_SYS_SYSCALL_H"] = False
-            else:
-                self._cmake.definitions["WITH_SYMBOLIZE"] = True
-            self._cmake.definitions["WITH_UNWIND"] = True
-        self._cmake.definitions["BUILD_TESTING"] = False
-        self._cmake.configure()
-        return self._cmake
-
     def build(self):
         self._patch_sources()
-        cmake = self._configure_cmake()
+        cmake = CMake(self)
+        cmake.configure()
         cmake.build()
 
     def package(self):
-        self.copy("COPYING", dst="licenses", src=self._source_subfolder)
-        cmake = self._configure_cmake()
+        self.copy("COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        cmake = CMake(self)
         cmake.install()
-        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
-        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "share"))
 
     def package_info(self):
-        self.cpp_info.names["cmake_find_package"] = "glog"
-        self.cpp_info.names["cmake_find_package_multi"] = "glog"
-        self.cpp_info.names["pkgconfig"] = "libglog"
+        self.cpp_info.set_property("cmake_file_name", "glog")
+        self.cpp_info.set_property("cmake_target_name", "glog::glog")
+        self.cpp_info.set_property("pkg_config_name", "libglog")
         postfix = "d" if self.settings.build_type == "Debug" else ""
         self.cpp_info.libs = ["glog" + postfix]
         if self.settings.os == "Linux":
@@ -108,6 +117,6 @@ def package_info(self):
             self.cpp_info.system_libs = ["dbghelp"]
             self.cpp_info.defines = ["GLOG_NO_ABBREVIATED_SEVERITIES"]
             decl = "__declspec(dllimport)" if self.options.shared else ""
-            self.cpp_info.defines.append("GOOGLE_GLOG_DLL_DECL={}".format(decl))
+            self.cpp_info.defines.append(f"GOOGLE_GLOG_DLL_DECL={decl}")
         if self.options.with_gflags and not self.options.shared:
             self.cpp_info.defines.extend(["GFLAGS_DLL_DECLARE_FLAG=", "GFLAGS_DLL_DEFINE_FLAG="])


Test patch: