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