From a2630df7ce6970aefe04197a210b99e2fbcafaed Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sun, 12 Feb 2017 19:59:40 +0100 Subject: [PATCH] cmake: Add find_package support for windows. On Windows we do not want to require CMake users to have pkg-config installed so cmake buildin target export support for exporting all targets into DBus1ConfigTargets*.cmake is used on build. These files are installed into the related directory where cmake expects find_package related config files. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 --- cmake/CMakeLists.txt | 6 ++- cmake/DBus1Config.cmake.in | 97 +++++++++++++++++++++++++++------------------- 2 files changed, 63 insertions(+), 40 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7603fdd..322b47d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -91,7 +91,7 @@ set(DBUS_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}) #enable building of shared library SET(BUILD_SHARED_LIBS ON) -set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if (CYGWIN) set (WIN32) @@ -522,6 +522,10 @@ install(FILES DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev ) +if(WIN32) + install(EXPORT DBus1Targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) +endif() + ########### subdirs ############### add_subdirectory( dbus ) diff --git a/cmake/DBus1Config.cmake.in b/cmake/DBus1Config.cmake.in index ae4e9ba..e34a46c 100644 --- a/cmake/DBus1Config.cmake.in +++ b/cmake/DBus1Config.cmake.in @@ -14,42 +14,61 @@ if(CMAKE_LIBRARY_ARCHITECTURE) else() get_filename_component(DBus1_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) endif() -get_filename_component(DBus1_PKGCONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}/../../pkgconfig" ABSOLUTE) - -find_package(PkgConfig) -set(ENV{PKG_CONFIG_DIR}) -set(ENV{PKG_CONFIG_PATH} ${DBus1_PKGCONFIG_DIR}) -set(ENV{PKG_CONFIG_LIBDIR} ${DBus1_PKGCONFIG_DIR}) -# for debugging -#set(ENV{PKG_CONFIG_DEBUG_SPEW} 1) -pkg_check_modules(PC_DBUS1 QUIET dbus-1) -set(DBus1_DEFINITIONS ${PC_DBUS1_CFLAGS_OTHER}) - -# find the real stuff and use pkgconfig variables as hints -# because cmake provides more search options -find_path(DBus1_INCLUDE_DIR dbus/dbus.h - HINTS ${PC_DBUS1_INCLUDEDIR} ${PC_DBUS1_INCLUDE_DIRS} - PATH_SUFFIXES dbus-1.0) -find_path(DBus1_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h - HINTS ${PC_DBUS1_INCLUDE_DIRS} - PATH_SUFFIXES dbus-1.0) -find_library(DBus1_LIBRARY NAMES ${PC_DBUS1_LIBRARIES} - HINTS ${PC_DBUS1_LIBDIR} ${PC_DBUS1_LIBRARY_DIRS}) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set DBus1_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(DBus1 DEFAULT_MSG - DBus1_LIBRARY DBus1_INCLUDE_DIR DBus1_ARCH_INCLUDE_DIR) - -# make the mentioned variables only visible in cmake gui with "advanced" enabled -mark_as_advanced(DBus1_INCLUDE_DIR DBus1_LIBRARY) - -set(DBus1_LIBRARIES dbus-1) -set(DBus1_INCLUDE_DIRS "${DBus1_INCLUDE_DIR}" "${DBus1_ARCH_INCLUDE_DIR}") - -# setup imported target -add_library(dbus-1 SHARED IMPORTED) -set_property(TARGET dbus-1 APPEND PROPERTY IMPORTED_LOCATION ${DBus1_LIBRARY}) -set_property(TARGET dbus-1 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${DBus1_INCLUDE_DIRS}) -set_property(TARGET dbus-1 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ${DBus1_DEFINITIONS}) +# Our library dependencies (contains definitions for IMPORTED targets) +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/DBus1Targets.cmake") + # do not additional search paths for implicit libraries + # see https://cmake.org/cmake/help/v3.0/policy/CMP0003.html + if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) + endif(COMMAND cmake_policy) + + if(NOT TARGET dbus-1) + include("${CMAKE_CURRENT_LIST_DIR}/DBus1Targets.cmake") + endif() + + set(DBus1_INCLUDE_DIRS "${DBus1_INSTALL_DIR}/include/dbus-1.0" "${DBus1_INSTALL_DIR}/@CMAKE_INSTALL_LIBDIR@/dbus-1.0/include") + set(DBus1_DEFINITIONS) + set(DBus1_LIBRARIES dbus-1) + + set_property(TARGET dbus-1 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${DBus1_INCLUDE_DIRS}) + set_property(TARGET dbus-1 PROPERTY INTERFACE_COMPILE_DEFINITIONS ${DBus1_DEFINITIONS}) +else() # installed from autotools + get_filename_component(DBus1_PKGCONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}/../../pkgconfig" ABSOLUTE) + find_package(PkgConfig) + set(ENV{PKG_CONFIG_DIR}) + set(ENV{PKG_CONFIG_PATH} ${DBus1_PKGCONFIG_DIR}) + set(ENV{PKG_CONFIG_LIBDIR} ${DBus1_PKGCONFIG_DIR}) + # for debugging + #set(ENV{PKG_CONFIG_DEBUG_SPEW} 1) + pkg_check_modules(PC_DBUS1 QUIET dbus-1) + set(DBus1_DEFINITIONS ${PC_DBUS1_CFLAGS_OTHER}) + + # find the real stuff and use pkgconfig variables as hints + # because cmake provides more search options + find_path(DBus1_INCLUDE_DIR dbus/dbus.h + HINTS ${PC_DBUS1_INCLUDEDIR} ${PC_DBUS1_INCLUDE_DIRS} + PATH_SUFFIXES dbus-1.0) + find_path(DBus1_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h + HINTS ${PC_DBUS1_INCLUDE_DIRS} + PATH_SUFFIXES dbus-1.0) + find_library(DBus1_LIBRARY NAMES ${PC_DBUS1_LIBRARIES} + HINTS ${PC_DBUS1_LIBDIR} ${PC_DBUS1_LIBRARY_DIRS}) + + include(FindPackageHandleStandardArgs) + # handle the QUIETLY and REQUIRED arguments and set DBus1_FOUND to TRUE + # if all listed variables are TRUE + find_package_handle_standard_args(DBus1 DEFAULT_MSG + DBus1_LIBRARY DBus1_INCLUDE_DIR DBus1_ARCH_INCLUDE_DIR) + + # make the mentioned variables only visible in cmake gui with "advanced" enabled + mark_as_advanced(DBus1_INCLUDE_DIR DBus1_LIBRARY) + + set(DBus1_LIBRARIES dbus-1) + set(DBus1_INCLUDE_DIRS "${DBus1_INCLUDE_DIR}" "${DBus1_ARCH_INCLUDE_DIR}") + + # setup imported target + add_library(dbus-1 SHARED IMPORTED) + set_property(TARGET dbus-1 APPEND PROPERTY IMPORTED_LOCATION ${DBus1_LIBRARY}) + set_property(TARGET dbus-1 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${DBus1_INCLUDE_DIRS}) + set_property(TARGET dbus-1 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ${DBus1_DEFINITIONS}) +endif() -- 2.6.6