Repository: conan-io/conan

Issue:
[bug] QMake generator does not honour system_libs
It seems the QMake generator, [like the SCons generator](https://github.com/conan-io/conan/issues/7301), was overlooked in https://github.com/conan-io/conan/pull/5582 which added `cpp_info.system_libs`.

### Environment Details (include every applicable attribute)

  * Operating System+version: Arch Linux
  * Compiler+version: gcc (GCC) 10.1.0
  * Conan version: 1.28.0
  * Python version: 3.8.5

### Steps to reproduce (Include if Applicable)
`conanfile.txt`:

```
[requires]
icu/67.1

[generators]
qmake
```

On Linux, the icu recipe adds `pthread` to `cpp_info.system_libs`:

https://github.com/conan-io/conan-center-index/blob/d6c56bef267cab013b13fbb35b9426735b78bd5e/recipes/icu/all/conanfile.py#L235

However, this is not reflected in the generated conanbuildinfo.pri:

```
$ grep pthread conanbuildinfo.pri
$
$ grep -i _libs conanbuildinfo.pri
CONAN_LIBS += -licui18n -licuio -licutest -licutu -licuuc -licudata
CONAN_LIBS_ICU += -licui18n -licuio -licutest -licutu -licuuc -licudata
    LIBS += $$CONAN_LIBS
        LIBS += $$CONAN_LIBS_RELEASE
        LIBS += $$CONAN_LIBS_DEBUG
```

Indeed `generators/qmake.py`, unlike most of the other generators, does not contain the text `system_libs` anywhere.

My actual problem is not with icu but with a proprietary package that I'm maintaining myself, so as a workaround I tried adding `cpp_info.exeflags.append('-lpthread')`. That gets added to the link command properly, but in the wrong order (it should be after the dependent lib), so it still doesn't work.

A workaround that does work (for me) is to put `self.cpp_info.libs += self.cpp_info.system_libs` at the end of the `package_info` function.

I think the solution for QMake would be to just add system libs to the end of the `*_LIBS` variables.
[bug] QMake generator does not honour system_libs
It seems the QMake generator, [like the SCons generator](https://github.com/conan-io/conan/issues/7301), was overlooked in https://github.com/conan-io/conan/pull/5582 which added `cpp_info.system_libs`.

### Environment Details (include every applicable attribute)

  * Operating System+version: Arch Linux
  * Compiler+version: gcc (GCC) 10.1.0
  * Conan version: 1.28.0
  * Python version: 3.8.5

### Steps to reproduce (Include if Applicable)
`conanfile.txt`:

```
[requires]
icu/67.1

[generators]
qmake
```

On Linux, the icu recipe adds `pthread` to `cpp_info.system_libs`:

https://github.com/conan-io/conan-center-index/blob/d6c56bef267cab013b13fbb35b9426735b78bd5e/recipes/icu/all/conanfile.py#L235

However, this is not reflected in the generated conanbuildinfo.pri:

```
$ grep pthread conanbuildinfo.pri
$
$ grep -i _libs conanbuildinfo.pri
CONAN_LIBS += -licui18n -licuio -licutest -licutu -licuuc -licudata
CONAN_LIBS_ICU += -licui18n -licuio -licutest -licutu -licuuc -licudata
    LIBS += $$CONAN_LIBS
        LIBS += $$CONAN_LIBS_RELEASE
        LIBS += $$CONAN_LIBS_DEBUG
```

Indeed `generators/qmake.py`, unlike most of the other generators, does not contain the text `system_libs` anywhere.

My actual problem is not with icu but with a proprietary package that I'm maintaining myself, so as a workaround I tried adding `cpp_info.exeflags.append('-lpthread')`. That gets added to the link command properly, but in the wrong order (it should be after the dependent lib), so it still doesn't work.

A workaround that does work (for me) is to put `self.cpp_info.libs += self.cpp_info.system_libs` at the end of the `package_info` function.

I think the solution for QMake would be to just add system libs to the end of the `*_LIBS` variables.


Discussion:
Hi @ttencate 

Yes, you are right, this seems to be missing. As the changes should be relatively straightforward, would you like to contribute yourself to the fix in ``QmakeGenerator`` class? If not, possible, not a problem, we will manage it (but it might need to wait until next Conan 1.30 release). Thanks for reporting!
Hi @ttencate 

Yes, you are right, this seems to be missing. As the changes should be relatively straightforward, would you like to contribute yourself to the fix in ``QmakeGenerator`` class? If not, possible, not a problem, we will manage it (but it might need to wait until next Conan 1.30 release). Thanks for reporting!

Resolving patch:
diff --git a/conans/client/generators/qmake.py b/conans/client/generators/qmake.py
--- a/conans/client/generators/qmake.py
+++ b/conans/client/generators/qmake.py
@@ -18,6 +18,7 @@ def multiline(field):
         self.build_paths = multiline(cpp_info.build_paths)
 
         self.libs = " ".join('-l%s' % lib for lib in cpp_info.libs)
+        self.system_libs = " ".join('-l%s' % lib for lib in cpp_info.system_libs)
         self.defines = " \\\n    ".join('"%s"' % d for d in cpp_info.defines)
         self.cxxflags = " ".join(cpp_info.cxxflags)
         self.cflags = " ".join(cpp_info.cflags)
@@ -38,6 +39,7 @@ def content(self):
 
         template = ('CONAN_INCLUDEPATH{dep_name}{build_type} += {deps.include_paths}\n'
                     'CONAN_LIBS{dep_name}{build_type} += {deps.libs}\n'
+                    'CONAN_SYSTEMLIBS{dep_name}{build_type} += {deps.system_libs}\n'
                     'CONAN_LIBDIRS{dep_name}{build_type} += {deps.lib_paths}\n'
                     'CONAN_BINDIRS{dep_name}{build_type} += {deps.bin_paths}\n'
                     'CONAN_RESDIRS{dep_name}{build_type} += {deps.res_paths}\n'
@@ -92,6 +94,12 @@ def content(self):
         BINDIRS += $$CONAN_BINDIRS_DEBUG
         DEFINES += $$CONAN_DEFINES_DEBUG
     }
+    LIBS += $$CONAN_SYSTEMLIBS
+    CONFIG(release, debug|release) {
+        LIBS += $$CONAN_SYSTEMLIBS_RELEASE
+    } else {
+        LIBS += $$CONAN_SYSTEMLIBS_DEBUG
+    }
     QMAKE_CXXFLAGS += $$CONAN_QMAKE_CXXFLAGS
     QMAKE_CFLAGS += $$CONAN_QMAKE_CFLAGS
     QMAKE_LFLAGS += $$CONAN_QMAKE_LFLAGS


Test patch:
diff --git a/conans/test/unittests/client/generators/qmake_test.py b/conans/test/unittests/client/generators/qmake_test.py
new file mode 100644
--- /dev/null
+++ b/conans/test/unittests/client/generators/qmake_test.py
@@ -0,0 +1,27 @@
+import platform
+import unittest
+
+from conans.client.generators.qmake import QmakeGenerator
+from conans.model.build_info import CppInfo, DepCppInfo
+from conans.model.conan_file import ConanFile
+from conans.model.env_info import EnvValues
+from conans.model.settings import Settings
+from conans.test.utils.mocks import TestBufferConanOutput
+
+
+class QmakeGeneratorTest(unittest.TestCase):
+
+    def system_libs_test(self):
+        # https://github.com/conan-io/conan/issues/7558
+        conanfile = ConanFile(TestBufferConanOutput(), None)
+        conanfile.initialize(Settings({}), EnvValues())
+        cpp_info = CppInfo("MyPkg", "/rootpath")
+        cpp_info.libs = ["mypkg"]
+        cpp_info.system_libs = ["pthread"]
+        conanfile.deps_cpp_info.add("MyPkg", DepCppInfo(cpp_info))
+        generator = QmakeGenerator(conanfile)
+        content = generator.content
+        qmake_lines = content.splitlines()
+        self.assertIn('CONAN_LIBS += -lmypkg', qmake_lines)
+        self.assertIn('CONAN_SYSTEMLIBS += -lpthread', qmake_lines)
+