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