test/dbus-daemon: Exercise the Peer interface
[platform/upstream/dbus.git] / cmake / ConfigureChecks.cmake
1 include(CheckIncludeFile)
2 include(CheckIncludeFiles)
3 include(CheckSymbolExists)
4 include(CheckStructMember)
5 include(CheckTypeSize)
6
7 check_include_file(alloca.h     HAVE_ALLOCA_H)
8 check_include_file(byteswap.h     HAVE_BYTESWAP_H)
9 check_include_file(crt/externs.h     HAVE_CRT_EXTERNS_H)
10 check_include_file(dirent.h     HAVE_DIRENT_H)  # dbus-sysdeps-util.c
11 check_include_file(dlfcn.h     HAVE_DLFCN_H)
12 check_include_file(execinfo.h     HAVE_EXECINFO_H)
13 check_include_file(errno.h     HAVE_ERRNO_H)    # dbus-sysdeps.c
14 check_include_file(expat.h     HAVE_EXPAT_H)
15 check_include_file(grp.h        HAVE_GRP_H)     # dbus-sysdeps-util-win.c
16 check_include_file(inttypes.h     HAVE_INTTYPES_H)   # dbus-pipe.h
17 check_include_file(io.h         HAVE_IO_H)      # internal
18 check_include_file(locale.h     HAVE_LOCALE_H)
19 check_include_file(memory.h     HAVE_MEMORY_H)
20 check_include_file(signal.h     HAVE_SIGNAL_H)
21 check_include_file(stdint.h     HAVE_STDINT_H)   # dbus-pipe.h
22 check_include_file(stdlib.h     HAVE_STDLIB_H)
23 check_include_file(stdio.h      HAVE_STDIO_H)   # dbus-sysdeps.h
24 check_include_file(string.h     HAVE_STRING_H)
25 check_include_file(strings.h     HAVE_STRINGS_H)
26 check_include_file(syslog.h     HAVE_SYSLOG_H)
27 check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
28 check_include_file(sys/inotify.h     HAVE_SYS_INOTIFY_H)
29 check_include_file(sys/resource.h     HAVE_SYS_RESOURCE_H)
30 check_include_file(sys/stat.h     HAVE_SYS_STAT_H)
31 check_include_file(sys/types.h     HAVE_SYS_TYPES_H)
32 check_include_file(sys/uio.h     HAVE_SYS_UIO_H)
33 check_include_file(sys/poll.h   HAVE_POLL)      # dbus-sysdeps.c, dbus-sysdeps-win.c
34 check_include_file(sys/prctl.h  HAVE_SYS_PRCTL_H)
35 check_include_file(sys/syslimits.h    HAVE_SYS_SYSLIMITS_H)   # dbus-sysdeps-unix.c
36 check_include_file(sys/time.h   HAVE_SYS_TIME_H)# dbus-sysdeps-win.c
37 check_include_file(sys/wait.h   HAVE_SYS_WAIT_H)# dbus-sysdeps-win.c
38 check_include_file(time.h       HAVE_TIME_H)    # dbus-sysdeps-win.c
39 check_include_file(ws2tcpip.h   HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c
40 check_include_file(unistd.h     HAVE_UNISTD_H)  # dbus-sysdeps-util-win.c
41
42 check_symbol_exists(backtrace    "execinfo.h"       HAVE_BACKTRACE)          #  dbus-sysdeps.c, dbus-sysdeps-win.c
43 check_symbol_exists(getgrouplist "grp.h"            HAVE_GETGROUPLIST)       #  dbus-sysdeps.c
44 check_symbol_exists(getpeerucred "ucred.h"          HAVE_GETPEERUCRED)       #  dbus-sysdeps.c, dbus-sysdeps-win.c
45 check_symbol_exists(nanosleep    "time.h"           HAVE_NANOSLEEP)          #  dbus-sysdeps.c
46 check_symbol_exists(getpwnam_r   "errno.h pwd.h"    HAVE_POSIX_GETPWNAM_R)   #  dbus-sysdeps-util-unix.c
47 check_symbol_exists(setenv       "stdlib.h"         HAVE_SETENV)             #  dbus-sysdeps.c
48 check_symbol_exists(unsetenv     "stdlib.h"         HAVE_UNSETENV)           #  dbus-sysdeps.c
49 check_symbol_exists(clearenv     "stdlib.h"         HAVE_CLEARENV)           #  dbus-sysdeps.c
50 check_symbol_exists(writev       "sys/uio.h"        HAVE_WRITEV)             #  dbus-sysdeps.c, dbus-sysdeps-win.c
51 check_symbol_exists(setrlimit    "sys/resource.h"   HAVE_SETRLIMIT)          #  dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
52 check_symbol_exists(socketpair   "sys/socket.h"     HAVE_SOCKETPAIR)         #  dbus-sysdeps.c
53 check_symbol_exists(setlocale    "locale.h"         HAVE_SETLOCALE)          #  dbus-test-main.c
54 check_symbol_exists(localeconv   "locale.h"         HAVE_LOCALECONV)         #  dbus-sysdeps.c
55 check_symbol_exists(strtoll      "stdlib.h"         HAVE_STRTOLL)            #  dbus-send.c
56 check_symbol_exists(strtoull     "stdlib.h"         HAVE_STRTOULL)           #  dbus-send.c
57 set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
58 check_symbol_exists(pipe2        "fcntl.h;unistd.h"         HAVE_PIPE2)
59 check_symbol_exists(accept4      "sys/socket.h"             HAVE_ACCEPT4)
60 check_symbol_exists(dirfd        "dirent.h"                 HAVE_DIRFD)
61 check_symbol_exists(inotify_init1 "sys/inotify.h"           HAVE_INOTIFY_INIT1)
62 check_symbol_exists(SCM_RIGHTS    "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING)
63 check_symbol_exists(prctl        "sys/prctl.h"              HAVE_PRCTL)
64 check_symbol_exists(raise        "signal.h"                 HAVE_RAISE)
65
66 check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED)   #  dbus-sysdeps.c
67
68 # missing:
69 # HAVE_ABSTRACT_SOCKETS
70 # DBUS_HAVE_GCC33_GCOV
71
72 check_type_size("short"     SIZEOF_SHORT)
73 check_type_size("int"       SIZEOF_INT)
74 check_type_size("long"      SIZEOF_LONG)
75 check_type_size("long long" SIZEOF_LONG_LONG)
76 check_type_size("__int64"   SIZEOF___INT64)
77 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
78 check_type_size("socklen_t" SOCKLEN_T)          #  dbus-sysdeps-unix.c
79 set(CMAKE_EXTRA_INCLUDE_FILES)
80
81 # DBUS_INT64_TYPE
82 if(SIZEOF_INT EQUAL 8)
83     set (DBUS_INT64_TYPE "int")
84     set (DBUS_INT64_CONSTANT  "(val)")
85     set (DBUS_UINT64_CONSTANT "(val##U)")
86 elseif(SIZEOF_LONG EQUAL 8)
87     set (DBUS_INT64_TYPE "long")
88     set (DBUS_INT64_CONSTANT  "(val##L)")
89     set (DBUS_UINT64_CONSTANT "(val##UL)")
90 elseif(SIZEOF_LONG_LONG EQUAL 8)
91     set (DBUS_INT64_TYPE "long long")
92     set (DBUS_INT64_CONSTANT  "(val##LL)")
93     set (DBUS_UINT64_CONSTANT "(val##ULL)")
94 elseif(SIZEOF___INT64 EQUAL 8)
95     set (DBUS_INT64_TYPE "__int64")
96     set (DBUS_INT64_CONSTANT  "(val##i64)")
97     set (DBUS_UINT64_CONSTANT "(val##ui64)")
98 else(SIZEOF_INT EQUAL 8)
99     message (FATAL_ERROR "Could not find a 64-bit integer type")
100 endif(SIZEOF_INT EQUAL 8)
101
102 # DBUS_INT32_TYPE
103 if(SIZEOF_INT EQUAL 4)
104     set (DBUS_INT32_TYPE "int")
105 elseif(SIZEOF_LONG EQUAL 4)
106     set (DBUS_INT32_TYPE "long")
107 elseif(SIZEOF_LONG_LONG EQUAL 4)
108     set (DBUS_INT32_TYPE "long long")
109 endif(SIZEOF_INT EQUAL 4)
110
111 # DBUS_INT16_TYPE
112 if(SIZEOF_INT EQUAL 2)
113     set (DBUS_INT16_TYPE "int")
114 elseif(SIZEOF_SHORT EQUAL 2)
115     set (DBUS_INT16_TYPE "short")
116 endif(SIZEOF_INT EQUAL 2)
117
118 find_program(DOXYGEN doxygen)
119 find_program(XMLTO xmlto)
120
121 if(MSVC)
122    SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN")
123 else(MSVC)
124 write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
125         #include <stdlib.h>
126         static void f (int i, ...) {
127         va_list args1, args2;
128         va_start (args1, i);
129         va_copy (args2, args1);
130         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
131           exit (1);
132         va_end (args1); va_end (args2);
133         }
134         int main() {
135           f (0, 42);
136           return 0;
137         }
138 ")
139 try_compile(DBUS_HAVE_VA_COPY
140             ${CMAKE_BINARY_DIR}
141             ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
142
143 if(DBUS_HAVE_VA_COPY)
144   SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function")
145 else(DBUS_HAVE_VA_COPY)
146   write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
147           #include <stdlib.h>
148           static void f (int i, ...) {
149           va_list args1, args2;
150           va_start (args1, i);
151           __va_copy (args2, args1);
152           if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
153             exit (1);
154           va_end (args1); va_end (args2);
155           }
156           int main() {
157             f (0, 42);
158             return 0;
159           }
160   ")
161   try_compile(DBUS_HAVE___VA_COPY
162               ${CMAKE_BINARY_DIR}
163               ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
164   if(DBUS_HAVE___VA_COPY)
165     SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function")
166   else(DBUS_HAVE___VA_COPY)
167     SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values")
168   endif(DBUS_HAVE___VA_COPY)
169 endif(DBUS_HAVE_VA_COPY)
170 endif(MSVC) # _not_ MSVC
171 #### Abstract sockets
172
173 if (DBUS_ENABLE_ABSTRACT_SOCKETS)
174
175   try_compile(HAVE_ABSTRACT_SOCKETS
176               ${CMAKE_BINARY_DIR}
177               ${CMAKE_SOURCE_DIR}/modules/CheckForAbstractSockets.c)
178
179 endif(DBUS_ENABLE_ABSTRACT_SOCKETS)
180
181 if(HAVE_ABSTRACT_SOCKETS)
182   set(DBUS_PATH_OR_ABSTRACT_VALUE abstract)
183 else(HAVE_ABSTRACT_SOCKETS)
184   set(DBUS_PATH_OR_ABSTRACT_VALUE path)
185 endif(HAVE_ABSTRACT_SOCKETS)
186