From f4f2fe1116974f9393c46cf46ae7ae304987fdb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= <domin144@o2.pl>
Date: Fri, 4 Aug 2023 22:46:25 +0200
Subject: [PATCH 1/2] Fix pkgconfig name collision on Windows

This fix is related to https://github.com/conan-io/conan/issues/10341
The previous fix did not take into account cases insensitive
filesystems. As a result the issue was still present on Windows.
OpenEXR is an example of affected recipe.
---
 conan/tools/gnu/pkgconfigdeps.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/conan/tools/gnu/pkgconfigdeps.py b/conan/tools/gnu/pkgconfigdeps.py
index 1aa86e9d472..0b54af8d201 100644
--- a/conan/tools/gnu/pkgconfigdeps.py
+++ b/conan/tools/gnu/pkgconfigdeps.py
@@ -336,7 +336,7 @@ def _update_pc_files(info):
         # if it does not already exist in components one
         # Issue related: https://github.com/conan-io/conan/issues/10341
         pkg_name = _get_package_name(self._dep, self._build_context_suffix)
-        if f"{pkg_name}.pc" not in pc_files:
+        if not f"{pkg_name}.pc".lower() in [x.lower() for x in pc_files]:
             package_info = _PCInfo(pkg_name, pkg_requires, f"Conan package: {pkg_name}",
                                    self._dep.cpp_info, _get_package_aliases(self._dep))
             # It'll be enough creating a shortened PC file. This file will be like an alias

From 80c00bda028e63b93ff51696a1cbfa37f11e6a38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= <domin144@o2.pl>
Date: Mon, 7 Aug 2023 22:20:42 +0200
Subject: [PATCH 2/2] Add test

---
 .../toolchains/gnu/test_pkgconfigdeps.py      | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py b/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
index 55f3db759fb..2bd0e0feb11 100644
--- a/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
+++ b/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
@@ -113,3 +113,68 @@ def layout(self):
     # Executing directly "meson test" fails if the bindir field does not exist
     client.run_command("meson test -C test_package/build-release")
     assert "1/1 ./src/example OK"
+
+
+@pytest.mark.tool("meson")
+@pytest.mark.tool("pkg_config")
+def test_pkgconfigdeps_pc_name_conflict():
+    """
+    This test checks that a pc file provided by component is not overwritten by
+    conan with pc file named after the package if the names collide.
+    Cases insensitive filesystems have to be taken into account.
+    """
+    client = TestClient()
+    client.run("new meson_lib -d name=hello -d version=1.0")
+    client.run("create . -tf=\"\"")
+    conanfile = textwrap.dedent("""
+    import os
+    from conan import ConanFile
+    from conan.tools.meson import MesonToolchain, Meson
+    from conan.tools.layout import basic_layout
+    from conan.tools.files import copy
+
+    class helloConan(ConanFile):
+        name = "hello"
+        version = "1.0"
+        package_type = "library"
+
+        # Binary configuration
+        settings = "os", "compiler", "build_type", "arch"
+        options = {"shared": [True, False], "fPIC": [True, False]}
+        default_options = {"shared": False, "fPIC": True}
+
+        # Sources are located in the same place as this recipe, copy them to the recipe
+        exports_sources = "meson.build", "src/*"
+
+        def config_options(self):
+            if self.settings.os == "Windows":
+                self.options.rm_safe("fPIC")
+
+        def configure(self):
+            if self.options.shared:
+                self.options.rm_safe("fPIC")
+
+        def layout(self):
+            basic_layout(self)
+
+        def generate(self):
+            tc = MesonToolchain(self)
+            tc.generate()
+
+        def build(self):
+            meson = Meson(self)
+            meson.configure()
+            meson.build()
+
+        def package(self):
+            meson = Meson(self)
+            meson.install()
+
+        def package_info(self):
+            self.cpp_info.components["component"].set_property("pkg_config_name", "Hello")
+            self.cpp_info.components["component"].libs = ["hello"]
+    """)
+    client.save({"conanfile.py": conanfile})
+    client.run("build test_package/conanfile.py")
+    client.run_command("meson test -C test_package/build-release")
+    assert "1/1 ./src/example OK"