summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2013-08-24 15:00:14 +0200
committerRalf Habacker <ralf.habacker@freenet.de>2013-10-26 10:07:04 +0200
commit8244477d225c35343804b07a23eb60c9c2a4e998 (patch)
tree40d5319ffbc436dac55aba2ed8c06d434f2bcfaa
parent41412e04b1a99707456cd205333fd0aa79f172ac (diff)
downloaddbus-68852-make-it-easier.tar.gz
Add glib support to cmake buildsystem.68852-make-it-easier
-rw-r--r--cmake/CMakeLists.txt7
-rw-r--r--cmake/modules/FindDBusGLib.cmake38
-rw-r--r--cmake/modules/FindGLIB.cmake42
-rw-r--r--cmake/modules/FindGLib2.cmake60
-rw-r--r--cmake/modules/FindGObject.cmake52
-rw-r--r--cmake/test/CMakeLists.txt49
6 files changed, 206 insertions, 42 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index fe111966..d950ef36 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -109,6 +109,12 @@ option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF)
find_package(EXPAT)
find_package(X11)
+find_package(GLib2)
+find_package(GObject)
+find_package(DBusGLib)
+if(GLIB2_FOUND AND GOBJECT_FOUND AND DBUSGLIB_FOUND)
+ option (DBUS_WITH_GLIB "build with glib" ON)
+endif()
# analogous to AC_USE_SYSTEM_EXTENSIONS in configure.ac
add_definitions(-D_GNU_SOURCE)
@@ -539,6 +545,7 @@ message(" Docbook Generator: ${DOCBOOK_GENERATOR_NAME} "
message(" gcc coverage profiling: ${DBUS_GCOV_ENABLED} ")
message(" Building unit tests: ${DBUS_BUILD_TESTS} ")
+message(" Building with GLib: ${DBUS_WITH_GLIB} ")
message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ")
message(" Building w/o assertions: ${DBUS_DISABLE_ASSERT} ")
message(" Building w/o checks: ${DBUS_DISABLE_CHECKS} ")
diff --git a/cmake/modules/FindDBusGLib.cmake b/cmake/modules/FindDBusGLib.cmake
new file mode 100644
index 00000000..19d05e8d
--- /dev/null
+++ b/cmake/modules/FindDBusGLib.cmake
@@ -0,0 +1,38 @@
+# - Try to find the DBUSGLIB libraries
+# Once done this will define
+#
+# DBUSGLIB_FOUND - system has DBUSGLIB
+# DBUSGLIB_INCLUDE_DIR - the DBUSGLIB include directory
+# DBUSGLIB_LIBRARIES - DBUSGLIB library
+
+# Copyright (c) 2013 Ralf Habacker <ralf.habacker@freenet.de>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+if(DBUSGLIB_INCLUDE_DIR AND DBUSGLIB_LIBRARIES)
+ # Already in cache, be silent
+ set(DBUSGLIB_FIND_QUIETLY TRUE)
+endif(DBUSGLIB_INCLUDE_DIR AND DBUSGLIB_LIBRARIES)
+
+if(NOT WIN32)
+ find_package(PkgConfig)
+ pkg_check_modules(PC_LibDBUSGLIB QUIET dbus-glib)
+endif()
+
+find_path(DBUSGLIB_INCLUDE_DIR
+ NAMES dbus/dbus-glib.h
+ HINTS ${PC_LibDBUSGLIB_INCLUDEDIR}
+ PATH_SUFFIXES dbus-1.0)
+
+find_library(DBUSGLIB_LIBRARY
+ NAMES dbus-glib-1
+ HINTS ${PC_LibDBUSGLIB_LIBDIR}
+)
+
+set(DBUSGLIB_LIBRARIES ${DBUSGLIB_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(DBUSGLIB DEFAULT_MSG DBUSGLIB_LIBRARIES DBUSGLIB_INCLUDE_DIR)
+
+mark_as_advanced(DBUSGLIB_INCLUDE_DIR DBUSGLIB_LIBRARIES)
diff --git a/cmake/modules/FindGLIB.cmake b/cmake/modules/FindGLIB.cmake
deleted file mode 100644
index 1fdaee95..00000000
--- a/cmake/modules/FindGLIB.cmake
+++ /dev/null
@@ -1,42 +0,0 @@
-# - Try to find the GLIB library
-# Once done this will define
-#
-# GLIB_FOUND - system has GLIB
-# GLIB_INCLUDES - the GLIB include directories
-# GLIB_LIBRARIES - The libraries needed to use GLIB
-
-if (WIN32)
-
-INCLUDE(MacroGetenvWinPath)
-
-MACRO_GETENV_WIN_PATH(_program_FILES_DIR PROGRAMFILES)
-
-FIND_PATH(GLIB_INCLUDE_DIR glib.h
- ${_program_FILES_DIR}/glib/include/glib-2.0
-)
-
-
-# search for GLIB in the default install directory for applications (default of (n)make install)
-FIND_LIBRARY(GLIB_LIBRARY NAMES glib-2.0
- PATHS
- ${_program_FILES_DIR}/glib/lib
-)
-
-if (GLIB_LIBRARY AND GLIB_INCLUDE_DIR)
- set(GLIB_FOUND TRUE)
- set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${GLIB_INCLUDES})
- set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${GLIB_LIBRARIES})
-
-endif (GLIB_LIBRARY AND GLIB_INCLUDE_DIR)
-
-if (GLIB_FOUND)
- if (NOT GLIB_FIND_QUIETLY)
- message(STATUS "Found GLIB: ${GLIB_LIBRARY}")
- endif (NOT GLIB_FIND_QUIETLY)
-else (GLIB_FOUND)
- if (GLIB_FIND_REQUIRED)
- message(FATAL_ERROR "Could NOT find GLIB library")
- endif (GLIB_FIND_REQUIRED)
-endif (GLIB_FOUND)
-
-endif (WIN32)
diff --git a/cmake/modules/FindGLib2.cmake b/cmake/modules/FindGLib2.cmake
new file mode 100644
index 00000000..a63694fb
--- /dev/null
+++ b/cmake/modules/FindGLib2.cmake
@@ -0,0 +1,60 @@
+# - Try to find the GLIB2 libraries
+# Once done this will define
+#
+# GLIB2_FOUND - system has glib2
+# GLIB2_INCLUDE_DIR - the glib2 include directory
+# GLIB2_LIBRARIES - glib2 library
+
+# Copyright (c) 2008 Laurent Montel, <montel@kde.org>
+# Copyright (c) 2013 Ralf Habacker, <ralf.habacker@freenet.de>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+ # Already in cache, be silent
+ set(GLIB2_FIND_QUIETLY TRUE)
+endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+
+if (NOT WIN32)
+ find_package(PkgConfig)
+ pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0)
+endif()
+
+find_path(GLIB2_MAIN_INCLUDE_DIR
+ NAMES glib.h
+ HINTS ${PC_LibGLIB2_INCLUDEDIR}
+ PATH_SUFFIXES glib-2.0)
+
+find_library(GLIB2_LIBRARY
+ NAMES glib-2.0
+ HINTS ${PC_LibGLIB2_LIBDIR}
+)
+
+find_library(GIO2_LIBRARY
+ NAMES gio-2.0
+ HINTS ${PC_LibGLIB2_LIBDIR}
+)
+
+set(GLIB2_LIBRARIES ${GLIB2_LIBRARY} ${GIO2_LIBRARY})
+
+# search the glibconfig.h include dir under the same root where the library is found
+get_filename_component(glib2LibDir "${GLIB2_LIBRARIES}" PATH)
+
+find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h
+ PATH_SUFFIXES glib-2.0/include
+ HINTS ${PC_LibGLIB2_INCLUDEDIR} "${glib2LibDir}" ${CMAKE_SYSTEM_LIBRARY_PATH})
+
+set(GLIB2_INCLUDE_DIR "${GLIB2_MAIN_INCLUDE_DIR}")
+
+# not sure if this include dir is optional or required
+# for now it is optional
+if(GLIB2_INTERNAL_INCLUDE_DIR)
+ set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} "${GLIB2_INTERNAL_INCLUDE_DIR}")
+endif(GLIB2_INTERNAL_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR)
+
+mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES)
diff --git a/cmake/modules/FindGObject.cmake b/cmake/modules/FindGObject.cmake
new file mode 100644
index 00000000..af0c9f73
--- /dev/null
+++ b/cmake/modules/FindGObject.cmake
@@ -0,0 +1,52 @@
+# - Try to find GObject
+# Once done this will define
+#
+# GOBJECT_FOUND - system has GObject
+# GOBJECT_INCLUDE_DIR - the GObject include directory
+# GOBJECT_LIBRARIES - the libraries needed to use GObject
+# GOBJECT_DEFINITIONS - Compiler switches required for using GObject
+
+# Copyright (c) 2011, Raphael Kubo da Costa <kubito@gmail.com>
+# Copyright (c) 2006, Tim Beaulen <tbscope@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+FIND_PACKAGE(PkgConfig)
+PKG_CHECK_MODULES(PC_GOBJECT gobject-2.0)
+SET(GOBJECT_DEFINITIONS ${PC_GOBJECT_CFLAGS_OTHER})
+
+FIND_PATH(GOBJECT_INCLUDE_DIR gobject.h
+ HINTS
+ ${PC_GOBJECT_INCLUDEDIR}
+ ${PC_GOBJECT_INCLUDE_DIRS}
+ PATH_SUFFIXES glib-2.0/gobject/
+ )
+
+FIND_LIBRARY(_GObjectLibs NAMES gobject-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GModuleLibs NAMES gmodule-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GThreadLibs NAMES gthread-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GLibs NAMES glib-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+
+SET( GOBJECT_LIBRARIES ${_GObjectLibs} ${_GModuleLibs} ${_GThreadLibs} ${_GLibs} )
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GOBJECT DEFAULT_MSG GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR)
+
+MARK_AS_ADVANCED(GOBJECT_INCLUDE_DIR _GObjectLibs _GModuleLibs _GThreadLibs _GLibs)
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index 8657e4c7..7758d2cd 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -71,6 +71,55 @@ target_link_libraries(test-segfault ${DBUS_INTERNAL_LIBRARIES})
add_executable(test-sleep-forever ${test-sleep-forever_SOURCES})
target_link_libraries(test-sleep-forever ${DBUS_INTERNAL_LIBRARIES})
+
+if(DBUS_WITH_GLIB)
+ message(STATUS "with glib test apps")
+ add_definitions(
+ ${GLIB2_DEFINITIONS}
+ ${GOBJECT_DEFINITIONS}
+ ${DBUSGLIB_DEFINITIONS}
+ )
+ message(STATUS ${GLIB2_INCLUDE_DIR} ${DBUSGLIB_INCLUDE_DIR})
+
+ include_directories(
+ ${GLIB2_INCLUDE_DIR}
+ ${GOBJECT_INCLUDE_DIR}
+ ${DBUSGLIB_INCLUDE_DIR}
+ ${CMAKE_SOURCE_DIR}/../test
+ )
+ set (TEST_LIBRARIES dbus-testutils ${DBUSGLIB_LIBRARIES} ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
+
+ add_executable(test-corrupt ${CMAKE_SOURCE_DIR}/../test/corrupt.c)
+ target_link_libraries(test-corrupt ${TEST_LIBRARIES})
+
+ add_executable(test-dbus-daemon ${CMAKE_SOURCE_DIR}/../test/dbus-daemon.c)
+ target_link_libraries(test-dbus-daemon ${TEST_LIBRARIES})
+
+ add_executable(test-dbus-daemon-eavesdrop ${CMAKE_SOURCE_DIR}/../test/dbus-daemon-eavesdrop.c)
+ target_link_libraries(test-dbus-daemon-eavesdrop ${TEST_LIBRARIES})
+
+ add_executable(test-loopback ${CMAKE_SOURCE_DIR}/../test/loopback.c)
+ target_link_libraries(test-loopback ${TEST_LIBRARIES})
+
+ add_executable(test-marshal ${CMAKE_SOURCE_DIR}/../test/marshal.c)
+ target_link_libraries(test-marshal ${TEST_LIBRARIES})
+
+ add_executable(test-refs ${CMAKE_SOURCE_DIR}/../test/internals/refs.c)
+ target_link_libraries(test-refs ${TEST_LIBRARIES})
+
+ add_executable(test-relay ${CMAKE_SOURCE_DIR}/../test/relay.c)
+ target_link_libraries(test-relay ${TEST_LIBRARIES})
+
+ add_executable(test-syntax ${CMAKE_SOURCE_DIR}/../test/syntax.c)
+ target_link_libraries(test-syntax ${TEST_LIBRARIES})
+
+ add_executable(test-syslog ${CMAKE_SOURCE_DIR}/../test/internals/syslog.c)
+ target_link_libraries(test-syslog ${TEST_LIBRARIES})
+
+ add_executable(manual-authz ${CMAKE_SOURCE_DIR}/../test/manual-authz.c)
+ target_link_libraries(manual-authz ${TEST_LIBRARIES})
+endif()
+
### keep these in creation order, i.e. uppermost dirs first
set (TESTDIRS
test/data