summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2013-02-28 23:39:42 +0100
committerRalf Habacker <ralf.habacker@freenet.de>2013-03-01 00:10:59 +0100
commite93b0decbeb06f897621d3f816365033dfa16a94 (patch)
tree21f783eaf0dcf83c608a0dde78728e7719f4df50
parentc57c4d281369589b636aee928238b7cf6e42e00f (diff)
Add CMake build support.HEADmaster
FindDBus.cmake and FindGLib2.cmake has been taken from the KDE project, MacrosAutotools.cmake has been taken from dbus source. pkgconfig file install is still missing
-rw-r--r--CMakeLists.txt104
-rw-r--r--cmake/FindDBus.cmake72
-rw-r--r--cmake/FindGLIB2.cmake52
-rw-r--r--cmake/MacrosAutotools.cmake47
4 files changed, 275 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f918f6a
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,104 @@
+project(dbus_python C)
+cmake_minimum_required(VERSION 2.8)
+
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+include(MacrosAutotools)
+
+autoversion(configure.ac dbus_python)
+autoconfig(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h.cmake)
+
+set(PACKAGE "dbus-python")
+set(PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=dbus&component=python")
+set(PACKAGE_NAME "dbus-python")
+set(PACKAGE_URL "")
+set(PACKAGE_VERSION ${DBUS_PYTHON_VERSION_STRING})
+set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+set(PACKAGE_TARNAME "${PACKAGE_NAME}")
+
+include (CheckTypeSize)
+
+#DBUS
+find_package(DBus REQUIRED)
+include_directories(${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
+set(CMAKE_REQUIRED_INCLUDES ${DBUS_INCLUDE_DIR})
+set(CMAKE_EXTRA_INCLUDE_FILES dbus/dbus.h)
+#check_type_size(DBusBasicValue HAVE_DBUSBASICVALUE)
+set(HAVE_DBUSBASICVALUE 1)
+
+configure_file(${CMAKE_CURRENT_BINARY_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(${DBUS_INCLUDE_DIR})
+
+#GLIB
+find_package(GLIB2 REQUIRED)
+
+# Find Python executable
+find_package(PythonInterp REQUIRED)
+find_package(PythonLibs REQUIRED)
+
+if(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE)
+ message(SEND_ERROR "You need Python to build the dbus python bindings")
+endif(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE)
+
+# The code below prints the Python extension for the current system
+set(get_python_suffix "import imp ; print(list(filter(lambda s : s[1] == 'rb' and s[0][0] == '.', imp.get_suffixes()))[0][0])")
+
+find_file(stdint stdint.h)
+if(NOT stdint)
+ message(SEND_ERROR "You need a C99 compliant stdint.h for windows, use e.g. http://msinttypes.googlecode.com/svn/trunk/stdint.h")
+endif(NOT stdint)
+
+execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "${get_python_suffix}"
+ OUTPUT_VARIABLE _modsuffix
+)
+string(REPLACE "\n" "" _modsuffix ${_modsuffix})
+message(STATUS "Python module suffix is: ${_modsuffix}")
+
+# The code below returns the site-packages directory for the current system
+set(get_site_package_dir "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
+execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "${get_site_package_dir}"
+ OUTPUT_VARIABLE site_pkg
+)
+string(REPLACE "\n" "" site_pkg ${site_pkg})
+message(STATUS "Python module path is: ${site_pkg}")
+
+include_directories(include/ ${PYTHON_INCLUDE_DIRS})
+include_directories(_dbus_bindings/)
+file(GLOB dbus_binding_sources _dbus_bindings/*.c)
+add_library(_dbus_bindings SHARED ${dbus_binding_sources})
+target_link_libraries(_dbus_bindings ${PYTHON_LIBRARIES} ${DBUS_LIBRARY})
+install(TARGETS _dbus_bindings RUNTIME DESTINATION ${site_pkg} LIBRARY DESTINATION ${site_pkg})
+
+include_directories(_dbus_glib_bindings/ ${GLIB2_INCLUDE_DIR} ${GLIB2_CONFIG_INCLUDE_DIR} ${DBUS_INCLUDE_DIR})
+file(GLOB dbus_glib_binding_sources _dbus_glib_bindings/*.c)
+add_library(_dbus_glib_bindings SHARED ${dbus_glib_binding_sources})
+target_link_libraries(_dbus_glib_bindings ${PYTHON_LIBRARIES} ${DBUS_LIBRARY} ${DBUS_GLIB_LIBRARY} ${GLIB2_LIBRARIES})
+install(TARGETS _dbus_glib_bindings RUNTIME DESTINATION ${site_pkg} LIBRARY DESTINATION ${site_pkg})
+
+install(FILES include/dbus-python.h DESTINATION include/dbus-1/dbus)
+install(DIRECTORY dbus DESTINATION ${site_pkg}/dbus)
+
+install(DIRECTORY doc DESTINATION share/doc/dbus-python)
+install(FILES README NEWS DESTINATION share/doc/dbus-python)
+
+file(GLOB dbus_py_test_sources test/*.c)
+add_library(dbus_py_test SHARED ${dbus_py_test_sources})
+target_link_libraries(dbus_py_test ${PYTHON_LIBRARIES} ${DBUS_LIBRARY})
+
+set_target_properties(_dbus_bindings _dbus_glib_bindings dbus_py_test
+ PROPERTIES
+ PREFIX "" # There is no prefix even on UNIXes
+ SUFFIX "${_modsuffix}" # The extension got from Python libraries
+)
+
+set(PYTHON ${PYTHON_EXECUTABLE})
+set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
+set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/tmp-session-bus.conf.in ${CMAKE_CURRENT_BINARY_DIR}/test/tmp-session-bus.conf)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/TestSuitePythonService.service.in ${CMAKE_CURRENT_BINARY_DIR}/test/TestSuitePythonService.service)
+#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus-python.pc.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-python.pc)
+#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dbus-python.pc DESTINATION lib64/pkgconfig)
+
diff --git a/cmake/FindDBus.cmake b/cmake/FindDBus.cmake
new file mode 100644
index 0000000..f227cc2
--- /dev/null
+++ b/cmake/FindDBus.cmake
@@ -0,0 +1,72 @@
+# - Try to find the low-level D-Bus library
+# Once done this will define
+#
+# DBUS_FOUND - system has D-Bus
+# DBUS_INCLUDE_DIR - the D-Bus include directory
+# DBUS_ARCH_INCLUDE_DIR - the D-Bus architecture-specific include directory
+# DBUS_LIBRARIES - the libraries needed to use D-Bus
+
+# Copyright (c) 2008, Kevin Kofler, <kevin.kofler@chello.at>
+# modeled after FindLibArt.cmake:
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
+
+ # in cache already
+ SET(DBUS_FOUND TRUE)
+
+else (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
+
+ IF (NOT WIN32)
+ FIND_PACKAGE(PkgConfig)
+ IF (PKG_CONFIG_FOUND)
+ # use pkg-config to get the directories and then use these values
+ # in the FIND_PATH() and FIND_LIBRARY() calls
+ pkg_check_modules(_DBUS_PC QUIET dbus-1)
+ ENDIF (PKG_CONFIG_FOUND)
+ ENDIF (NOT WIN32)
+
+ FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h
+ ${_DBUS_PC_INCLUDE_DIRS}
+ /usr/include
+ /usr/include/dbus-1.0
+ /usr/local/include
+ )
+
+ FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h
+ ${_DBUS_PC_INCLUDE_DIRS}
+ /usr/lib${LIB_SUFFIX}/include
+ /usr/lib${LIB_SUFFIX}/dbus-1.0/include
+ /usr/lib64/include
+ /usr/lib64/dbus-1.0/include
+ /usr/lib/include
+ /usr/lib/dbus-1.0/include
+ )
+
+ FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 dbus
+ PATHS
+ ${_DBUS_PC_LIBDIR}
+ )
+
+
+ if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
+ set(DBUS_FOUND TRUE)
+ endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
+
+
+ if (DBUS_FOUND)
+ if (NOT DBus_FIND_QUIETLY)
+ message(STATUS "Found D-Bus: ${DBUS_LIBRARIES}")
+ endif (NOT DBus_FIND_QUIETLY)
+ else (DBUS_FOUND)
+ if (DBus_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find D-Bus")
+ endif (DBus_FIND_REQUIRED)
+ endif (DBUS_FOUND)
+
+ MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIBRARIES)
+
+endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
diff --git a/cmake/FindGLIB2.cmake b/cmake/FindGLIB2.cmake
new file mode 100644
index 0000000..09fd98d
--- /dev/null
+++ b/cmake/FindGLIB2.cmake
@@ -0,0 +1,52 @@
+# - 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>
+#
+# 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)
+
+find_package(PkgConfig)
+pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0)
+
+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}
+)
+
+set(GLIB2_LIBRARIES ${GLIB2_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/MacrosAutotools.cmake b/cmake/MacrosAutotools.cmake
new file mode 100644
index 0000000..08c95d1
--- /dev/null
+++ b/cmake/MacrosAutotools.cmake
@@ -0,0 +1,47 @@
+#
+# @Author Ralf Habacker
+#
+# extracts version information from autoconf config file
+# and set related cmake variables
+#
+# returns
+# ${prefix}_VERSION
+# ${prefix}_VERSION_STRING
+# ${prefix}_MAJOR_VERSION
+# ${prefix}_MINOR_VERSION
+# ${prefix}_MICRO_VERSION
+#
+macro(autoversion config prefix)
+ file (READ ${config} _configure_ac)
+ string(TOUPPER ${prefix} prefix_upper)
+ string (REGEX REPLACE ".*${prefix}_major_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_minor_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_micro_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac})
+ set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION})
+ set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
+
+endmacro()
+
+#
+# parses config.h template and create cmake equivalent
+# not implemented yet
+#
+macro(autoconfig template output)
+ file(READ ${template} contents)
+ # Convert file contents into a CMake list (where each element in the list
+ # is one line of the file)
+ STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
+ STRING(REGEX REPLACE "\n" ";" contents "${contents}")
+ #message(STATUS ${contents})
+ foreach(line ${contents})
+ if(line MATCHES "#undef HAVE")
+ STRING(REGEX REPLACE "#undef (.*)$" "#cmakedefine \\1 @\\1@" line "${line}")
+ elseif(line MATCHES "#undef")
+ STRING(REGEX REPLACE "#undef (.*)$" "#cmakedefine \\1 \"@\\1@\"" line "${line}")
+ endif()
+ #message(STATUS ${line})
+ # append to config.h #define <variable-name> <variable-content>
+ set(outlines "${outlines}\n${line}")
+ endforeach()
+ file(WRITE ${output} ${outlines})
+endmacro()