summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: f918f6aab0c74f0182f5f03d63705ba8a1a8b448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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)