cmake: check for the necessary symbols for test-segfault.c
[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(unistd.h     HAVE_UNISTD_H)  # dbus-sysdeps-util-win.c
15 check_include_file(stdio.h      HAVE_STDIO_H)   # dbus-sysdeps.h
16 check_include_file(sys/syslimits.h    HAVE_SYS_SYSLIMITS_H)   # dbus-sysdeps-unix.c
17 check_include_file(errno.h     HAVE_ERRNO_H)    # dbus-sysdeps.c
18 check_include_file(signal.h     HAVE_SIGNAL_H)
19 check_include_file(locale.h     HAVE_LOCALE_H)
20 check_include_file(inttypes.h     HAVE_INTTYPES_H)   # dbus-pipe.h
21 check_include_file(stdint.h     HAVE_STDINT_H)   # dbus-pipe.h
22 check_include_file(sys/prctl.h  HAVE_SYS_PRCTL_H)
23
24 check_symbol_exists(backtrace    "execinfo.h"       HAVE_BACKTRACE)          #  dbus-sysdeps.c, dbus-sysdeps-win.c
25 check_symbol_exists(getgrouplist "grp.h"            HAVE_GETGROUPLIST)       #  dbus-sysdeps.c
26 check_symbol_exists(getpeerucred "ucred.h"          HAVE_GETPEERUCRED)       #  dbus-sysdeps.c, dbus-sysdeps-win.c
27 check_symbol_exists(nanosleep    "time.h"           HAVE_NANOSLEEP)          #  dbus-sysdeps.c
28 check_symbol_exists(getpwnam_r   "errno.h pwd.h"    HAVE_POSIX_GETPWNAM_R)   #  dbus-sysdeps-util-unix.c
29 check_symbol_exists(setenv       "stdlib.h"         HAVE_SETENV)             #  dbus-sysdeps.c
30 check_symbol_exists(unsetenv     "stdlib.h"         HAVE_UNSETENV)           #  dbus-sysdeps.c
31 check_symbol_exists(clearenv     "stdlib.h"         HAVE_CLEARENV)           #  dbus-sysdeps.c
32 check_symbol_exists(writev       "sys/uio.h"        HAVE_WRITEV)             #  dbus-sysdeps.c, dbus-sysdeps-win.c
33 check_symbol_exists(setrlimit    "sys/resource.h"   HAVE_SETRLIMIT)          #  dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
34 check_symbol_exists(socketpair   "sys/socket.h"     HAVE_SOCKETPAIR)         #  dbus-sysdeps.c
35 check_symbol_exists(socklen_t    "sys/socket.h"     HAVE_SOCKLEN_T)          #  dbus-sysdeps-unix.c
36 check_symbol_exists(setlocale    "locale.h"         HAVE_SETLOCALE)          #  dbus-test-main.c
37 check_symbol_exists(localeconv   "locale.h"         HAVE_LOCALECONV)         #  dbus-sysdeps.c
38 check_symbol_exists(strtoll      "stdlib.h"         HAVE_STRTOLL)            #  dbus-send.c
39 check_symbol_exists(strtoull     "stdlib.h"         HAVE_STRTOULL)           #  dbus-send.c
40 set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
41 check_symbol_exists(pipe2        "fcntl.h;unistd.h"         HAVE_PIPE2)
42 check_symbol_exists(accept4      "sys/socket.h"             HAVE_ACCEPT4)
43 check_symbol_exists(dirfd        "dirent.h"                 HAVE_DIRFD)
44 check_symbol_exists(inotify_init1 "sys/inotify.h"           HAVE_INOTIFY_INIT1)
45 check_symbol_exists(SCM_RIGHTS    "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING)
46 check_symbol_exists(prctl        "sys/prctl.h"              HAVE_PRCTL)
47 check_symbol_exists(raise        "signal.h"                 HAVE_RAISE)
48
49 check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED)   #  dbus-sysdeps.c
50
51 # missing:
52 # HAVE_ABSTRACT_SOCKETS
53 # DBUS_HAVE_GCC33_GCOV
54
55 check_type_size("short"     SIZEOF_SHORT)
56 check_type_size("int"       SIZEOF_INT)
57 check_type_size("long"      SIZEOF_LONG)
58 check_type_size("long long" SIZEOF_LONG_LONG)
59 check_type_size("__int64"   SIZEOF___INT64)
60
61 # DBUS_INT64_TYPE
62 if(SIZEOF_INT EQUAL 8)
63     set (DBUS_INT64_TYPE "int")
64     set (DBUS_INT64_CONSTANT  "(val)")
65     set (DBUS_UINT64_CONSTANT "(val##U)")
66 elseif(SIZEOF_LONG EQUAL 8)
67     set (DBUS_INT64_TYPE "long")
68     set (DBUS_INT64_CONSTANT  "(val##L)")
69     set (DBUS_UINT64_CONSTANT "(val##UL)")
70 elseif(SIZEOF_LONG_LONG EQUAL 8)
71     set (DBUS_INT64_TYPE "long long")
72     set (DBUS_INT64_CONSTANT  "(val##LL)")
73     set (DBUS_UINT64_CONSTANT "(val##ULL)")
74 elseif(SIZEOF___INT64 EQUAL 8)
75     set (DBUS_INT64_TYPE "__int64")
76     set (DBUS_INT64_CONSTANT  "(val##i64)")
77     set (DBUS_UINT64_CONSTANT "(val##ui64)")
78 else(SIZEOF_INT EQUAL 8)
79     message (FATAL_ERROR "Could not find a 64-bit integer type")
80 endif(SIZEOF_INT EQUAL 8)
81
82 # DBUS_INT32_TYPE
83 if(SIZEOF_INT EQUAL 4)
84     set (DBUS_INT32_TYPE "int")
85 elseif(SIZEOF_LONG EQUAL 4)
86     set (DBUS_INT32_TYPE "long")
87 elseif(SIZEOF_LONG_LONG EQUAL 4)
88     set (DBUS_INT32_TYPE "long long")
89 endif(SIZEOF_INT EQUAL 4)
90
91 # DBUS_INT16_TYPE
92 if(SIZEOF_INT EQUAL 2)
93     set (DBUS_INT16_TYPE "int")
94 elseif(SIZEOF_SHORT EQUAL 2)
95     set (DBUS_INT16_TYPE "short")
96 endif(SIZEOF_INT EQUAL 2)
97
98 find_program(DOXYGEN doxygen)
99 find_program(XMLTO xmlto)
100
101 if(MSVC)
102    SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN")
103 else(MSVC)
104 write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
105         #include <stdlib.h>
106         static void f (int i, ...) {
107         va_list args1, args2;
108         va_start (args1, i);
109         va_copy (args2, args1);
110         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
111           exit (1);
112         va_end (args1); va_end (args2);
113         }
114         int main() {
115           f (0, 42);
116           return 0;
117         }
118 ")
119 try_compile(DBUS_HAVE_VA_COPY
120             ${CMAKE_BINARY_DIR}
121             ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
122
123 if(DBUS_HAVE_VA_COPY)
124   SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function")
125 else(DBUS_HAVE_VA_COPY)
126   write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
127           #include <stdlib.h>
128           static void f (int i, ...) {
129           va_list args1, args2;
130           va_start (args1, i);
131           __va_copy (args2, args1);
132           if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
133             exit (1);
134           va_end (args1); va_end (args2);
135           }
136           int main() {
137             f (0, 42);
138             return 0;
139           }
140   ")
141   try_compile(DBUS_HAVE___VA_COPY
142               ${CMAKE_BINARY_DIR}
143               ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
144   if(DBUS_HAVE___VA_COPY)
145     SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function")
146   else(DBUS_HAVE___VA_COPY)
147     SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values")
148   endif(DBUS_HAVE___VA_COPY)
149 endif(DBUS_HAVE_VA_COPY)
150 endif(MSVC) # _not_ MSVC
151 #### Abstract sockets
152
153 if (DBUS_ENABLE_ABSTRACT_SOCKETS)
154
155   try_compile(HAVE_ABSTRACT_SOCKETS
156               ${CMAKE_BINARY_DIR}
157               ${CMAKE_SOURCE_DIR}/modules/CheckForAbstractSockets.c)
158
159 endif(DBUS_ENABLE_ABSTRACT_SOCKETS)
160
161 if(HAVE_ABSTRACT_SOCKETS)
162   set(DBUS_PATH_OR_ABSTRACT_VALUE abstract)
163 else(HAVE_ABSTRACT_SOCKETS)
164   set(DBUS_PATH_OR_ABSTRACT_VALUE path)
165 endif(HAVE_ABSTRACT_SOCKETS)
166