From 2e3f66efe142fe0117e0f4de1d735742d1241a65 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 10 Feb 2017 22:53:34 +0100 Subject: [PATCH] Add find package config support to cmake build system. Generate cmake equivalent of pkgconfig files and install them at a location known by clients using find_package(DBus1). See readme.cmake for more instructions how to use. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 Signed-off-by: Ralf Habacker --- README.cmake | 21 ++++++++++++++++++++- cmake/CMakeLists.txt | 15 ++++++++++++++- cmake/DBus1Config.cmake.in | 24 ++++++++++++++++++++++++ cmake/DBus1ConfigVersion.cmake.in | 11 +++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 cmake/DBus1Config.cmake.in create mode 100644 cmake/DBus1ConfigVersion.cmake.in diff --git a/README.cmake b/README.cmake index 55427df..9f8b6f7 100644 --- a/README.cmake +++ b/README.cmake @@ -2,7 +2,7 @@ This file describes how to compile dbus using the cmake build system Requirements ------------ -- cmake version >= 2.4.4 see http://www.cmake.org +- cmake version >= 2.6.0 see http://www.cmake.org - installed libexpat see http://sourceforge.net/projects/expat/ unsupported RelWithDebInfo builds could be fetched from http://sourceforge.net/projects/kde-windows/files/expat/ @@ -171,3 +171,22 @@ Note: The above mentioned options could be extracted after configuring from the output of running " help-options" in the build directory. The related entries start with CMAKE_ or DBUS_. + + +How to compile in dbus into clients with cmake +---------------------------------------------- + +To compile dbus library into a client application with cmake +the following cmake commands are required: + +1. call find_package to find dbus package + +find_package(DBus1) + +2. after specifing targets link dbus into target + +add_executable(test test.c) +target_link_libraries(test ${DBus1_LIBRARIES}) + +Adding dbus libraries to targets also adds required dbus +include dirs and compiler definitions by default. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ae388bc..e38be84 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -96,7 +96,7 @@ set(DBUS_DATADIR ${EXPANDED_DATADIR}) #enable building of shared library SET(BUILD_SHARED_LIBS ON) -set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) if (CYGWIN) set (WIN32) @@ -654,3 +654,16 @@ if(UNIX) install(FILES ${CMAKE_BINARY_DIR}/dbus-1.pc DESTINATION lib/pkgconfig) endif() endif() + +# +# create cmake find_package support +# +set(INSTALL_CMAKE_DIR lib/cmake/DBus1) +configure_file(DBus1Config.cmake.in "${CMAKE_BINARY_DIR}/DBus1Config.cmake" @ONLY) +configure_file(DBus1ConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake" @ONLY) +install(FILES + "${CMAKE_BINARY_DIR}/DBus1Config.cmake" + "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev +) +install(EXPORT DBus1Targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) diff --git a/cmake/DBus1Config.cmake.in b/cmake/DBus1Config.cmake.in new file mode 100644 index 0000000..83d8ae2 --- /dev/null +++ b/cmake/DBus1Config.cmake.in @@ -0,0 +1,24 @@ +# - Config file for the DBus1 package +# It defines the following variables +# DBus1_FOUND - Flag for indicating that DBus1 package has been found +# DBus1_DEFINITIONS - compile definitions for DBus1 [1] +# DBus1_INCLUDE_DIRS - include directories for DBus1 [1] +# DBus1_LIBRARIES - cmake targets to link against + +# [1] This variable is not required if DBus1_LIBRARIES is added +# to a target with target_link_libraries + +# Compute paths +get_filename_component(DBus1_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) + +# Our library dependencies (contains definitions for IMPORTED targets) +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}/lib/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}) diff --git a/cmake/DBus1ConfigVersion.cmake.in b/cmake/DBus1ConfigVersion.cmake.in new file mode 100644 index 0000000..8c7b6ea --- /dev/null +++ b/cmake/DBus1ConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@DBUS_VERSION_STRING@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() -- 2.6.6