From 0637e4f75956ae27e501568fdb7ee1da339baab0 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 9 Feb 2017 09:57:16 +0100 Subject: [PATCH] Add and install find package config support to cmake build system. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 Signed-off-by: Ralf Habacker --- README.cmake | 21 ++++++++++++++++++++- cmake/CMakeLists.txt | 17 +++++++++++++++-- cmake/DBus1Config.cmake.in | 24 ++++++++++++++++++++++++ cmake/DBus1ConfigVersion.cmake.in | 11 +++++++++++ cmake/dbus/CMakeLists.txt | 2 +- 5 files changed, 71 insertions(+), 4 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 2c397d2..cd614a5 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -97,9 +97,9 @@ set(DBUS_DATADIR ${EXPANDED_DATADIR}) SET(BUILD_SHARED_LIBS ON) if(WIN32) - 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") else() - set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${EXPANDED_LIBDIR}" LIBRARY DESTINATION "${EXPANDED_LIBDIR}" ARCHIVE DESTINATION "${EXPANDED_LIBDIR}") + set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION "${EXPANDED_BINDIR}" LIBRARY DESTINATION "${EXPANDED_LIBDIR}" ARCHIVE DESTINATION "${EXPANDED_LIBDIR}") endif() if (CYGWIN) @@ -635,3 +635,16 @@ add_custom_target(help-options cmake -LH WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) + +# +# 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..5024b86 --- /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 - libraries 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 AND NOT DBus1_BINARY_DIR) + include("${CMAKE_CURRENT_LIST_DIR}/DBus1Targets.cmake") +endif() + +set(DBus1_INCLUDE_DIRS "${DBus1_INSTALL_DIR}/include/dbus-1") +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() diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index dfc4842..378c359 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -304,7 +304,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") install(TARGETS dbus-1 ${INSTALL_TARGETS_DEFAULT_ARGS}) -install(FILES ${dbusinclude_HEADERS} DESTINATION include/dbus) +install(FILES ${dbusinclude_HEADERS} DESTINATION include/dbus-1/dbus) ### Internal library, used for the daemon, tools and tests, compiled statically. -- 1.8.4.5