Repository: conan-io/conan-center-index

Issue:
[package] libunwind/1.3.1 library dependency order is wrong
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **libunwind/1.3.1**
  * Operating System+version: **Linux Ubuntu 18.04**
  * Compiler+version: **GCC 7**
  * Conan version: **conan 1.21.1**
  * Python version: **Python 2.7.17, 3.6.9**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=7
compiler.libcxx=libstdc++1+
[options]
[build_requires]
[env]
```

But **error occurs when static linking**, that is shared=False.

### Steps to reproduce (Include if Applicable)

Soon I will write an example to reproduce.

But there is [an example about libunwind library dependency](https://github.com/daniel-thompson/libunwind-examples/blob/master/Makefile)

* current order : `unwind` `unwind-generic` `unwind-ptrace`
* right order : `unwind-ptrace` `unwind-generic` `unwind`

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
Put your log output here
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/libunwind/all/conanfile.py b/recipes/libunwind/all/conanfile.py
--- a/recipes/libunwind/all/conanfile.py
+++ b/recipes/libunwind/all/conanfile.py
@@ -24,6 +24,8 @@ def _source_subfolder(self):
     def configure(self):
         if self.settings.os not in ["Linux", "FreeBSD"]:
             raise ConanInvalidConfiguration("libunwind is only supported on Linux and FreeBSD")
+        if self.options.shared:
+            del self.options.fPIC
         del self.settings.compiler.libcxx
         del self.settings.compiler.cppstd
 
@@ -61,6 +63,23 @@ def package(self):
                 os.unlink(filename)
 
     def package_info(self):
-        self.cpp_info.libs = tools.collect_libs(self)
+        self.cpp_info.components["unwind"].names["pkg_config"] = "libunwind"
+        self.cpp_info.components["unwind"].libs = ["unwind"]
+        self.cpp_info.components["unwind"].requires = ["xz_utils::xz_utils"]
         if self.settings.os == "Linux":
-            self.cpp_info.system_libs.append("pthread")
+            self.cpp_info.components["unwind"].system_libs.append("pthread")
+        self.cpp_info.components["generic"].names["pkg_config"] = "libunwind-generic"
+        self.cpp_info.components["generic"].libs = ["unwind-generic"]
+        self.cpp_info.components["generic"].requires = ["unwind"]
+        if self.options.ptrace:
+            self.cpp_info.components["ptrace"].names["pkg_config"] = "libunwind-ptrace"
+            self.cpp_info.components["ptrace"].libs = ["unwind-ptrace"]
+            self.cpp_info.components["ptrace"].requires = ["generic", "unwind"]
+        if self.options.setjmp:
+            self.cpp_info.components["setjmp"].names["pkg_config"] = "libunwind-setjmp"
+            self.cpp_info.components["setjmp"].libs = ["unwind-setjmp"]
+            self.cpp_info.components["setjmp"].requires = ["unwind"]
+        if self.options.coredump:
+            self.cpp_info.components["coredump"].names["pkg_config"] = "libunwind-coredump"
+            self.cpp_info.components["coredump"].libs = ["unwind-coredump"]
+            self.cpp_info.components["coredump"].requires = ["generic", "unwind"]


Test patch:
diff --git a/recipes/libunwind/all/test_package/CMakeLists.txt b/recipes/libunwind/all/test_package/CMakeLists.txt
--- a/recipes/libunwind/all/test_package/CMakeLists.txt
+++ b/recipes/libunwind/all/test_package/CMakeLists.txt
@@ -1,10 +1,10 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.1)
 project(test_package C)
 
-set(CMAKE_VERBOSE_MAKEFILE TRUE)
-
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
 conan_basic_setup()
 
+find_package(libunwind CONFIG REQUIRED)
+
 add_executable(${PROJECT_NAME} test_package.c)
-target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
+target_link_libraries(${PROJECT_NAME} libunwind::libunwind)
diff --git a/recipes/libunwind/all/test_package/conanfile.py b/recipes/libunwind/all/test_package/conanfile.py
--- a/recipes/libunwind/all/test_package/conanfile.py
+++ b/recipes/libunwind/all/test_package/conanfile.py
@@ -4,7 +4,7 @@
 
 class TestPackageConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
-    generators = "cmake"
+    generators = "cmake", "cmake_find_package_multi"
 
     def build(self):
         cmake = CMake(self)
@@ -15,4 +15,3 @@ def test(self):
         if not tools.cross_building(self.settings):
             bin_path = os.path.join("bin", "test_package")
             self.run(bin_path, run_environment=True)
-
diff --git a/recipes/libunwind/all/test_package/test_package.c b/recipes/libunwind/all/test_package/test_package.c
--- a/recipes/libunwind/all/test_package/test_package.c
+++ b/recipes/libunwind/all/test_package/test_package.c
@@ -1,6 +1,8 @@
+#include <stdio.h>
 #define UNW_LOCAL_ONLY
 #include <libunwind.h>
 
+
 void show_backtrace (void) {
   unw_cursor_t cursor; unw_context_t uc;
   unw_word_t ip, sp;
@@ -17,4 +19,4 @@ void show_backtrace (void) {
 int main() {
     show_backtrace();
     return 0;
-}
\ No newline at end of file
+}