4b9fbd15414f8cc05e620ac9f213956d52622fc5
[platform/upstream/dbus.git] / cmake / ConfigureChecks.cmake
1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckStructMember)
4 include(CheckTypeSize)
5
6 check_include_file(dirent.h     HAVE_DIRENT_H)  # dbus-sysdeps-util.c
7 check_include_file(io.h         HAVE_IO_H)      # internal
8 check_include_file(grp.h        HAVE_GRP_H)     # dbus-sysdeps-util-win.c
9 check_include_file(sys/poll.h   HAVE_POLL)      # dbus-sysdeps.c, dbus-sysdeps-win.c
10 check_include_file(sys/time.h   HAVE_SYS_TIME_H)# dbus-sysdeps-win.c
11 check_include_file(sys/wait.h   HAVE_SYS_WAIT_H)# dbus-sysdeps-win.c
12 check_include_file(time.h       HAVE_TIME_H)    # dbus-sysdeps-win.c
13 check_include_file(ws2tcpip.h   HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c
14 check_include_file(wspiapi.h    HAVE_WSPIAPI_H) # dbus-sysdeps-win.c
15 check_include_file(unistd.h     HAVE_UNISTD_H)  # dbus-sysdeps-util-win.c
16 check_include_file(stdio.h      HAVE_STDIO_H)   # dbus-sysdeps.h
17 check_include_file(sys/syslimits.h    HAVE_SYS_SYSLIMITS_H)   # dbus-sysdeps-unix.c
18 check_include_file(errno.h     HAVE_ERRNO_H)    # dbus-sysdeps.c
19 check_include_file(signal.h     HAVE_SIGNAL_H)
20 check_include_file(locale.h     HAVE_LOCALE_H)
21
22 check_symbol_exists(backtrace    "execinfo.h"       HAVE_BACKTRACE)          #  dbus-sysdeps.c, dbus-sysdeps-win.c
23 check_symbol_exists(getgrouplist "grp.h"            HAVE_GETGROUPLIST)       #  dbus-sysdeps.c
24 check_symbol_exists(getpeerucred "ucred.h"          HAVE_GETPEERUCRED)       #  dbus-sysdeps.c, dbus-sysdeps-win.c
25 check_symbol_exists(nanosleep    "time.h"           HAVE_NANOSLEEP)          #  dbus-sysdeps.c
26 check_symbol_exists(getpwnam_r   "errno.h pwd.h"    HAVE_POSIX_GETPWNAM_R)   #  dbus-sysdeps-util-unix.c
27 check_symbol_exists(setenv       "stdlib.h"         HAVE_SETENV)             #  dbus-sysdeps.c
28 check_symbol_exists(unsetenv     "stdlib.h"         HAVE_UNSETENV)           #  dbus-sysdeps.c
29 check_symbol_exists(clearenv     "stdlib.h"         HAVE_CLEARENV)           #  dbus-sysdeps.c
30 check_symbol_exists(writev       "sys/uio.h"        HAVE_WRITEV)             #  dbus-sysdeps.c, dbus-sysdeps-win.c
31 check_symbol_exists(setrlimit    "sys/resource.h"   HAVE_SETRLIMIT)          #  dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
32 check_symbol_exists(socketpair   "sys/socket.h"     HAVE_SOCKETPAIR)         #  dbus-sysdeps.c
33 check_symbol_exists(socklen_t    "sys/socket.h"     HAVE_SOCKLEN_T)          #  dbus-sysdeps-unix.c
34 check_symbol_exists(setlocale    "locale.h"         HAVE_SETLOCALE)          #  dbus-test-main.c
35 check_symbol_exists(localeconv   "locale.h"         HAVE_LOCALECONV)         #  dbus-sysdeps.c
36 check_symbol_exists(strtoll      "stdlib.h"         HAVE_STRTOLL)            #  dbus-send.c
37 check_symbol_exists(strtoull     "stdlib.h"         HAVE_STRTOULL)           #  dbus-send.c
38
39 check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED)   #  dbus-sysdeps.c
40
41 # missing:
42 # HAVE_ABSTRACT_SOCKETS
43 # DBUS_HAVE_GCC33_GCOV
44
45 check_type_size("short"     SIZEOF_SHORT)
46 check_type_size("int"       SIZEOF_INT)
47 check_type_size("long"      SIZEOF_LONG)
48 check_type_size("long long" SIZEOF_LONG_LONG)
49 check_type_size("__int64"   SIZEOF___INT64)
50
51 # DBUS_INT64_TYPE
52 if(SIZEOF_INT EQUAL 8)
53     set (DBUS_HAVE_INT64 1)
54     set (DBUS_INT64_TYPE "int")
55 else(SIZEOF_INT EQUAL 8)
56     if(SIZEOF_LONG EQUAL 8)
57         set (DBUS_HAVE_INT64 1)
58         set (DBUS_INT64_TYPE "long")
59     else(SIZEOF_LONG EQUAL 8)
60         if(SIZEOF_LONG_LONG EQUAL 8)
61             set (DBUS_HAVE_INT64 1)
62             set (DBUS_INT64_TYPE "long long")
63         else(SIZEOF_LONG_LONG EQUAL 8)
64             if(SIZEOF___INT64 EQUAL 8)
65                 set (DBUS_HAVE_INT64 1)
66                 set (DBUS_INT64_TYPE "__int64")
67             endif(SIZEOF___INT64 EQUAL 8)
68         endif(SIZEOF_LONG_LONG EQUAL 8)
69     endif(SIZEOF_LONG EQUAL 8)
70 endif(SIZEOF_INT EQUAL 8)
71
72 # DBUS_INT32_TYPE
73 if(SIZEOF_INT EQUAL 4)
74     set (DBUS_INT32_TYPE "int")
75 else(SIZEOF_INT EQUAL 4)
76     if(SIZEOF_LONG EQUAL 4)
77         set (DBUS_INT32_TYPE "long")
78     else(SIZEOF_LONG EQUAL 4)
79         if(SIZEOF_LONG_LONG EQUAL 4)
80             set (DBUS_INT32_TYPE "long long")
81         endif(SIZEOF_LONG_LONG EQUAL 4)
82     endif(SIZEOF_LONG EQUAL 4)
83 endif(SIZEOF_INT EQUAL 4)
84
85 # DBUS_INT16_TYPE
86 if(SIZEOF_INT EQUAL 2)
87     set (DBUS_INT16_TYPE "int")
88 else(SIZEOF_INT EQUAL 2)
89     if(SIZEOF_SHORT EQUAL 2)
90         set (DBUS_INT16_TYPE "short")
91     endif(SIZEOF_SHORT EQUAL 2)
92 endif(SIZEOF_INT EQUAL 2)
93
94 find_program(DOXYGEN doxygen)
95 find_program(XMLTO xmlto)
96
97 if(MSVC)
98    SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN";)
99 else(MSVC)
100 write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
101         #include <stdlib.h>
102         static void f (int i, ...) {
103         va_list args1, args2;
104         va_start (args1, i);
105         va_copy (args2, args1);
106         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
107           exit (1);
108         va_end (args1); va_end (args2);
109         }
110         int main() {
111           f (0, 42);
112           return 0;
113         }
114 ")
115 try_compile(DBUS_HAVE_VA_COPY
116             ${CMAKE_BINARY_DIR}
117             ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
118
119 if(DBUS_HAVE_VA_COPY)
120   SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function")
121 else(DBUS_HAVE_VA_COPY)
122   write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
123           #include <stdlib.h>
124           static void f (int i, ...) {
125           va_list args1, args2;
126           va_start (args1, i);
127           __va_copy (args2, args1);
128           if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
129             exit (1);
130           va_end (args1); va_end (args2);
131           }
132           int main() {
133             f (0, 42);
134             return 0;
135           }
136   ")
137   try_compile(DBUS_HAVE___VA_COPY
138               ${CMAKE_BINARY_DIR}
139               ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
140   if(DBUS_HAVE___VA_COPY)
141     SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function")
142   else(DBUS_HAVE___VA_COPY)
143     SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values")
144   endif(DBUS_HAVE___VA_COPY)
145 endif(DBUS_HAVE_VA_COPY)
146 endif(MSVC) # _not_ MSVC
147 #### Abstract sockets
148
149 if (DBUS_ENABLE_ABSTRACT_SOCKETS)
150
151   try_compile(HAVE_ABSTRACT_SOCKETS
152               ${CMAKE_BINARY_DIR}
153               ${CMAKE_SOURCE_DIR}/modules/CheckForAbstractSockets.c)
154
155 endif(DBUS_ENABLE_ABSTRACT_SOCKETS)
156
157 if(HAVE_ABSTRACT_SOCKETS)
158   set(DBUS_PATH_OR_ABSTRACT_VALUE abstract)
159 else(HAVE_ABSTRACT_SOCKETS)
160   set(DBUS_PATH_OR_ABSTRACT_VALUE path)
161 endif(HAVE_ABSTRACT_SOCKETS)
162