Repository: conan-io/conan-center-index

Issue:
[bug] dbus: generated dbus-1.pc incorrectly has Requires: xorg
### Environment details

When building qt with with_dbus=True and dbus option with_x11=True I see a dbus-1.pc like this being generated:

```
$ cat ./p/b/qt1f8e4c91c1b89/b/dbus-1.pc
prefix=/home/ts/.conan2/p/b/dbuse119f1e6f4a56/p
libdir=${prefix}/lib
includedir=${prefix}/include
includedir1=${prefix}/include/dbus-1.0
includedir2=${prefix}/lib/dbus-1.0/include
bindir=${prefix}/bin

Name: dbus-1
Description: Conan package: dbus-1
Version: 1.15.8
Libs: -L"${libdir}" -ldbus-1 -lrt -lpthread
Cflags: -I"${includedir}" -I"${includedir1}" -I"${includedir2}"
Requires: expat xorg
```

It incorrectly lists xorg as dependency, which is incorrect. When dbus is built with with_x11 the libdbus-1 library is not affected - the only impact is that a binary `dbus-launch` is built that depends on x11.

* Operating System+version: AlmaLinux 9.3
* Compiler+version: gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
* Conan version: 2.0.16
* Python version: 3.9.18


### Steps to reproduce

_No response_

### Logs

_No response_
dbus: with_x11=True does not mean libdbus depends on xorg/system
When dbus is built with with_x11 an extra executable `dbus-launch` will be built. Only this executable depends on x11. By adding the explicit requirement trait visible=False we avoid passing all the X11 libraries in xorg/system as link libraries to applications that link with dbus.

Fixes #22133

---

- [x] I've read the [contributing guidelines](https://github.com/conan-io/conan-center-index/blob/master/CONTRIBUTING.md).
- [x] I've used a [recent](https://github.com/conan-io/conan/releases/latest) Conan client version close to the [currently deployed](https://github.com/conan-io/conan-center-index/blob/master/.c3i/config_v1.yml#L6).
- [x] I've tried at least one configuration locally with the [conan-center hook](https://github.com/conan-io/hooks.git) activated.



Discussion:
Hi @tsondergaard 

Thanks for your report.

I am not sure this is a Conan client issue. I see the ConanCenter recipe contains in https://github.com/conan-io/conan-center-index/blob/f4eb09ad79e8c869ccaabdc493a660cc91d24a4f/recipes/dbus/1.x.x/conanfile.py#L78

```
self.requires("xorg/system")
```
There are no components definition or anything similar, so the recipe depends on ``xorg`` and that results in the definition of that requires in ``.pc`` files, so looks correct. If we would like something different that would be implemented adding components to the ``dbus`` recipe, though I am not sure it is really worth.

I am moving this ticket to ConanCenter github repo, but please note that at the moment there is a huge queue of open PRs to ConanCenter, so this might take a while to be addressed.
:robot: **Beep Boop**! This pull request is making changes to 'recipes/dbus/*/*'.

:wave: @jwillikers you might be interested. :wink:

Resolving patch:
diff --git a/recipes/dbus/1.x.x/conanfile.py b/recipes/dbus/1.x.x/conanfile.py
--- a/recipes/dbus/1.x.x/conanfile.py
+++ b/recipes/dbus/1.x.x/conanfile.py
@@ -15,7 +15,8 @@
 
 class DbusConan(ConanFile):
     name = "dbus"
-    license = ("AFL-2.1", "GPL-2.0-or-later")
+    # license is AFL-2.1 OR GPL-2.0-or-later with several other compatible licenses for smaller sections of code
+    license = "(AFL-2.1 OR GPL-2.0-or-later) AND DocumentRef-COPYING"
     url = "https://github.com/conan-io/conan-center-index"
     homepage = "https://www.freedesktop.org/wiki/Software/dbus"
     description = "D-Bus is a simple system for interprocess communication and coordination."
@@ -29,7 +30,7 @@ class DbusConan(ConanFile):
         "system_socket": [None, "ANY"],
         "system_pid_file": [None, "ANY"],
         "with_x11": [True, False],
-        "with_glib": [True, False],
+        "with_glib": ["deprecated", True, False],
         "with_systemd": [True, False],
         "with_selinux": [True, False],
         "session_socket_dir": ["ANY"],
@@ -40,7 +41,7 @@ class DbusConan(ConanFile):
         "system_socket": None,
         "system_pid_file": None,
         "with_x11": False,
-        "with_glib": False,
+        "with_glib": "deprecated",
         "with_systemd": False,
         "with_selinux": False,
         "session_socket_dir": "/tmp",
@@ -52,8 +53,8 @@ def export_sources(self):
     def config_options(self):
         if self.settings.os not in ("Linux", "FreeBSD"):
             del self.options.with_systemd
