From 7738f33306510ffddd380d1625a06010613bbfae Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 27 May 2019 11:37:35 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 5 ++--- CMakeModules/FindDBus.cmake | 31 ++++++++++++++++++--------- CMakeModules/SetupFGFSLibraries.cmake | 10 +++++++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dadd8825..bf25f6dc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeModules/FindDBus.cmake b/CMakeModules/FindDBus.cmake index 40c960b03..00ca87489 100644 --- a/CMakeModules/FindDBus.cmake +++ b/CMakeModules/FindDBus.cmake @@ -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) diff --git a/CMakeModules/SetupFGFSLibraries.cmake b/CMakeModules/SetupFGFSLibraries.cmake index 2fa26fdc6..1525d0800 100644 --- a/CMakeModules/SetupFGFSLibraries.cmake +++ b/CMakeModules/SetupFGFSLibraries.cmake @@ -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)