bus/policy: separate prefix rules in default context
[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 3.0.2 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 string(TIMESTAMP DBUS_BUILD_TIMESTAMP "%Y%m%d%H%M" UTC)
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         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 # all missing or hardcoded for now
367
368 # 'hidden' ones
369 set(atomic_int OFF)
370 set(atomic_int486 OFF)
371 if(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI)
372     FIND_PROGRAM(UNAME_EXECUTABLE
373                     NAMES uname
374                     PATHS /bin /usr/bin /usr/local/bin c:/Programme/MSys/bin d:/Programme/MSys/bin)
375
376     if(UNAME_EXECUTABLE)
377         EXECUTE_PROCESS(COMMAND ${UNAME_EXECUTABLE} "-m"
378                         OUTPUT_VARIABLE UNAME_OUTPUT)
379
380         if("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
381             set(atomic_int ON)
382         else("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
383             if("UNAME_OUTPUT" MATCHES "^.*i?86.*$")
384                 set(atomic_int ON)
385                 set(atomic_int_486 ON)
386             endif("UNAME_OUTPUT" MATCHES "^.*i?86.*$")
387         endif("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$")
388     endif(UNAME_EXECUTABLE)
389 endif(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI)
390
391 if(X11_FOUND)
392   option (DBUS_BUILD_X11 "Build with X11 autolaunch support " ON)
393 endif(X11_FOUND)
394
395 # test binary names
396 if (WIN32)
397     # follow Automake's naming convention so we can share .in files
398     set (EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
399 endif(WIN32)
400
401 if (MSVC_IDE)
402     if(CMAKE_BUILD_TYPE MATCHES Debug)
403                 set(IDE_BIN /Debug )
404                 message(STATUS)
405                 message(STATUS "Visual Studio: test programs will only work with 'Debug' configuration!")
406                 message(STATUS "To run tests with 'Release' configuration use -DCMAKE_BUILD_TYPE=Release")
407                 message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs")
408                 message(STATUS)
409     else(CMAKE_BUILD_TYPE MATCHES Debug)
410                 set(IDE_BIN /Release)
411                 message(STATUS)
412                 message(STATUS "Visual Studio: test programs will only work with 'Release' configuration!")
413                 message(STATUS "To run tests with 'Debug' configuration use -DCMAKE_BUILD_TYPE=Debug")
414                 message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs")
415                 message(STATUS)
416     endif(CMAKE_BUILD_TYPE MATCHES Debug)
417         set (TEST_PATH_FORCE FORCE)
418         FILE(REMOVE ${CMAKE_BINARY_DIR}/data/dbus-1/services)
419 endif (MSVC_IDE)
420
421 #### Find socket directories
422 if(UNIX)
423     if(NOT $ENV{TMPDIR} STREQUAL "")
424         set(DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR})
425     elseif(NOT $ENV{TEMP} STREQUAL "")
426         set(DBUS_SESSION_SOCKET_DIR $ENV{TEMP})
427     elseif(NOT $ENV{TMP} STREQUAL "")
428         set(DBUS_SESSION_SOCKET_DIR $ENV{TMP})
429     else()
430         set(DBUS_SESSION_SOCKET_DIR /tmp)
431     endif()
432 endif()
433
434  # Not used on Windows, where there is no system bus
435 set (DBUS_SYSTEM_PID_FILE ${DBUS_RUNSTATEDIR}/dbus/pid)
436
437 set (DBUS_CONSOLE_AUTH_DIR "" CACHE STRING "Directory to check for pam_console/pam_foreground flag files, or empty to ignore")
438
439 # This won't work on Windows. It's not meant to - the system bus is
440 # meaningless on Windows anyway.
441 #
442 # This has to be suitable for hard-coding in client libraries as well as
443 # in the dbus-daemon's configuration, so it has to be valid to listen on
444 # and also to connect to. If this ever changes, it'll need to be split into
445 # two variables, one for the listening address and one for the connecting
446 # address.
447 set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=${DBUS_RUNSTATEDIR}/dbus/system_bus_socket" CACHE STRING "system bus default address")
448
449 if (WIN32)
450   set (DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address")
451   set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
452
453   set (DBUS_SYSTEM_CONFIG_FILE "share/dbus-1/system.conf")
454   set (DBUS_SESSION_CONFIG_FILE "share/dbus-1/session.conf")
455   # bus-test expects a non empty string
456   set (DBUS_USER "Administrator")
457   set (DBUS_TEST_USER "guest")
458   set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<!--<auth>EXTERNAL</auth>-->")
459 else (WIN32)
460   set (DBUS_SESSION_BUS_LISTEN_ADDRESS "unix:tmpdir=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default listening address")
461   set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
462   set (sysconfdir "")
463   set (configdir ${sysconfdir}/dbus-1 )
464   set (DBUS_SYSTEM_CONFIG_FILE  ${configdir}/system.conf)
465   set (DBUS_SESSION_CONFIG_FILE ${configdir}/session.conf)
466   set (DBUS_USER "messagebus")
467   set (DBUS_TEST_USER "nobody")
468   # For best security, assume that all non-Windows platforms can do
469   # credentials-passing.
470   set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<auth>EXTERNAL</auth>")
471 endif (WIN32)
472
473 set (DBUS_DAEMON_NAME "dbus-daemon" CACHE STRING "The name of the dbus daemon executable")
474
475 ########### create config.h ###############
476
477 #include(ConfigureChecks.cmake)
478
479 # better use flags for gcc
480 if (MINGW)
481         set (HAVE_GNUC_VARARGS 1)
482 endif(MINGW)
483
484 # compiler definitions
485 add_definitions(-DHAVE_CONFIG_H=1)
486 add_definitions(${DBUS_BUS_CFLAGS})
487
488
489 if (DBUS_BUILD_TESTS)
490     # set variables used for the .in files (substituted by configure_file) in test/data:
491     set(DBUS_TEST_EXEC ${EXECUTABLE_OUTPUT_PATH}${IDE_BIN})
492     set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data)
493     set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test)
494     if (UNIX)
495         set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR})
496         set(TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}")
497     endif()
498     if (WIN32)
499         set (TEST_LISTEN "tcp:host=localhost")
500     endif (WIN32)
501 endif  (DBUS_BUILD_TESTS)
502
503 set(DBUS_LIBRARIES dbus-1)
504 set(DBUS_INTERNAL_LIBRARIES dbus-internal)
505
506 set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC)
507 set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_COMPILATION")
508
509 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
510
511 if (WIN32)
512 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus-env.bat.cmake ${CMAKE_BINARY_DIR}/bin/dbus-env.bat )
513     install(FILES ${CMAKE_BINARY_DIR}/bin/dbus-env.bat DESTINATION bin)
514 endif()
515
516 add_definitions(-DHAVE_CONFIG_H=1)
517
518 #
519 # create cmake find_package related files
520 #
521 set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/DBus1)
522 if(WIN32)
523    configure_file(DBus1Config.cmake.in "${CMAKE_BINARY_DIR}/DBus1Config.cmake" @ONLY)
524 else()
525    configure_file(DBus1Config.pkgconfig.in "${CMAKE_BINARY_DIR}/DBus1Config.cmake" @ONLY)
526 endif()
527 configure_file(DBus1ConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake" @ONLY)
528 install(FILES
529     "${CMAKE_BINARY_DIR}/DBus1Config.cmake"
530     "${CMAKE_BINARY_DIR}/DBus1ConfigVersion.cmake"
531     DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev
532 )
533
534 if(WIN32)
535     install(EXPORT DBus1Targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
536 endif()
537
538 ########### subdirs ###############
539
540 add_subdirectory( dbus )
541 add_subdirectory( bus )
542 if (DBUS_BUILD_TESTS)
543         add_subdirectory( test )
544         add_custom_target(check
545                 COMMAND ctest -R ^test-.*
546         )
547 endif (DBUS_BUILD_TESTS)
548 add_subdirectory( tools )
549 add_subdirectory( doc )
550
551
552 OPTION(DBUS_INSTALL_SYSTEM_LIBS "install required system libraries" OFF)
553 MESSAGE(" ")
554 MESSAGE("set -DDBUS_INSTALL_SYSTEM_LIBS=1 to install runtime libraries too")
555 MESSAGE("set DBUSDIR (environment or cmake option) to overwrite the default install directory ")
556 MESSAGE(" ")
557 MESSAGE(" ")
558 GET_FILENAME_COMPONENT(C_COMPILER ${CMAKE_C_COMPILER} NAME)
559 GET_FILENAME_COMPONENT(CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME)
560
561 message("                  D-BUS ${DBUS_VERSION}                               ")
562 message("                  =============                                       ")
563 message("                                                                      ")
564 message("        install prefix:           ${prefix}                           ")
565 message("        install exec_prefix:      ${exec_prefix}                      ")
566 message("        install libdir:           ${CMAKE_INSTALL_FULL_LIBDIR}        ")
567 message("        install bindir:           ${CMAKE_INSTALL_FULL_BINDIR}        ")
568 message("        install sysconfdir:       ${CMAKE_INSTALL_FULL_SYSCONFDIR}    ")
569 message("        install datadir:          ${CMAKE_INSTALL_FULL_DATADIR}       ")
570 message("        source code location:     ${DBUS_SOURCE_DIR}                  ")
571 message("        build dir:                ${CMAKE_BINARY_DIR}                 ")
572 message("        c compiler:               ${C_COMPILER}                       ")
573 message("        cflags:                   ${CMAKE_C_FLAGS}                    ")
574 message("        cflags debug:             ${CMAKE_C_FLAGS_DEBUG}              ")
575 message("        cflags release:           ${CMAKE_C_FLAGS_RELEASE}            ")
576 message("        cxx compiler:             ${CXX_COMPILER}                     ")
577 message("        cxxflags:                 ${CMAKE_CXX_FLAGS}                  ")
578 message("        cxxflags debug:           ${CMAKE_CXX_FLAGS_DEBUG}            ")
579 message("        cxxflags release:         ${CMAKE_CXX_FLAGS_RELEASE}          ")
580 message("        64-bit int:               ${DBUS_INT64_TYPE}                  ")
581 message("        32-bit int:               ${DBUS_INT32_TYPE}                  ")
582 message("        16-bit int:               ${DBUS_INT16_TYPE}                  ")
583 message("        Doxygen:                  ${DOXYGEN}                          ")
584 message("        Docbook Generator:        ${DOCBOOK_GENERATOR_NAME}           ")
585
586
587 message("        gcc coverage profiling:   ${DBUS_GCOV_ENABLED}                ")
588 message("        Building unit tests:      ${DBUS_BUILD_TESTS}                 ")
589 message("        Building with GLib:       ${DBUS_WITH_GLIB}                   ")
590 message("        Building verbose mode:    ${DBUS_ENABLE_VERBOSE_MODE}         ")
591 message("        Building w/o assertions:  ${DBUS_DISABLE_ASSERT}              ")
592 message("        Building w/o checks:      ${DBUS_DISABLE_CHECKS}              ")
593 message("        Building bus stats API:   ${DBUS_ENABLE_STATS}                ")
594 message("        installing system libs:   ${DBUS_INSTALL_SYSTEM_LIBS}         ")
595 message("        Building inotify support: ${DBUS_BUS_ENABLE_INOTIFY}          ")
596 message("        Building kqueue support:  ${DBUS_BUS_ENABLE_KQUEUE}           ")
597 message("        Building Doxygen docs:    ${DBUS_ENABLE_DOXYGEN_DOCS}         ")
598 message("        Building XML docs:        ${DBUS_ENABLE_XML_DOCS}             ")
599 message("        Daemon executable name:   ${DBUS_DAEMON_NAME}")
600 if(WIN32)
601 message("        Session bus listens on:   ${DBUS_SESSION_BUS_LISTEN_ADDRESS}  ")
602 message("        Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} ")
603 else()
604 message("        System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
605 message("        System bus socket:        ${DBUS_SYSTEM_SOCKET}               ")
606 message("        System bus PID file:      ${DBUS_SYSTEM_PID_FILE}             ")
607 message("        System bus user:          ${DBUS_USER}                        ")
608 message("        Session bus socket dir:   ${DBUS_SESSION_SOCKET_DIR}          ")
609
610 if(DBUS_CONSOLE_AUTH_DIR)
611 message("        pam_console auth dir:     ${DBUS_CONSOLE_AUTH_DIR}            ")
612 else()
613 message("        pam_console auth dir:     (none)                              ")
614 endif()
615
616 message("        'make check' socket dir:  ${TEST_SOCKET_DIR}                  ")
617 endif()
618 message("        Test listen address:      ${TEST_LISTEN}                      ")
619 if (MSVC)
620 message("        build timestamp:          ${DBUS_BUILD_TIMESTAMP}             ")
621 endif (MSVC)
622
623 MESSAGE(" ")
624 if (DBUS_BUILD_TESTS)
625     message("NOTE: building with unit tests increases the size of the installed library and renders it insecure.")
626 endif(DBUS_BUILD_TESTS)
627
628 if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
629     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)")
630 endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
631
632 if (DBUS_GCOV_ENABLED)
633     message("NOTE: building with coverage profiling is definitely for developers only.")
634 endif(DBUS_GCOV_ENABLED)
635
636 if (DBUS_ENABLE_VERBOSE_MODE)
637     message("NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance.")
638 endif(DBUS_ENABLE_VERBOSE_MODE)
639
640 if(NOT DBUS_DISABLE_ASSERT)
641     message("NOTE: building with assertions increases library size and decreases performance.")
642 endif(NOT DBUS_DISABLE_ASSERT)
643
644 if (DBUS_DISABLE_CHECKS)
645     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.")
646 endif(DBUS_DISABLE_CHECKS)
647
648 foreach(_note ${FOOTNOTES})
649     message(${_note})
650 endforeach()
651
652 MESSAGE(" ")
653
654 INCLUDE(modules/CPackInstallConfig.cmake)
655
656 add_custom_target(help-options
657     cmake -LH 
658     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
659 )
660
661 #
662 # create pkgconfig file
663 #
664 if(UNIX)
665     set(PLATFORM_LIBS pthread ${LIBRT})
666     include(FindPkgConfig QUIET)
667     if(PKG_CONFIG_FOUND)
668         # convert lists of link libraries into -lstdc++ -lm etc..
669         foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
670             set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}")
671         endforeach()
672         set(original_prefix "${CMAKE_INSTALL_PREFIX}")
673         if(DBUS_RELOCATABLE)
674             set(pkgconfig_prefix "\${pcfiledir}/../../")
675         else()
676             set(pkgconfig_prefix "\${original_prefix}")
677         endif()
678         set(exec_prefix "\${prefix}")
679         set(bindir "\${prefix}/${CMAKE_INSTALL_BINDIR}")
680         set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
681         set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
682         set(sysconfdir "\${prefix}/${CMAKE_INSTALL_SYSCONFDIR}")
683         set(datadir "\${prefix}/${CMAKE_INSTALL_DATADIR}")
684         set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATADIR}")
685         set(dbus_daemondir "\${prefix}/${CMAKE_INSTALL_BINDIR}")
686         configure_file(../dbus-1.pc.in ${CMAKE_BINARY_DIR}/dbus-1.pc @ONLY)
687         install(FILES ${CMAKE_BINARY_DIR}/dbus-1.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
688     endif()
689 endif()