Repository: conan-io/conan-center-index

Issue:
Add dbus/1.12.16
Specify library name and version:  **dbus/1.12.16**

- [X] I've read the [guidelines](https://github.com/conan-io/conan-center-index/wiki#how-to-submit-a-pull-request) for contributing.
- [X] I've followed the [PEP8](https://www.python.org/dev/peps/pep-0008/) style guides for Python code in the recipes.
- [X] I've used the [latest](https://github.com/conan-io/conan/releases/latest) Conan client version.
- [ ] I've tried at least one configuration locally with the
      [conan-center hook](https://github.com/conan-io/hooks.git) activated.




Discussion:

Resolving patch:
diff --git a/recipes/dbus/1.x.x/conanfile.py b/recipes/dbus/1.x.x/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dbus/1.x.x/conanfile.py
@@ -0,0 +1,110 @@
+import os
+import shutil
+from conans import CMake, ConanFile, tools
+from conans.errors import ConanInvalidConfiguration
+
+
+class DbusConan(ConanFile):
+    name = "dbus"
+    license = ("AFL-2.1", "GPL-2.0-or-later")
+    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."
+    topics = ("conan", "dbus")
+    settings = "os", "compiler", "build_type", "arch"
+
+    options = {
+        "with_x11": [True, False],
+        "with_glib": [True, False],
+        "enable_assert": [True, False],
+        "enable_checks": [True, False]}
+
+    default_options = {
+        "with_x11": False,
+        "with_glib": False,
+        "enable_assert": False,
+        "enable_checks": False}
+
+    generators = "cmake", "cmake_find_package"
+
+    exports_sources = ["patches/*"]
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    _cmake = None
+
+    def configure(self):
+        if self.settings.os not in ("Linux", "FreeBSD"):
+            raise ConanInvalidConfiguration("dbus is only supported on Linux and FreeBSD")
+
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = self.name + "-" + self.version
+        tools.rename(extracted_dir, self._source_subfolder)
+
+    def requirements(self):
+        self.requires("expat/2.2.10")
+        if self.options.with_glib:
+            self.requires("glib/2.67.0")
+
+        if self.options.with_x11:
+            self.requires("xorg/system")
+
+    def _configure_cmake(self):
+        if not self._cmake:
+            self._cmake = CMake(self)
+
+            self._cmake.definitions["DBUS_BUILD_TESTS"] = False
+            self._cmake.definitions["DBUS_ENABLE_DOXYGEN_DOCS"] = False
+            self._cmake.definitions["DBUS_ENABLE_XML_DOCS"] = False
+
+            self._cmake.definitions["DBUS_BUILD_X11"] = self.options.with_x11
+            self._cmake.definitions["DBUS_WITH_GLIB"] = self.options.with_glib
+            self._cmake.definitions["DBUS_DISABLE_ASSERT"] = not self.options.enable_assert
+            self._cmake.definitions["DBUS_DISABLE_CHECKS"] = not self.options.enable_checks
+
+            path_to_cmake_lists = os.path.join(self._source_subfolder, "cmake")
+
+            self._cmake.configure(source_folder=path_to_cmake_lists,
+                                  build_folder=self._build_subfolder)
+        return self._cmake
+
+    def build(self):
+        for patch in self.conan_data["patches"][self.version]:
+            tools.patch(**patch)
+
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy(pattern="COPYING", dst="licenses",
+                  src=self._source_subfolder)
+        cmake = self._configure_cmake()
+        cmake.install()
+
+        for i in ["var", "share", "etc"]:
+            shutil.move(os.path.join(self.package_folder, i), os.path.join(self.package_folder, "res", i))
+
+        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
+        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+
+    def package_info(self):
+        # FIXME: There should not be a namespace
+        self.cpp_info.filenames["cmake_find_package"] = "DBus1"
+        self.cpp_info.filenames["cmake_find_package_multi"] = "DBus1"
+        self.cpp_info.names["cmake_find_package"] = "dbus-1"
+        self.cpp_info.names["cmake_find_package_multi"] = "dbus-1"
+        self.cpp_info.names["pkg_config"] = "dbus-1"
+
+        self.cpp_info.includedirs.extend([
+            "include/dbus-1.0", "lib/dbus-1.0/include"])
+        self.cpp_info.libs = ["dbus-1"]


Test patch:
diff --git a/recipes/dbus/1.x.x/test_package/CMakeLists.txt b/recipes/dbus/1.x.x/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/dbus/1.x.x/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+project(PackageTest)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+find_package(DBus1 REQUIRED)
+
+add_executable(example example.c)
+target_link_libraries(example dbus-1::dbus-1)
diff --git a/recipes/dbus/1.x.x/test_package/conanfile.py b/recipes/dbus/1.x.x/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dbus/1.x.x/test_package/conanfile.py
@@ -0,0 +1,17 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class DbusTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake_find_package", "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            self.run("dbus-monitor --help", run_environment=True)
+            self.run(os.path.join("bin", "example"), run_environment=True)
diff --git a/recipes/dbus/1.x.x/test_package/example.c b/recipes/dbus/1.x.x/test_package/example.c
new file mode 100644
--- /dev/null
+++ b/recipes/dbus/1.x.x/test_package/example.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <dbus/dbus.h>
+
+int main() {
+    int major_version = 0;
+    int minor_version = 0;
+    int micro_version = 0;
+
+    dbus_get_version(&major_version, &minor_version, &micro_version);
+
+    printf("D-Bus version: v%i.%i.%i\n", major_version, minor_version, micro_version);
+    return 0;
+}