"Fossies" - the Fresh Open Source Software Archive

Member "dbus-1.13.18/CMakeLists.txt" (1 Jul 2020, 29765 Bytes) of package /linux/misc/dbus-1.13.18.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "CMakeLists.txt": 1.13.16_vs_1.13.18.

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