Skip to content

Commit

Permalink
dbus/1.12.20: Use CMake to build D-Bus to fix cross-compiling
Browse files Browse the repository at this point in the history
Currently, Autotools errors out when attempting to cross-compile D-Bus.
However, D-Bus can be built with CMake by defining a simple variable.
Using CMake, D-Bus is able to be cross-compiled successfully.
This minimizes the complexity of the D-Bus Conanfile by using 1 build system.

D-Bus has better support for CMake in newer versions.
This should lead to reduced maintenance overhead in the future, too.
  • Loading branch information
jwillikers committed Jul 9, 2022
1 parent 78ea863 commit f5501e4
Showing 1 changed file with 12 additions and 47 deletions.
59 changes: 12 additions & 47 deletions recipes/dbus/1.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools, CMake
import os
import shutil
import textwrap

from conans import ConanFile, tools, CMake

required_conan_version = ">=1.43.0"


Expand Down Expand Up @@ -30,8 +31,7 @@ class DbusConan(ConanFile):
"with_selinux": False,
}

generators = "pkg_config", "cmake", "cmake_find_package"
_autotools = None
generators = "cmake", "cmake_find_package"
_cmake = None

@property
Expand Down Expand Up @@ -62,37 +62,6 @@ def requirements(self):
def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def _configure_autotools(self):
if not self._autotools:
self._autotools = AutoToolsBuildEnvironment(self)

args = []
args.append("--disable-tests")
args.append("--disable-doxygen-docs")
args.append("--disable-xml-docs")

args.append("--with-x=%s" % ("yes" if self.options.get_safe("with_x11", False) else "no"))
args.append("--%s-x11-autolaunch" % ("enable" if self.options.get_safe("with_x11", False) else "disable"))
args.append("--disable-asserts")
args.append("--disable-checks")

args.append("--with-systemdsystemunitdir=%s" % os.path.join(self.package_folder, "lib", "systemd", "system"))
args.append("--with-systemduserunitdir=%s" % os.path.join(self.package_folder, "lib", "systemd", "user"))

if not self.options.with_selinux:
args.append("--disable-selinux")

if str(self.options.system_socket) != "":
args.append("--with-system-socket=%s" % self.options.system_socket)
if str(self.options.system_pid_file) != "":
args.append("--with-system-pid-file=%s" % self.options.system_pid_file)

args.append("--disable-launchd")
args.append("--disable-systemd")

self._autotools.configure(args=args, configure_dir=self._source_subfolder)
return self._autotools

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
Expand All @@ -103,9 +72,13 @@ def _configure_cmake(self):

self._cmake.definitions["DBUS_BUILD_X11"] = self.options.get_safe("with_x11", False)
self._cmake.definitions["DBUS_WITH_GLIB"] = self.options.with_glib
self._cmake.definitions["DBUS_DISABLE_ASSERT"] = False
self._cmake.definitions["DBUS_DISABLE_ASSERT"] = tools.is_apple_os(self.settings.os)
self._cmake.definitions["DBUS_DISABLE_CHECKS"] = False

# Conan does not provide an EXPAT_LIBRARIES CMake variable for the Expat library.
# Define EXPAT_LIBRARIES to be the expat::expat target provided by Conan to fix linking.
self._cmake.definitions["EXPAT_LIBRARIES"] = "expat::expat"

path_to_cmake_lists = os.path.join(self._source_subfolder, "cmake")

self._cmake.configure(source_folder=path_to_cmake_lists,
Expand All @@ -116,22 +89,14 @@ def build(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "cmake", "CMakeLists.txt"),
"project(dbus)",
"project(dbus)\ninclude(../../conanbuildinfo.cmake)\nconan_basic_setup()")
if self.settings.os == "Windows":
cmake = self._configure_cmake()
cmake.build()
else:
autotools = self._configure_autotools()
autotools.make()
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="COPYING", dst="licenses",
src=self._source_subfolder)
if self.settings.os == "Windows":
cmake = self._configure_cmake()
cmake.install()
else:
autotools = self._configure_autotools()
autotools.install()
cmake = self._configure_cmake()
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "share", "doc"))
for i in ["var", "share", "etc"]:
Expand Down

0 comments on commit f5501e4

Please sign in to comment.