cmake: Add helper to find dbus package

The DBus library is a message bus system used to make applications
communicate with each other.  The primary reason for adding it is to
access certain service features to prevent computer sleep/hibernate/etc.

This will also create a HAVE_DBUS variable (set to 1 or 0 if found or
not found)
This commit is contained in:
jp9000 2015-09-12 19:15:32 -07:00
parent a60189d429
commit 88ab25870e

View file

@ -0,0 +1,43 @@
# Once done these will be defined:
#
# DBUS_FOUND
# DBUS_INCLUDE_DIRS
# DBUS_LIBRARIES
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_DBUS QUIET dbus-1)
endif()
find_path(DBUS_INCLUDE_DIR
NAMES dbus/dbus.h
HINTS
${_DBUS_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include)
find_path(DBUS_ARCH_INCLUDE_DIR
NAMES dbus/dbus-arch-deps.h
HINTS
${_DBUS_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include)
find_library(DBUS_LIB
NAMES dbus-1
HINTS
${_DBUS_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DBus DEFAULT_MSG DBUS_LIB DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR)
mark_as_advanced(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIB)
if(DBUS_FOUND)
set(DBUS_INCLUDE_DIRS ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
set(DBUS_LIBRARIES ${DBUS_LIB})
set(HAVE_DBUS "1")
else()
set(HAVE_DBUS "0")
endif()