Merge branch 'dbus-1.10'
[platform/upstream/dbus.git] / cmake / CMakeLists.txt
1 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
2 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
3
4 # we do not need to have WIN32 defined
5 set(CMAKE_LEGACY_CYGWIN_WIN32 0)
6
7 project(dbus)
8
9 # we need to be up to date
10 CMAKE_MINIMUM_REQUIRED(VERSION 2.4.4 FATAL_ERROR)
11 if(COMMAND cmake_policy)
12     cmake_policy(SET CMP0003 NEW)
13 endif(COMMAND cmake_policy)
14
15 if(CMAKE_MAJOR_VERSION GREATER 2)
16     cmake_policy(SET CMP0026 NEW)
17     if (CMAKE_MAJOR_VERSION GREATER 4 OR CMAKE_MINOR_VERSION GREATER 1)
18         cmake_policy(SET CMP0053 NEW)
19         cmake_policy(SET CMP0054 NEW)
20     endif()
21 endif()
22
23 # detect version
24 include(MacrosAutotools)
25 autoinit(../configure.ac)
26 autoversion(dbus)
27
28 if(EXISTS ../config.h.in)
29     autoheaderchecks(../config.h.in ConfigureChecks.cmake config.h.cmake)
30 else()
31     message(STATUS "Generate config.h.in with autogen.sh to enable cmake header difference check.")
32 endif()
33
34 # used by file version info
35 set (DBUS_PATCH_VERSION "0")
36
37 # set PACKAGE_... variables
38 autopackage(
39     dbus
40     ${DBUS_VERSION_STRING}
41     "http://dbus.freedesktop.org"
42     "https://bugs.freedesktop.org/enter_bug.cgi?product=dbus"
43 )
44
45 include(Macros)
46 TIMESTAMP(DBUS_BUILD_TIMESTAMP)
47
48 ########### basic vars ###############
49
50 include(GNUInstallDirs)
51
52 if (DBUSDIR)
53         set(DBUS_INSTALL_DIR "${DBUSDIR}")
54 endif (DBUSDIR)
55 if ($ENV{DBUSDIR})
56         set(DBUS_INSTALL_DIR "$ENV{DBUSDIR}")
57 endif ($ENV{DBUSDIR})
58
59 if (DBUS_INSTALL_DIR)
60         set(CMAKE_INSTALL_PREFIX "${DBUS_INSTALL_DIR}" CACHE PATH "install prefix" FORCE)
61 else (DBUS_INSTALL_DIR)
62         set(DBUS_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
63 endif (DBUS_INSTALL_DIR)
64
65 set(DBUS_PREFIX ${DBUS_INSTALL_DIR})
66
67 set(prefix                   ${DBUS_INSTALL_DIR})
68 set(exec_prefix              ${prefix})
69 set(DBUS_MACHINE_UUID_FILE   ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dbus/machine-id)
70 set(DBUS_BINDIR              ${CMAKE_INSTALL_FULL_BINDIR})
71 set(DBUS_DAEMONDIR           ${CMAKE_INSTALL_FULL_BINDIR})
72 set(DBUS_LOCALSTATEDIR       ${CMAKE_INSTALL_FULL_LOCALSTATEDIR})
73 set(DBUS_RUNSTATEDIR         ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run)
74
75 # On Windows this is relative to where we put the bus setup, in
76 # ${datadir}/dbus-1. For simplicity, we only do this if
77 # ${sysconfdir} = ${prefix}/etc and ${datadir} = ${prefix}/share.
78 #
79 # On Unix, or on Windows with weird install layouts, it's the absolute path.
80 if(WIN32 AND ${CMAKE_INSTALL_FULL_SYSCONFDIR} STREQUAL ${prefix}/etc AND ${CMAKE_INSTALL_FULL_DATADIR} STREQUAL ${prefix}/share)
81 set(SYSCONFDIR_FROM_PKGDATADIR ../../etc)
82 set(DATADIR_FROM_PKGSYSCONFDIR ../../share)
83 else()
84 set(SYSCONFDIR_FROM_PKGDATADIR ${CMAKE_INSTALL_FULL_SYSCONFDIR})
85 set(DATADIR_FROM_PKGSYSCONFDIR ${CMAKE_INSTALL_FULL_DATADIR})
86 endif()
87
88 option (DBUS_RELOCATABLE "Attempt to make metadata relocatable" ON)
89
90 # For simplicity, we're not relocatable if CMAKE_INSTALL_LIBDIR
91 # is something more complicated (e.g. Debian multiarch);
92 # we don't want to have to compute how many ../ to add
93 if(CMAKE_INSTALL_LIBDIR STREQUAL "lib" OR CMAKE_INSTALL_LIBDIR STREQUAL "lib64")
94     # We know we can use ../ to get to the prefix. Do nothing.
95 elseif(DBUS_RELOCATABLE)
96     # Sorry, it's too hard to make this particular build relocatable
97     message("Unusual CMAKE_INSTALL_LIBDIR: the generated package will not be relocatable.")
98     set(DBUS_RELOCATABLE OFF)
99 endif()
100
101 # used in the C code
102 set(DBUS_LIBEXECDIR          ${CMAKE_INSTALL_FULL_LIBEXECDIR})
103 set(DBUS_DATADIR             ${CMAKE_INSTALL_FULL_DATADIR})
104
105 #enable building of shared library
106 SET(BUILD_SHARED_LIBS ON)
107
108 set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
109
110 if (CYGWIN)
111    set (WIN32)
112 endif (CYGWIN)
113
114 # search for required packages
115 if (WIN32)
116     # include local header first to avoid using old installed header
117     set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/..)
118         find_package(LibIconv)
119     include(Win32Macros)
120     addExplorerWrapper(${CMAKE_PROJECT_NAME})
121 endif (WIN32)
122
123 if(NOT WIN32)
124         option (DBUS_ENABLE_ABSTRACT_SOCKETS "enable support for abstract sockets" ON)
125         set (CMAKE_THREAD_PREFER_PTHREAD ON)
126         include (FindThreads)
127 endif(NOT WIN32)
128
129 option (DBUS_DISABLE_ASSERT "Disable assertion checking" OFF)
130
131 option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF)
132
133 if(WIN32)
134     set(FD_SETSIZE "8192" CACHE STRING "The maximum number of connections that can be handled at once")
135 endif()
136
137 find_package(EXPAT)
138 find_package(X11)
139 find_package(GLib2)
140 find_package(GObject)
141 if(GLIB2_FOUND AND GOBJECT_FOUND)
142     option (DBUS_WITH_GLIB "build with glib" ON)
143 endif()
144
145 # analogous to AC_USE_SYSTEM_EXTENSIONS in configure.ac
146 add_definitions(-D_GNU_SOURCE)
147
148 # do config checks
149 INCLUDE(ConfigureChecks.cmake)
150
151 # @TODO: how to remove last dir from ${CMAKE_SOURCE_DIR} ?
152 SET(DBUS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/..)
153
154 # make some more macros available
155 include (MacroLibrary)
156
157 if(VCS)
158         set(DBUS_VERBOSE_C_S 1 CACHE STRING "verbose mode" FORCE)
159 endif(VCS)
160
161 if(MSVC)
162     # controll folders in msvc projects
163     include(ProjectSourceGroup)
164     if(NOT GROUP_CODE)
165         #set(GROUP_CODE split) #cmake default
166         set(GROUP_CODE flat)
167     endif(NOT GROUP_CODE)
168     ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
169     SET(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG}   /FIconfig.h")
170     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /FIconfig.h")
171 endif()
172
173 #
174 # setup warnings
175 #
176 if(MSVC)
177     # Use the highest warning level
178     if(WALL)
179         set(WALL 1 CACHE STRING "all warnings"  FORCE)
180         set(CMAKE_CXX_WARNING_LEVEL 4 CACHE STRING "warning level" FORCE)
181         if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
182             string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
183         else()
184             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
185         endif()
186
187         if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
188             string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
189         else()
190             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
191         endif()
192     else()
193         set(CMAKE_CXX_WARNING_LEVEL 3 CACHE STRING "warning level" FORCE)
194     endif()
195
196     # see https://msdn.microsoft.com/en-us/library/z78503e6.aspx
197     # 4018 'expression' : signed/unsigned mismatch
198     set(WARNINGS "4018")
199     # 4090 'operation' : different 'modifier' qualifiers
200     # 4101 'identifier' : unreferenced local variable
201     # 4127 conditional expression is constant
202     # 4244 'argument' : conversion from 'type1' to 'type2', possible loss of data
203     set(WARNINGS_DISABLED "4090 4101 4127 4244")
204     # 4002 too many actual parameters for macro 'identifier'
205     # 4003 not enough actual parameters for macro 'identifier'
206     # 4013 'function' undefined; assuming extern returning int
207     # 4028 formal parameter 'number' different from declaration
208     # 4031 second formal parameter list longer than the first list
209     # 4047 operator' : 'identifier1' differs in levels of indirection from 'identifier2'
210     # 4114 same type qualifier used more than once
211     # 4133 'type' : incompatible types - from 'type1' to 'type2'
212     set(WARNINGS_ERRORS "4002 4003 4013 4028 4031 4047 4114 4133")
213 else()
214     set(WARNINGS "sign-compare")
215     set(WARNINGS_DISABLED "")
216     set(WARNINGS_ERRORS "")
217 endif()
218 generate_warning_cflags(WARNINGS_CFLAGS "${WARNINGS}" "${WARNINGS_DISABLED}" "${WARNINGS_ERRORS}")
219 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNINGS_CFLAGS}")
220 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS_CFLAGS}")
221
222
223 if (UNIX AND NOT DBUS_DISABLE_ASSERT)
224         # required for backtrace
225         SET(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG}   -Wl,--export-dynamic")
226         SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,--export-dynamic")
227         add_definitions(-DDBUS_BUILT_R_DYNAMIC)
228 endif (UNIX AND NOT DBUS_DISABLE_ASSERT)
229
230 if(DBUS_WITH_GLIB)
231     autodefine(GLIB_VERSION_MIN_REQUIRED)
232     autodefine(GLIB_VERSION_MAX_ALLOWED)
233 endif()
234
235 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}  -D_DEBUG")
236
237 #########################################################################
238 # Windows CE (>= 5.0.0)
239 #
240 # WinCE support now relies on the presence of platform files, found in cmake/modules/platform
241 # Cmake 2.8.0 doesn't include WinCE platform files by default, but working ones can be found
242 # on CMake's bugtracker :
243 # http://public.kitware.com/Bug/view.php?id=7919
244 #
245 # for cmake 2.8.0 get the following patch only :
246 # http://public.kitware.com/Bug/file_download.php?file_id=2944&type=bug
247 #
248 # after applying the patch, you can enable the WinCE build by specifying :
249 # cmake [...] -DCMAKE_SYSTEM_NAME=WinCE -DCMAKE_SYSTEM_VERSION=X.XX
250 # (where X.XX is your actual WinCE version, e.g. 5.02 for Windows Mobile 6)
251 #
252 # Note that you should have a proper cross-compilation environment set up prior to running
253 # cmake, ie. the PATH, INCLUDE and LIB env vars pointing to your CE SDK/toolchain.
254 #
255 if(WINCE)
256
257 MESSAGE("Building for WinCE (${CMAKE_SYSTEM_VERSION})")
258
259 endif(WINCE)
260 #########################################################################
261
262
263 ENABLE_TESTING()
264
265 #########################################################################
266 # Disallow in-source build
267 #macro_ensure_out_of_source_build("dbus requires an out of source build. Please create a separate build directory and run 'cmake path_to_dbus [options]' there.")
268
269 # ... and warn in case of an earlier in-source build
270 #set(generatedFileInSourceDir EXISTS ${dbus_SOURCE_DIR}/config.h)
271 #if(${generatedFileInSourceDir})
272 #   message(STATUS "config.h exists in your source directory.")
273 #endif(${generatedFileInSourceDir})
274 #########################################################################
275
276 if (WIN32 OR CYGWIN)
277         set (LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/bin)
278 else (WIN32 OR CYGWIN)
279         set (LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)
280 endif (WIN32 OR CYGWIN)
281
282 set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
283
284 # for including config.h and for includes like <dir/foo.h>
285 include_directories( ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR} ${CMAKE_INCLUDE_PATH} )
286
287 # linker search directories
288 link_directories(${DBUS_LIB_DIR} ${LIBRARY_OUTPUT_PATH} )
289 include_directories( ${CMAKE_LIBRARY_PATH}  )
290
291 set(DBUS_INCLUDES)
292
293 ENABLE_TESTING()
294
295 ########### command line options ###############
296 # TODO: take check from configure.in
297
298 option (DBUS_BUILD_TESTS "enable unit test code" ON)
299  
300 if(DBUS_BUILD_TESTS)
301     set (DBUS_ENABLE_EMBEDDED_TESTS ON)
302     set (DBUS_ENABLE_MODULAR_TESTS ON)
303     add_definitions(-DDBUS_ENABLE_EMBEDDED_TESTS -DDBUS_ENABLE_MODULAR_TESTS)
304 endif(DBUS_BUILD_TESTS)
305
306 option (DBUS_USE_OUTPUT_DEBUG_STRING "enable win32 debug port for message output" OFF)
307 if(DBUS_USE_OUTPUT_DEBUG_STRING)
308     add_definitions(-DDBUS_USE_OUTPUT_DEBUG_STRING)
309 endif(DBUS_USE_OUTPUT_DEBUG_STRING)
310
311 if(WIN32)
312         # win32 dbus service support - this support is not complete
313         option (DBUS_SERVICE "enable dbus service installer" OFF)
314 endif(WIN32)
315
316 option (DBUS_ENABLE_ANSI "enable -ansi -pedantic gcc flags" OFF)
317 if(DBUS_ENABLE_ANSI)
318    if(NOT MSVC)
319         add_definitions(-ansi -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -pedantic)
320    else(NOT MSVC)
321         add_definitions(-Za -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -W4)
322    endif(NOT MSVC)
323 endif(DBUS_ENABLE_ANSI)
324
325 option (DBUS_ENABLE_VERBOSE_MODE "support verbose debug mode" ON)
326
327 option (DBUS_DISABLE_CHECKS "Disable public API sanity checking" OFF)
328
329 if(NOT MSVC)
330     option (DBUS_GCOV_ENABLED "compile with coverage profiling instrumentation (gcc only)" OFF)
331     if(DBUS_GCOV_ENABLED)
332             add_definitions(-fprofile-arcs -ftest-coverage)
333             # FIXME!!!!
334             ## remove optimization
335     #        CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'`
336     endif(DBUS_GCOV_ENABLED)
337 endif(NOT MSVC)
338
339 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
340     option (DBUS_BUS_ENABLE_INOTIFY "build with inotify support (linux only)" ON)
341     if(DBUS_BUS_ENABLE_INOTIFY)
342         if(NOT HAVE_SYS_INOTIFY_H)
343             message(FATAL_ERROR "sys/inotify.h not found!")
344         endif(NOT HAVE_SYS_INOTIFY_H)
345     endif(DBUS_BUS_ENABLE_INOTIFY)
346 elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*BSD")
347     option (DBUS_BUS_ENABLE_KQUEUE "build with kqueue support (FreeBSD only)" ON)
348     if(DBUS_BUS_ENABLE_KQUEUE)
349         if(NOT HAVE_SYS_EVENT_H)
350             message(FATAL_ERROR "sys/event.h not found!")
351         endif(NOT HAVE_SYS_EVENT_H)
352     endif(DBUS_BUS_ENABLE_KQUEUE)
353 endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
354
355 STRING(TOUPPER ${CMAKE_SYSTEM_NAME} sysname)
356 if("${sysname}" MATCHES ".*SOLARIS.*")
357     option (HAVE_CONSOLE_OWNER_FILE "enable console owner file (solaris only)" ON)
358     if(HAVE_CONSOLE_OWNER_FILE)
359         set (DBUS_CONSOLE_OWNER_FILE "/dev/console" CACHE STRING "Directory to check for console ownerhip")
360     endif(HAVE_CONSOLE_OWNER_FILE)
361 endif("${sysname}" MATCHES ".*SOLARIS.*")
362
363 if(NOT EXPAT_FOUND)
364     message(FATAL_ERROR "expat not found!")
365 endif(NOT EXPAT_FOUND)
366
367 # all missing or hardcoded for now
368
369 # 'hidden' ones
370 set(atomic_int OFF)
371 set(atomic_int486 OFF)
372 if(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI)
373     FIND_PROGRAM(UNAME_EXECUTABLE
374                     NAMES uname
375                     PATHS /bin /usr/bin /usr/local/bin c:/Programme/MSys/bin d:/Programme/MSys/bin)
376
377     if(UNAME_EXECUTABLE)
378         EXECUTE_PROCESS(COMMAND ${UNAME_EXECUTABLE} "-m"
379                         OUTPUT_VARIABLE UNAME_OUTPUT)
380
381         if("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
382             set(atomic_int ON)
383         else("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
384             if("UNAME_OUTPUT" MATCHES "^.*i?86.*$")
385                 set(atomic_int ON)
386                 set(atomic_int_486 ON)
387             endif("UNAME_OUTPUT" MATCHES "^.*i?86.*$")
388         endif("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
389     endif(UNAME_EXECUTABLE)
390 endif(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI)
391
392 if(X11_FOUND)
393   option (DBUS_BUILD_X11 "Build with X11 autolaunch support " ON)
394 endif(X11_FOUND)
395
396 # test binary names
397 if (WIN32)
398     # follow Automake's naming convention so we can share .in files
399     set (EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
400 endif(WIN32)
401
402 if (MSVC_IDE)
403     if(CMAKE_BUILD_TYPE MATCHES Debug)
404                 set(IDE_BIN /Debug )
405                 message(STATUS)
406                 message(STATUS "Visual Studio: test programs will only work with 'Debug' configuration!")
407                 message(STATUS "To run tests with 'Release' configuration use -DCMAKE_BUILD_TYPE=Release")
408                 message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs")
409                 message(STATUS)
410     else(CMAKE_BUILD_TYPE MATCHES Debug)
411                 set(IDE_BIN /Release)
412                 message(STATUS)
413                 message(STATUS "Visual Studio: test programs will only work with 'Release' configuration!")
414                 message(STATUS "To run tests with 'Debug' configuration use -DCMAKE_BUILD_TYPE=Debug")
415                 message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs")
416                 message(STATUS)
417     endif(CMAKE_BUILD_TYPE MATCHES Debug)
418         set (TEST_PATH_FORCE FORCE)
419         FILE(REMOVE ${CMAKE_BINARY_DIR}/data/dbus-1/services)
420 endif (MSVC_IDE)
421
422 #### Find socket directories
423 if(UNIX)
424     if(NOT $ENV{TMPDIR} STREQUAL "")
425         set(DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR})
426     elseif(NOT $ENV{TEMP} STREQUAL "")
427         set(DBUS_SESSION_SOCKET_DIR $ENV{TEMP})
428     elseif(NOT $ENV{TMP} STREQUAL "")
429         set(DBUS_SESSION_SOCKET_DIR $ENV{TMP})
430     else()
431         set(DBUS_SESSION_SOCKET_DIR /tmp)
432     endif()
433 endif()
434
435  # Not used on Windows, where there is no system bus
436 set (DBUS_SYSTEM_PID_FILE ${DBUS_RUNSTATEDIR}/dbus/pid)
437
438 if (WIN32)
439         set (DBUS_CONSOLE_AUTH_DIR "")
440 else (WIN32)
441         set (DBUS_CONSOLE_AUTH_DIR "/var/run/console/")
442 endif (WIN32)
443
444 # This won't work on Windows. It's not meant to - the system bus is
445 # meaningless on Windows anyway.
446 #
447 # This has to be suitable for hard-coding in client libraries as well as
448 # in the dbus-daemon's configuration, so it has to be valid to listen on
449 # and also to connect to. If this ever changes, it'll need to be split into
450 # two variables, one for the listening address and one for the connecting
451 # address.
452 set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=${DBUS_RUNSTATEDIR}/dbus/system_bus_socket" CACHE STRING "system bus default address")
453
454 if (WIN32)
455   set (DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address")
456   set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
457
458   set (DBUS_SYSTEM_CONFIG_FILE "share/dbus-1/system.conf")
459   set (DBUS_SESSION_CONFIG_FILE "share/dbus-1/session.conf")
460   # bus-test expects a non empty string
461   set (DBUS_USER "Administrator")
462   set (DBUS_TEST_USER "guest")
463   set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<!--<auth>EXTERNAL</auth>-->")
464 else (WIN32)
465   set (DBUS_SESSION_BUS_LISTEN_ADDRESS "unix:tmpdir=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default listening address")
466   set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
467   set (sysconfdir "")
468   set (configdir ${sysconfdir}/dbus-1 )
469   set (DBUS_SYSTEM_CONFIG_FILE  ${configdir}/system.conf)
470   set (DBUS_SESSION_CONFIG_FILE ${configdir}/session.conf)
471   set (DBUS_USER "messagebus")
472   set (DBUS_TEST_USER "nobody")
473   # For best security, assume that all non-Windows platforms can do
474   # credentials-passing.
475   set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<auth>EXTERNAL</auth>")
476 endif (WIN32)
477
478 set (DBUS_DAEMON_NAME "dbus-daemon" CACHE STRING "The name of the dbus daemon executable")
479
480 ########### create config.h ###############
481
482 #include(ConfigureChecks.cmake)
483
484 # better use flags for gcc
485 if (MINGW)
486         set (HAVE_GNUC_VARARGS 1)
487 endif(MINGW)
488
489 # compiler definitions
490 add_definitions(-DHAVE_CONFIG_H=1)
491 add_definitions(${DBUS_BUS_CFLAGS})
492
493
494 if (DBUS_BUILD_TESTS)
495     # set variables used for the .in files (substituted by configure_file) in test/data:
496     set(DBUS_TEST_EXEC ${EXECUTABLE_OUTPUT_PATH}${IDE_BIN})
497     set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data)
498     set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test)
499     if (UNIX)
500         set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR})
501         set(TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}")
502     endif()
503     if (WIN32)
504         set (TEST_LISTEN "tcp:host=localhost")
505     endif (WIN32)
506 endif  (DBUS_BUILD_TESTS)
507
508 set(DBUS_LIBRARIES dbus-1)
509 set(DBUS_INTERNAL_LIBRARIES dbus-internal)
510
511 set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC)
512 set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_COMPILATION")
513
514 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
515
516 if (WIN32)
517 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus-env.bat.cmake ${CMAKE_BINARY_DIR}/bin/dbus-env.bat )
518     install(FILES ${CMAKE_BINARY_DIR}/bin/dbus-env.bat DESTINATION bin)
519 endif()
520
521 add_definitions(-DHAVE_CONFIG_H=1)
522
523 #
524 # create cmake find_package related files
525 #
526 set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/DBus1)
527 if(WIN32)
528    configure_file(DBus1Config.cmake.in "${CMAKE_BINARY_DIR}/DBus1Config.cmake" @ONLY)
529 else()
530    configure_file(DBus1Config.pkgconfig.in "${CMAKE_BINARY_DIR}/DBus1Config.cmake" @ONLY)
531 endif()
532 configure_file(DBus1ConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake" @ONLY)
533 install(FILES
534     "${CMAKE_BINARY_DIR}/DBus1Config.cmake"
535     "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake"
536     DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev
537 )
538
539 if(WIN32)
540     install(EXPORT DBus1Targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
541 endif()
542
543 ########### subdirs ###############
544
545 add_subdirectory( dbus )
546 add_subdirectory( bus )
547 if (DBUS_BUILD_TESTS)
548         add_subdirectory( test )
549         add_custom_target(check
550                 COMMAND ctest -R ^test-.*
551         )
552 endif (DBUS_BUILD_TESTS)
553 add_subdirectory( tools )
554 add_subdirectory( doc )
555
556
557 OPTION(DBUS_INSTALL_SYSTEM_LIBS "install required system libraries" OFF)
558 MESSAGE(" ")
559 MESSAGE("set -DDBUS_INSTALL_SYSTEM_LIBS=1 to install runtime libraries too")
560 MESSAGE("set DBUSDIR (environment or cmake option) to overwrite the default install directory ")
561 MESSAGE(" ")
562 MESSAGE(" ")
563 GET_FILENAME_COMPONENT(C_COMPILER ${CMAKE_C_COMPILER} NAME)
564 GET_FILENAME_COMPONENT(CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME)
565
566 message("                  D-BUS ${DBUS_VERSION}                               ")
567 message("                  =============                                       ")
568 message("                                                                      ")
569 message("        install prefix:           ${prefix}                           ")
570 message("        install exec_prefix:      ${exec_prefix}                      ")
571 message("        install libdir:           ${CMAKE_INSTALL_FULL_LIBDIR}        ")
572 message("        install bindir:           ${CMAKE_INSTALL_FULL_BINDIR}        ")
573 message("        install sysconfdir:       ${CMAKE_INSTALL_FULL_SYSCONFDIR}    ")
574 message("        install datadir:          ${CMAKE_INSTALL_FULL_DATADIR}       ")
575 message("        source code location:     ${DBUS_SOURCE_DIR}                  ")
576 message("        build dir:                ${CMAKE_BINARY_DIR}                 ")
577 message("        c compiler:               ${C_COMPILER}                       ")
578 message("        cflags:                   ${CMAKE_C_FLAGS}                    ")
579 message("        cflags debug:             ${CMAKE_C_FLAGS_DEBUG}              ")
580 message("        cflags release:           ${CMAKE_C_FLAGS_RELEASE}            ")
581 message("        cxx compiler:             ${CXX_COMPILER}                     ")
582 message("        cxxflags:                 ${CMAKE_CXX_FLAGS}                  ")
583 message("        cxxflags debug:           ${CMAKE_CXX_FLAGS_DEBUG}            ")
584 message("        cxxflags release:         ${CMAKE_CXX_FLAGS_RELEASE}          ")
585 message("        64-bit int:               ${DBUS_INT64_TYPE}                  ")
586 message("        32-bit int:               ${DBUS_INT32_TYPE}                  ")
587 message("        16-bit int:               ${DBUS_INT16_TYPE}                  ")
588 message("        Doxygen:                  ${DOXYGEN}                          ")
589 message("        Docbook Generator:        ${DOCBOOK_GENERATOR_NAME}           ")
590
591
592 message("        gcc coverage profiling:   ${DBUS_GCOV_ENABLED}                ")
593 message("        Building unit tests:      ${DBUS_BUILD_TESTS}                 ")
594 message("        Building with GLib:       ${DBUS_WITH_GLIB}                   ")
595 message("        Building verbose mode:    ${DBUS_ENABLE_VERBOSE_MODE}         ")
596 message("        Building w/o assertions:  ${DBUS_DISABLE_ASSERT}              ")
597 message("        Building w/o checks:      ${DBUS_DISABLE_CHECKS}              ")
598 message("        Building bus stats API:   ${DBUS_ENABLE_STATS}                ")
599 message("        installing system libs:   ${DBUS_INSTALL_SYSTEM_LIBS}         ")
600 message("        Building inotify support: ${DBUS_BUS_ENABLE_INOTIFY}          ")
601 message("        Building kqueue support:  ${DBUS_BUS_ENABLE_KQUEUE}           ")
602 message("        Building Doxygen docs:    ${DBUS_ENABLE_DOXYGEN_DOCS}         ")
603 message("        Building XML docs:        ${DBUS_ENABLE_XML_DOCS}             ")
604 message("        Daemon executable name:   ${DBUS_DAEMON_NAME}")
605 if(WIN32)
606 message("        Session bus listens on:   ${DBUS_SESSION_BUS_LISTEN_ADDRESS}  ")
607 message("        Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} ")
608 else()
609 message("        System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
610 message("        System bus socket:        ${DBUS_SYSTEM_SOCKET}               ")
611 message("        System bus PID file:      ${DBUS_SYSTEM_PID_FILE}             ")
612 message("        System bus user:          ${DBUS_USER}                        ")
613 message("        Session bus socket dir:   ${DBUS_SESSION_SOCKET_DIR}          ")
614 message("        Console auth dir:         ${DBUS_CONSOLE_AUTH_DIR}            ")
615 message("        'make check' socket dir:  ${TEST_SOCKET_DIR}                  ")
616 endif()
617 message("        Test listen address:      ${TEST_LISTEN}                      ")
618 if (MSVC)
619 message("        build timestamp:          ${DBUS_BUILD_TIMESTAMP}             ")
620 endif (MSVC)
621
622 MESSAGE(" ")
623 if (DBUS_BUILD_TESTS)
624     message("NOTE: building with unit tests increases the size of the installed library and renders it insecure.")
625 endif(DBUS_BUILD_TESTS)
626
627 if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
628     message("NOTE: building with unit tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)")
629 endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
630
631 if (DBUS_GCOV_ENABLED)
632     message("NOTE: building with coverage profiling is definitely for developers only.")
633 endif(DBUS_GCOV_ENABLED)
634
635 if (DBUS_ENABLE_VERBOSE_MODE)
636     message("NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance.")
637 endif(DBUS_ENABLE_VERBOSE_MODE)
638
639 if(NOT DBUS_DISABLE_ASSERT)
640     message("NOTE: building with assertions increases library size and decreases performance.")
641 endif(NOT DBUS_DISABLE_ASSERT)
642
643 if (DBUS_DISABLE_CHECKS)
644     message("NOTE: building without checks for arguments passed to public API makes it harder to debug apps using D-BUS, but will slightly decrease D-BUS library size and _very_ slightly improve performance.")
645 endif(DBUS_DISABLE_CHECKS)
646
647 foreach(_note ${FOOTNOTES})
648     message(${_note})
649 endforeach()
650
651 MESSAGE(" ")
652
653 INCLUDE(modules/CPackInstallConfig.cmake)
654
655 add_custom_target(help-options
656     cmake -LH 
657     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
658 )
659
660 #
661 # create pkgconfig file
662 #
663 if(UNIX)
664     set(PLATFORM_LIBS pthread ${LIBRT})
665     include(FindPkgConfig QUIET)
666     if(PKG_CONFIG_FOUND)
667         # convert lists of link libraries into -lstdc++ -lm etc..
668         foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
669             set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}")
670         endforeach()
671         set(original_prefix "${CMAKE_INSTALL_PREFIX}")
672         if(DBUS_RELOCATABLE)
673             set(pkgconfig_prefix "\${pcfiledir}/../../")
674         else()
675             set(pkgconfig_prefix "\${original_prefix}")
676         endif()
677         set(exec_prefix "\${prefix}")
678         set(bindir "\${prefix}/${CMAKE_INSTALL_BINDIR}")
679         set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
680         set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
681         set(sysconfdir "\${prefix}/${CMAKE_INSTALL_SYSCONFDIR}")
682         set(datadir "\${prefix}/${CMAKE_INSTALL_DATADIR}")
683         set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATADIR}")
684         set(dbus_daemondir "\${prefix}/${CMAKE_INSTALL_BINDIR}")
685         configure_file(../dbus-1.pc.in ${CMAKE_BINARY_DIR}/dbus-1.pc @ONLY)
686         install(FILES ${CMAKE_BINARY_DIR}/dbus-1.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
687     endif()
688 endif()