1
0
Fork 0

Adjust FindDBus to use imported targets

This is necessary on macOS where DBus is typically installed using
Homebrew, and hence we need additional linker flags to find the
library. Using the PkgConfig::DBUS imported target handles all this
transparently, but then we need to define an imported target for
Windows to work.
This commit is contained in:
James Turner 2019-05-27 11:37:35 +01:00
parent 59ec70dfea
commit 7738f33306
3 changed files with 31 additions and 15 deletions

View file

@ -276,11 +276,10 @@ if (ENABLE_SWIFT)
find_package(LibEvent)
if (DBUS_FOUND AND LIBEVENT_FOUND)
list(APPEND PLATFORM_LIBS ${DBUS_LIBRARIES})
message(STATUS "SWIFT support enabled")
list(APPEND PLATFORM_LIBS ${LIBEVENT_LIB})
# FIXME, make this target specific, not a global include setting
include_directories(${DBUS_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIR})
include_directories(${LIBEVENT_INCLUDE_DIR})
else()
message(WARNING "SWIFT support disabled, dbus and/or LibEvent not found")
set(ENABLE_SWIFT 0)

View file

@ -2,18 +2,29 @@
# Defining:
# DBUS_LIBRARY
# DBUS_INCLUDE_DIR
if(WIN32)
FIND_PATH(DBUS_INCLUDE_DIRS dbus/dbus.h PATH_SUFFIXES include HINTS ${ADDITIONAL_LIBRARY_PATHS})
FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 PATH_SUFFIXES lib HINTS ${ADDITIONAL_LIBRARY_PATHS})
if(WIN32)
FIND_PATH(DBUS_INCLUDE_DIRS dbus/dbus.h PATH_SUFFIXES include HINTS ${ADDITIONAL_LIBRARY_PATHS})
FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 PATH_SUFFIXES lib HINTS ${ADDITIONAL_LIBRARY_PATHS})
# define an imported target for DBus manually
if (DBUS_INCLUDE_DIRS AND DBUS_LIBRARIES)
add_library(DBus UNKNOWN IMPORTED)
set_target_properties(DBus PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${DBUS_INCLUDE_DIRS}"
IMPORTED_LOCATION "${DBUS_LIBRARIES)}"
)
endif()
else()
include(FindPkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(DBUS dbus-1)
endif (PKG_CONFIG_FOUND)
if(DBUS_FOUND)
set(HAVE_DBUS 1)
endif(DBUS_FOUND)
include(FindPkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(DBUS IMPORTED_TARGET dbus-1)
endif (PKG_CONFIG_FOUND)
if(DBUS_FOUND)
set(HAVE_DBUS 1)
endif(DBUS_FOUND)
endif(WIN32)
include(FindPackageHandleStandardArgs)

View file

@ -26,8 +26,14 @@ function(setup_fgfs_libraries target)
target_link_libraries(${target} iaxclient_lib ${OPENAL_LIBRARY})
endif()
if(USE_DBUS)
target_link_libraries(${target} ${DBUS_LDFLAGS})
# manually created DBus target
if(TARGET DBus)
target_link_libraries(${target} DBus)
endif()
# PkgCOnfig::DBUS target
if(TARGET PkgConfig::DBUS)
target_link_libraries(${target} PkgConfig::DBUS)
endif()
if(FG_HAVE_GPERFTOOLS)