Repository: conan-io/conan

Issue:
[bug] self.cpp_info.name breaks pkg-config for some packages
Defining self.cpp_info.name for a package changes (at least) two file names: cmake module `FindFOO` files, and pkg-config files. The problem is that in the wild, the name used for cmake module files and pkg-config files are not always identical, for example zlib has `FindZLIB`, but `zlib.pc`, and expat has `FindEXPAT` but `expat.pc`.
recipes consuming these two packages via pkg-config are broken since these two recipes set `self.cpp_info.name` to uppercase, the workaround being to rename generated `ZLIB.pc` to `zlib.pc` and `EXPAT.pc` to `expat.pc`.
If pkg-config files are always the lower-case version of corresponding `findFOO` cmake file, the simplest fix would be to modify pkg-config generator to use `self.cpp_info.name.lower()` instead of `self.cpp_info.name`. If not, a solution would be to make `self.cpp_info.name` a dictionary mapping generators to name.


Discussion:
Is it possible that this is addressed by https://github.com/conan-io/conan/pull/5973? this will be released in 1.19.3 asap.
I don't think so
@ericLemanissier is the casing of the name of the lib (zlib) different inside the file? I mean, the issue is just the file name or the name of the lib inside the contents of that file too?
More generally it seems that we are currently setting `self.cpp_info.name` to match what we need for CMake to work, but we've got no guarantee that the case will be the same for every build system. Inconsistencies and related issues are very likely.
The library name appears in the pkg-config file, and is currently in uppercase, but it does not seem to have an impact(renaming the file without modifying content solves the problem). According to https://people.freedesktop.org/~dbn/pkg-config-guide.html, name is `A human-readable name for the library or package. This does not affect usage of the pkg-config tool, which uses the name of the .pc file.`

Resolving patch:
diff --git a/conans/client/generators/pkg_config.py b/conans/client/generators/pkg_config.py
--- a/conans/client/generators/pkg_config.py
+++ b/conans/client/generators/pkg_config.py
@@ -34,12 +34,12 @@ def compiler(self):
     @property
     def content(self):
         ret = {}
-        for _, cpp_info in self.deps_build_info.dependencies:
-            ret["%s.pc" % cpp_info.name] = self.single_pc_file_contents(cpp_info)
+        for depname, cpp_info in self.deps_build_info.dependencies:
+            name = cpp_info.name.lower() if cpp_info.name != depname else depname
+            ret["%s.pc" % name] = self.single_pc_file_contents(name, cpp_info)
         return ret
 
-    def single_pc_file_contents(self, cpp_info):
-        name = cpp_info.name
+    def single_pc_file_contents(self, name, cpp_info):
         prefix_path = cpp_info.rootpath.replace("\\", "/")
         lines = ['prefix=%s' % prefix_path]
 


Test patch:
diff --git a/conans/test/unittests/client/generators/pkg_config_test.py b/conans/test/unittests/client/generators/pkg_config_test.py
--- a/conans/test/unittests/client/generators/pkg_config_test.py
+++ b/conans/test/unittests/client/generators/pkg_config_test.py
@@ -22,8 +22,18 @@ def variables_setup_test(self):
         cpp_info.cflags.append("-Flag1=23")
         cpp_info.version = "1.3"
         cpp_info.description = "My cool description"
+        conanfile.deps_cpp_info.update(cpp_info, ref.name)
 
+        ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables")
+        cpp_info = CppInfo("dummy_root_folder1")
+        cpp_info.name = "MYPKG1"
+        cpp_info.defines = ["MYDEFINE11"]
+        cpp_info.cflags.append("-Flag1=21")
+        cpp_info.version = "1.7"
+        cpp_info.description = "My other cool description"
+        cpp_info.public_deps = ["MyPkg"]
         conanfile.deps_cpp_info.update(cpp_info, ref.name)
+
         ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
         cpp_info = CppInfo("dummy_root_folder2")
         cpp_info.name = ref.name
@@ -47,6 +57,18 @@ def variables_setup_test(self):
 Libs: -L${libdir} -sharedlinkflag -exelinkflag
 Cflags: -I${includedir} -cxxflag -DMYDEFINE2
 Requires: MyPkg
+""")
+
+        self.assertEqual(files["mypkg1.pc"], """prefix=dummy_root_folder1
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: mypkg1
+Description: My other cool description
+Version: 1.7
+Libs: -L${libdir}
+Cflags: -I${includedir} -Flag1=21 -DMYDEFINE11
+Requires: MyPkg
 """)
 
         self.assertEqual(files["my_pkg.pc"], """prefix=dummy_root_folder1