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