Debian Codegraph @

cmake/ConfigureChecks.cmake

raw
1 include(CheckIncludeFile)
2 include(CheckIncludeFiles)
3 include(CheckSymbolExists)
4 include(CheckStructMember)
5 include(CheckTypeSize)
6 include(CheckCSourceCompiles)
7 include(CheckCSourceRuns)
8
9 set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
10
11 # keep in sync with check_headers in meson.build
12 check_include_files("winsock2.h;afunix.h" HAVE_AFUNIX_H)
13 check_include_file(alloca.h HAVE_ALLOCA_H)
14 check_include_file(byteswap.h HAVE_BYTESWAP_H)
15 check_include_file(crt/externs.h HAVE_CRT_EXTERNS_H)
16 check_include_file(dirent.h HAVE_DIRENT_H) # dbus-sysdeps-util.c
17 check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c
18 check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h
19 check_include_file(io.h HAVE_IO_H) # internal
20 check_include_file(linux/close_range.h HAVE_LINUX_CLOSE_RANGE_H)
21 check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H)
22 check_include_file(locale.h HAVE_LOCALE_H)
23 check_include_file(signal.h HAVE_SIGNAL_H)
24 check_include_file(stdatomic.h HAVE_STDATOMIC_H)
25 check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h
26 check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
27 check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
28 check_include_file(sys/inotify.h DBUS_BUS_ENABLE_INOTIFY)
29 check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
30 check_include_file(sys/random.h HAVE_SYS_RANDOM_H)
31 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
32 check_include_file(sys/syscall.h HAVE_SYS_SYSCALL_H)
33 check_include_file(sys/time.h HAVE_SYS_TIME_H)# dbus-sysdeps-win.c
34 check_include_file(sys/vfs.h HAVE_SYS_VFS_H)
35 check_include_file(syslog.h HAVE_SYSLOG_H)
36 check_include_file(unistd.h HAVE_UNISTD_H) # dbus-sysdeps-util-win.c
37 check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c
38
39 find_package(Backtrace) # dbus-sysdeps.c, dbus-sysdeps-win.c
40 set(HAVE_BACKTRACE ${Backtrace_FOUND})
41
42 # keep in sync with check_functions in meson.build
43 check_symbol_exists(LOG_PERROR "syslog.h" HAVE_DECL_LOG_PERROR)
44 check_symbol_exists(MSG_NOSIGNAL "sys/socket.h" HAVE_DECL_MSG_NOSIGNAL)
45 check_symbol_exists(SCM_RIGHTS "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING)
46 check_symbol_exists(SYS_pidfd_open "sys/syscall.h" HAVE_DECL_SYS_PIDFD_OPEN) # dbus-sysdeps-unix.c
47 check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4)
48 check_symbol_exists(clearenv "stdlib.h" HAVE_CLEARENV) # dbus-sysdeps.c
49 check_symbol_exists(close_range "unistd.h" HAVE_CLOSE_RANGE) # dbus-sysdeps-unix.c
50 check_symbol_exists(closefrom "unistd.h" HAVE_CLOSEFROM) # dbus-sysdeps-unix.c
51 check_symbol_exists(environ "unistd.h" HAVE_DECL_ENVIRON)
52 check_symbol_exists(fstatfs "sys/vfs.h" HAVE_FSTATFS)
53 check_symbol_exists(getgrouplist "grp.h" HAVE_GETGROUPLIST) # dbus-sysdeps.c
54 check_symbol_exists(getpeerucred "ucred.h" HAVE_GETPEERUCRED) # dbus-sysdeps.c, dbus-sysdeps-win.c
55 check_symbol_exists(getpwnam_r "errno.h;pwd.h" HAVE_GETPWNAM_R) # dbus-sysdeps-util-unix.c
56 check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
57 check_symbol_exists(getresuid "unistd.h" HAVE_GETRESUID)
58 check_symbol_exists(getrlimit "sys/resource.h;sys/time.h" HAVE_GETRLIMIT)
59 check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1)
60 check_symbol_exists(localeconv "locale.h" HAVE_LOCALECONV) # dbus-sysdeps.c
61 check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP) # dbus-sysdeps.c
62 check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2)
63 check_symbol_exists(poll "poll.h" HAVE_POLL) # dbus-sysdeps-unix.c
64 check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL)
65 check_symbol_exists(prlimit "sys/resource.h;sys/time.h" HAVE_PRLIMIT)
66 check_symbol_exists(raise "signal.h" HAVE_RAISE)
67 check_symbol_exists(setenv "stdlib.h" HAVE_SETENV) # dbus-sysdeps.c
68 check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) # dbus-test-main.c
69 check_symbol_exists(setresuid "unistd.h" HAVE_SETRESUID)
70 check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) # dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
71 check_symbol_exists(setrlimit "sys/resource.h;sys/time.h" HAVE_SETRLIMIT)
72 check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # dbus-sysdeps.c
73 check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV) # dbus-sysdeps.c
74 check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV) # dbus-sysdeps.c, dbus-sysdeps-win.c
75
76 # It doesn't really matter which specific header we use for these, as long as
77 # we include at least one glibc-provided header. time.h is suitable.
78 check_symbol_exists(__GLIBC__ "time.h" HAVE___GLIBC__)
79 check_symbol_exists(_FILE_OFFSET_BITS "time.h" HAVE__FILE_OFFSET_BITS)
80 check_symbol_exists(_TIME_BITS "time.h" HAVE__TIME_BITS)
81
82 # Opt-in to large inode number and timestamp support, which we know doesn't
83 # break libdbus ABI: https://gitlab.freedesktop.org/dbus/dbus/-/issues/465
84 if(HAVE___GLIBC__ AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT HAVE__FILE_OFFSET_BITS)
85 set(_FILE_OFFSET_BITS 64)
86 endif()
87
88 if(HAVE___GLIBC__ AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT HAVE__TIME_BITS)
89 set(_TIME_BITS 64)
90 endif()
91
92 check_struct_member(cmsgcred cmcred_pid "sys/types.h;sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c
93
94 CHECK_C_SOURCE_COMPILES("
95 #ifndef __linux__
96 #error This is not Linux
97 #endif
98 #include <sys/epoll.h>
99 int main() {
100 epoll_create1 (EPOLL_CLOEXEC);
101 }" DBUS_HAVE_LINUX_EPOLL)
102
103 CHECK_C_SOURCE_COMPILES("
104 int main() {
105 int a = 4;
106 int b = __sync_sub_and_fetch(&a, 4);
107 return b;
108 }
109 " DBUS_USE_SYNC)
110
111 set(DBUS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
112
113 check_type_size("short" SIZEOF_SHORT)
114 check_type_size("int" SIZEOF_INT)
115 check_type_size("long" SIZEOF_LONG)
116 check_type_size("long long" SIZEOF_LONG_LONG)
117 check_type_size("__int64" SIZEOF___INT64)
118 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
119 check_type_size("socklen_t" HAVE_SOCKLEN_T) # dbus-sysdeps-unix.c
120 set(CMAKE_EXTRA_INCLUDE_FILES)
121
122 # DBUS_INT64_TYPE
123 if(SIZEOF_INT EQUAL 8)
124 set(DBUS_INT64_TYPE "int")
125 set(DBUS_INT64_CONSTANT "(val)")
126 set(DBUS_UINT64_CONSTANT "(val##U)")
127 set(DBUS_INT64_MODIFIER "")
128 elseif(SIZEOF_LONG EQUAL 8)
129 set(DBUS_INT64_TYPE "long")
130 set(DBUS_INT64_CONSTANT "(val##L)")
131 set(DBUS_UINT64_CONSTANT "(val##UL)")
132 set(DBUS_INT64_MODIFIER "l")
133 elseif(SIZEOF_LONG_LONG EQUAL 8)
134 set(DBUS_INT64_TYPE "long long")
135 set(DBUS_INT64_CONSTANT "(val##LL)")
136 set(DBUS_UINT64_CONSTANT "(val##ULL)")
137 set(DBUS_INT64_MODIFIER "ll")
138 elseif(SIZEOF___INT64 EQUAL 8)
139 set(DBUS_INT64_TYPE "__int64")
140 set(DBUS_INT64_CONSTANT "(val##i64)")
141 set(DBUS_UINT64_CONSTANT "(val##ui64)")
142 set(DBUS_INT64_MODIFIER "I64")
143 else(SIZEOF_INT EQUAL 8)
144 message(FATAL_ERROR "Could not find a 64-bit integer type")
145 endif()
146
147 # MSVCRT.dll printf() doesn't support %lld
148 if(WIN32 AND NOT CYGWIN)
149 set(DBUS_INT64_MODIFIER "I64")
150 endif()
151
152 # DBUS_INT32_TYPE
153 if(SIZEOF_INT EQUAL 4)
154 set(DBUS_INT32_TYPE "int")
155 elseif(SIZEOF_LONG EQUAL 4)
156 set(DBUS_INT32_TYPE "long")
157 elseif(SIZEOF_LONG_LONG EQUAL 4)
158 set(DBUS_INT32_TYPE "long long")
159 endif()
160
161 # DBUS_INT16_TYPE
162 if(SIZEOF_INT EQUAL 2)
163 set(DBUS_INT16_TYPE "int")
164 elseif(SIZEOF_SHORT EQUAL 2)
165 set(DBUS_INT16_TYPE "short")
166 endif()
167
168 find_program(DOXYGEN doxygen)
169 find_program(XMLTO xmlto)