-        if self.settings.os not in ("Linux", "FreeBSD"):
             del self.options.with_x11
+            del self.options.with_selinux
         if self.settings.os == "Windows":
             del self.options.fPIC
 
@@ -63,26 +64,32 @@ def configure(self):
         if self.options.shared:
             self.options.rm_safe("fPIC")
 
+    def package_id(self):
+        del self.info.options.with_glib
+
     def layout(self):
         basic_layout(self, src_folder="src")
 
     def requirements(self):
         self.requires("expat/2.6.0")
-        if self.options.with_glib:
-            self.requires("glib/2.78.3")
         if self.options.get_safe("with_systemd"):
             self.requires("libsystemd/253.6")
-        if self.options.with_selinux:
-            self.requires("libselinux/3.3")
+        if self.options.get_safe("with_selinux"):
+            self.requires("libselinux/3.5")
         if self.options.get_safe("with_x11"):
-            self.requires("xorg/system")
+            # X11 is only linked into an executable and should not be propagated as a library dependency.
+            # It should still be provided in a VirtualRunEnv context, though,
+            # but Conan as of v2.2 does not yet provide a fine-grained enough control over this.
+            self.requires("xorg/system", visible=False)
 
     def validate(self):
         if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < 7:
             raise ConanInvalidConfiguration(f"{self.ref} requires at least gcc 7.")
+        if self.options.with_glib != "deprecated":
+            raise ConanInvalidConfiguration(f"with_glib option is deprecated and should not be used - the option had no effect.")
 
     def build_requirements(self):
-        self.tool_requires("meson/1.3.2")
+        self.tool_requires("meson/1.4.0")
         if not self.conf.get("tools.gnu:pkg_config",check_type=str):
             self.tool_requires("pkgconf/2.1.0")
 
@@ -103,8 +110,8 @@ def generate(self):
         tc.project_options["selinux"] = "enabled" if self.options.get_safe("with_selinux", False) else "disabled"
         tc.project_options["systemd"] = "enabled" if self.options.get_safe("with_systemd", False) else "disabled"
         if self.options.get_safe("with_systemd", False):
-            tc.project_options["systemd_system_unitdir"] = os.path.join(self.package_folder, "lib", "systemd", "system")
-            tc.project_options["systemd_user_unitdir"] = os.path.join(self.package_folder, "lib", "systemd", "user")
+            tc.project_options["systemd_system_unitdir"] = "/res/lib/systemd/system"
+            tc.project_options["systemd_user_unitdir"] = "/res/usr/lib/systemd/system"
         if is_apple_os(self):
             tc.project_options["launchd_agent_dir"] = os.path.join(self.package_folder, "res", "LaunchAgents")
         tc.project_options["x11_autolaunch"] = "enabled" if self.options.get_safe("with_x11", False) else "disabled"
@@ -113,15 +120,20 @@ def generate(self):
         deps = PkgConfigDeps(self)
         deps.generate()
 
-    def build(self):
+    def _patch_sources(self):
         apply_conandata_patches(self)
-        replace_in_file(self, os.path.join(self.source_folder, "meson.build"), "subdir('test')", "# subdir('test')")
+        replace_in_file(self, os.path.join(self.source_folder, "meson.build"),
+                        "subdir('test')", "# subdir('test')")
+
+    def build(self):
+        self._patch_sources()
         meson = Meson(self)
         meson.configure()
         meson.build()
 
     def package(self):
-        copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
+        copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
+        copy(self, "*", os.path.join(self.source_folder, "LICENSES"), os.path.join(self.package_folder, "licenses"))
         meson = Meson(self)
         meson.install()
 
@@ -133,7 +145,6 @@ def package(self):
 
         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, "lib", "systemd"))
         fix_apple_shared_install_name(self)
         if self.settings.os == "Windows" and not self.options.shared:
             rename(self, os.path.join(self.package_folder, "lib", "libdbus-1.a"), os.path.join(self.package_folder, "lib", "dbus-1.lib"))
@@ -179,6 +190,12 @@ def package_info(self):
         if not self.options.shared:
             self.cpp_info.defines.append("DBUS_STATIC_BUILD")
 
+        self.cpp_info.requires.append("expat::expat")
+        if self.options.get_safe("with_systemd"):
+            self.cpp_info.requires.append("libsystemd::libsystemd")
+        if self.options.get_safe("with_selinux"):
+            self.cpp_info.requires.append("libselinux::selinux")
+
         # TODO: to remove in conan v2 once cmake_find_package_* & pkg_config generators removed
         self.cpp_info.filenames["cmake_find_package"] = "DBus1"
         self.cpp_info.filenames["cmake_find_package_multi"] = "DBus1"


Test patch: