c44ea7ae7e7b4ffb87fe1cf03e79c53f49253903
[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(wspiapi.h    HAVE_WSPIAPI_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
19 check_symbol_exists(backtrace    "execinfo.h"       HAVE_BACKTRACE)          #  dbus-sysdeps.c, dbus-sysdeps-win.c
20 check_symbol_exists(getgrouplist "grp.h"            HAVE_GETGROUPLIST)       #  dbus-sysdeps.c
21 check_symbol_exists(getpeerucred "ucred.h"          HAVE_GETPEERUCRED)       #  dbus-sysdeps.c, dbus-sysdeps-win.c
22 check_symbol_exists(nanosleep    "time.h"           HAVE_NANOSLEEP)          #  dbus-sysdeps.c
23 check_symbol_exists(getpwnam_r   "errno.h pwd.h"    HAVE_POSIX_GETPWNAM_R)   #  dbus-sysdeps-util-unix.c
24 check_symbol_exists(setenv       "stdlib.h"         HAVE_SETENV)             #  dbus-sysdeps.c
25 check_symbol_exists(socketpair   "sys/socket.h"     HAVE_SOCKETPAIR)         #  dbus-sysdeps.c
26 check_symbol_exists(unsetenv     "stdlib.h"         HAVE_UNSETENV)           #  dbus-sysdeps.c
27 check_symbol_exists(writev       "sys/uio.h"        HAVE_WRITEV)             #  dbus-sysdeps.c, dbus-sysdeps-win.c
28 check_symbol_exists(setrlimit    "sys/resource.h"   HAVE_SETRLIMIT)          #  dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
29 check_symbol_exists(socklen_t    "sys/socket.h"     HAVE_SOCKLEN_T)          #  dbus-sysdeps-unix.c
30
31 check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED)   #  dbus-sysdeps.c
32
33 # missing:
34 # HAVE_ABSTRACT_SOCKETS
35 # DBUS_HAVE_GCC33_GCOV
36
37 check_type_size("short"     SIZEOF_SHORT)
38 check_type_size("int"       SIZEOF_INT)
39 check_type_size("long"      SIZEOF_LONG)
40 check_type_size("long long" SIZEOF_LONG_LONG)
41 check_type_size("__int64"   SIZEOF___INT64)
42
43 # DBUS_INT64_TYPE
44 if(SIZEOF_INT EQUAL 8)
45     set (DBUS_HAVE_INT64 1)
46     set (DBUS_INT64_TYPE "int")
47 else(SIZEOF_INT EQUAL 8)
48     if(SIZEOF_LONG EQUAL 8)
49         set (DBUS_HAVE_INT64 1)
50         set (DBUS_INT64_TYPE "long")
51     else(SIZEOF_LONG EQUAL 8)
52         if(SIZEOF_LONG_LONG EQUAL 8)
53             set (DBUS_HAVE_INT64 1)
54             set (DBUS_INT64_TYPE "long long")
55         else(SIZEOF_LONG_LONG EQUAL 8)
56             if(SIZEOF___INT64 EQUAL 8)
57                 set (DBUS_HAVE_INT64 1)
58                 set (DBUS_INT64_TYPE "__int64")
59             endif(SIZEOF___INT64 EQUAL 8)
60         endif(SIZEOF_LONG_LONG EQUAL 8)
61     endif(SIZEOF_LONG EQUAL 8)
62 endif(SIZEOF_INT EQUAL 8)
63
64 # DBUS_INT32_TYPE
65 if(SIZEOF_INT EQUAL 4)
66     set (DBUS_INT32_TYPE "int")
67 else(SIZEOF_INT EQUAL 4)
68     if(SIZEOF_LONG EQUAL 4)
69         set (DBUS_INT32_TYPE "long")
70     else(SIZEOF_LONG EQUAL 4)
71         if(SIZEOF_LONG_LONG EQUAL 4)
72             set (DBUS_INT32_TYPE "long long")
73         endif(SIZEOF_LONG_LONG EQUAL 4)
74     endif(SIZEOF_LONG EQUAL 4)
75 endif(SIZEOF_INT EQUAL 4)
76
77 # DBUS_INT16_TYPE
78 if(SIZEOF_INT EQUAL 2)
79     set (DBUS_INT16_TYPE "int")
80 else(SIZEOF_INT EQUAL 2)
81     if(SIZEOF_SHORT EQUAL 2)
82         set (DBUS_INT16_TYPE "short")
83     endif(SIZEOF_SHORT EQUAL 2)
84 endif(SIZEOF_INT EQUAL 2)
85
86 find_program(DOXYGEN doxygen)
87 find_program(XMLTO xmlto)
88
89 write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
90         void f (int i, ...) {
91         va_list args1, args2;
92         va_start (args1, i);
93         va_copy (args2, args1);
94         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
95           exit (1);
96         va_end (args1); va_end (args2);
97         }
98         int main() {
99           f (0, 42);
100           return 0;
101         }
102 ")
103 try_compile(DBUS_HAVE_VA_COPY
104             ${CMAKE_BINARY_DIR}
105             ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
106
107 if(DBUS_HAVE_VA_COPY)
108   SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function")
109 else(DBUS_HAVE_VA_COPY)
110   write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
111           void f (int i, ...) {
112           va_list args1, args2;
113           va_start (args1, i);
114           __va_copy (args2, args1);
115           if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
116             exit (1);
117           va_end (args1); va_end (args2);
118           }
119           int main() {
120             f (0, 42);
121             return 0;
122           }
123   ")
124   try_compile(DBUS_HAVE___VA_COPY
125               ${CMAKE_BINARY_DIR}
126               ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c)
127   if(DBUS_HAVE___VA_COPY)
128     SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function")
129   else(DBUS_HAVE___VA_COPY)
130     SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values")
131   endif(DBUS_HAVE___VA_COPY)
132 endif(DBUS_HAVE_VA_COPY)