2007-03-03 14:32:17 +00:00
|
|
|
include(CheckIncludeFile)
|
2015-03-05 14:43:26 +01:00
|
|
|
include(CheckIncludeFiles)
|
2007-03-03 14:32:17 +00:00
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
include(CheckStructMember)
|
|
|
|
|
include(CheckTypeSize)
|
2018-10-20 22:22:20 +02:00
|
|
|
include(CheckCSourceCompiles)
|
2018-10-25 20:14:24 +02:00
|
|
|
include(CheckCSourceRuns)
|
2007-03-03 14:32:17 +00:00
|
|
|
|
2023-06-06 13:33:00 +01:00
|
|
|
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
|
|
|
|
|
2023-08-07 15:46:52 +02:00
|
|
|
# keep in sync with check_headers in meson.build
|
2022-02-09 14:48:43 +04:00
|
|
|
check_include_files("winsock2.h;afunix.h" HAVE_AFUNIX_H)
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(alloca.h HAVE_ALLOCA_H)
|
|
|
|
|
check_include_file(byteswap.h HAVE_BYTESWAP_H)
|
|
|
|
|
check_include_file(crt/externs.h HAVE_CRT_EXTERNS_H)
|
2007-03-03 14:32:17 +00:00
|
|
|
check_include_file(dirent.h HAVE_DIRENT_H) # dbus-sysdeps-util.c
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c
|
|
|
|
|
check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h
|
|
|
|
|
check_include_file(io.h HAVE_IO_H) # internal
|
2022-03-02 13:08:46 +00:00
|
|
|
check_include_file(linux/close_range.h HAVE_LINUX_CLOSE_RANGE_H)
|
2023-03-20 01:40:20 +00:00
|
|
|
check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H)
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(locale.h HAVE_LOCALE_H)
|
|
|
|
|
check_include_file(signal.h HAVE_SIGNAL_H)
|
sysdeps: Use C11 stdatomic.h where possible
On Unix, dbus has historically used gcc-specific lock-free atomic
intrinsics where available, falling back to a pthreads mutex where
possible. Meanwhile, on Windows, it has historically used
InterlockedIncrement() and similar library functions (in practice
wrappers around lock-free intrinsics on real Windows, but IPC calls into
wineserver on Wine).
ISO C11 provides a new header, stdatomic.h, with standardized support
for atomic operations. Exactly how these are implemented is a compiler
quality-of-implementation decision, but any reasonable compiler
implementation on a modern CPU should be using intrinsics. Let's use
this wherever possible, falling back to our old implementation only if
the C11 implementation is unsupported.
One concrete benefit that we get from this is that when compiling with
mingw-w64 gcc and running via Wine, this makes atomic reference counting
operations into a simple local operation, rather than IPC to wineserver
which can be very slow. This should make our CI tests considerably more
reliable.
In all vaguely modern gcc versions (gcc 5.5 or later) and in contemporary
versions of clang, the default compiler mode is C11 or later with GNU
extensions. We intentionally do not ask for any specific C standard, so
we can use C11 features like this one, as long as we do so conditionally.
The Microsoft Visual C compiler does not currently support this without
special options, so we still use the Interlocked family of functions
when compiling for Windows with MSVC.
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 19:53:11 +01:00
|
|
|
check_include_file(stdatomic.h HAVE_STDATOMIC_H)
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h
|
2015-03-05 13:06:10 +01:00
|
|
|
check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
|
2023-08-07 15:46:52 +02:00
|
|
|
check_include_file(sys/inotify.h DBUS_BUS_ENABLE_INOTIFY)
|
|
|
|
|
check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
|
2020-03-24 11:31:41 +01:00
|
|
|
check_include_file(sys/random.h HAVE_SYS_RANDOM_H)
|
2015-03-05 09:02:03 +01:00
|
|
|
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
|
2022-03-02 12:25:54 +00:00
|
|
|
check_include_file(sys/syscall.h HAVE_SYS_SYSCALL_H)
|
2007-03-03 14:32:17 +00:00
|
|
|
check_include_file(sys/time.h HAVE_SYS_TIME_H)# dbus-sysdeps-win.c
|
2023-03-20 01:40:20 +00:00
|
|
|
check_include_file(sys/vfs.h HAVE_SYS_VFS_H)
|
2023-08-07 15:46:52 +02:00
|
|
|
check_include_file(syslog.h HAVE_SYSLOG_H)
|
2007-03-03 14:32:17 +00:00
|
|
|
check_include_file(unistd.h HAVE_UNISTD_H) # dbus-sysdeps-util-win.c
|
2023-08-07 15:46:52 +02:00
|
|
|
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c
|
2007-03-03 14:32:17 +00:00
|
|
|
|
2022-03-20 23:25:29 +00:00
|
|
|
find_package(Backtrace) # dbus-sysdeps.c, dbus-sysdeps-win.c
|
|
|
|
|
set(HAVE_BACKTRACE ${Backtrace_FOUND})
|
|
|
|
|
|
2023-08-07 15:46:52 +02:00
|
|
|
# keep in sync with check_functions in meson.build
|
|
|
|
|
check_symbol_exists(LOG_PERROR "syslog.h" HAVE_DECL_LOG_PERROR)
|
|
|
|
|
check_symbol_exists(MSG_NOSIGNAL "sys/socket.h" HAVE_DECL_MSG_NOSIGNAL)
|
|
|
|
|
check_symbol_exists(SCM_RIGHTS "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING)
|
2023-03-20 02:00:51 +00:00
|
|
|
check_symbol_exists(SYS_pidfd_open "sys/syscall.h" HAVE_DECL_SYS_PIDFD_OPEN) # dbus-sysdeps-unix.c
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4)
|
|
|
|
|
check_symbol_exists(clearenv "stdlib.h" HAVE_CLEARENV) # dbus-sysdeps.c
|
|
|
|
|
check_symbol_exists(close_range "unistd.h" HAVE_CLOSE_RANGE) # dbus-sysdeps-unix.c
|
|
|
|
|
check_symbol_exists(closefrom "unistd.h" HAVE_CLOSEFROM) # dbus-sysdeps-unix.c
|
|
|
|
|
check_symbol_exists(environ "unistd.h" HAVE_DECL_ENVIRON)
|
|
|
|
|
check_symbol_exists(fstatfs "sys/vfs.h" HAVE_FSTATFS)
|
2007-03-03 14:32:17 +00:00
|
|
|
check_symbol_exists(getgrouplist "grp.h" HAVE_GETGROUPLIST) # dbus-sysdeps.c
|
|
|
|
|
check_symbol_exists(getpeerucred "ucred.h" HAVE_GETPEERUCRED) # dbus-sysdeps.c, dbus-sysdeps-win.c
|
2018-10-22 14:52:01 +01:00
|
|
|
check_symbol_exists(getpwnam_r "errno.h;pwd.h" HAVE_GETPWNAM_R) # dbus-sysdeps-util-unix.c
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
|
|
|
|
|
check_symbol_exists(getresuid "unistd.h" HAVE_GETRESUID)
|
|
|
|
|
check_symbol_exists(getrlimit "sys/resource.h;sys/time.h" HAVE_GETRLIMIT)
|
|
|
|
|
check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1)
|
2010-04-13 16:16:27 +02:00
|
|
|
check_symbol_exists(localeconv "locale.h" HAVE_LOCALECONV) # dbus-sysdeps.c
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP) # dbus-sysdeps.c
|
2014-10-14 16:18:54 +02:00
|
|
|
check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2)
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(poll "poll.h" HAVE_POLL) # dbus-sysdeps-unix.c
|
2015-02-20 16:00:30 +00:00
|
|
|
check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL)
|
2018-02-20 11:45:39 +00:00
|
|
|
check_symbol_exists(prlimit "sys/resource.h;sys/time.h" HAVE_PRLIMIT)
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(raise "signal.h" HAVE_RAISE)
|
|
|
|
|
check_symbol_exists(setenv "stdlib.h" HAVE_SETENV) # dbus-sysdeps.c
|
|
|
|
|
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) # dbus-test-main.c
|
2022-05-25 22:00:08 +00:00
|
|
|
check_symbol_exists(setresuid "unistd.h" HAVE_SETRESUID)
|
2023-08-07 15:46:52 +02:00
|
|
|
check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) # dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
|
|
|
|
|
check_symbol_exists(setrlimit "sys/resource.h;sys/time.h" HAVE_SETRLIMIT)
|
|
|
|
|
check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # dbus-sysdeps.c
|
|
|
|
|
check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV) # dbus-sysdeps.c
|
|
|
|
|
check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV) # dbus-sysdeps.c, dbus-sysdeps-win.c
|
2007-03-03 14:32:17 +00:00
|
|
|
|
On 32-bit glibc, define _TIME_BITS to 64 if not already defined
On older 32-bit architectures such as i386, this redefines time_t to be
64-bit, and correspondingly increases the size of all system data
structures that contain a time_t, such as struct timeval and struct stat.
This is necessary to allow timestamps beyond January 2038 to be
represented; as well as things that obviously deal with timestamps,
this affects functions like stat() (and therefore our wrapper
_dbus_stat()), which will fail with EOVERFLOW if asked to inspect a
file whose correct timestamp does not fit in time_t.
In particular, if the modification or access timestamp on
/etc/machine-id has somehow been set to a post-2038 time, libdbus will
consider the inability to stat() that file to be an installation error,
and when using the deprecated dbus_get_local_machine_id(), that can
cause third-party i386 software such as the Steam client to crash.
Using 64-bit timestamps avoids that failure mode.
Using 64-bit timestamps in glibc is an opt-in and not the default,
because if done carelessly it can change libraries' ABIs. However,
libdbus is careful not to include system headers and system data
types in its own headers, with the only exceptions being extremely
basic ISO C headers like <stddef.h> and <stdarg.h>; so we can safely
do this without it breaking our ABI. This is similar to the reasoning
for why commit 96ffc2a0 "configure.ac: support large-file for stat64"
was a safe change.
This change only affects glibc. Some non-GNU operating system libraries
(such as musl) are less concerned with binary backwards compatibility
than glibc, and therefore have incompatibly changed their ABI on 32-bit
platforms to switch to 64-bit timestamps throughout; no action is needed
on those platforms. If other non-GNU OS libraries have taken a route
similar to GNU's, then maintainers of those operating systems are
welcome to send tested merge requests similar to this one.
An extra subtlety here is that _TIME_BITS=64 requires
_FILE_OFFSET_BITS=64. In the Meson build, Meson unconditionally enables
_FILE_OFFSET_BITS=64 where appropriate, and in the Autotools build,
we already had that via AC_SYS_LARGEFILE, but in the CMake build we
did not necessarily have this; so we also define _FILE_OFFSET_BITS=64
there if necessary, as a continuation of commit 96ffc2a0
"configure.ac: support large-file for stat64".
On newer 32-bit architectures like x32, time_t is always 64-bit and so
this has no practical effect.
On 64-bit, setting these would have no practical effect, but to minimize
risk I'm only doing this for 32-bit architectures.
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/465
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-07 20:19:17 +01:00
|
|
|
# It doesn't really matter which specific header we use for these, as long as
|
|
|
|
|
# we include at least one glibc-provided header. time.h is suitable.
|
|
|
|
|
check_symbol_exists(__GLIBC__ "time.h" HAVE___GLIBC__)
|
|
|
|
|
check_symbol_exists(_FILE_OFFSET_BITS "time.h" HAVE__FILE_OFFSET_BITS)
|
|
|
|
|
check_symbol_exists(_TIME_BITS "time.h" HAVE__TIME_BITS)
|
|
|
|
|
|
|
|
|
|
# Opt-in to large inode number and timestamp support, which we know doesn't
|
|
|
|
|
# break libdbus ABI: https://gitlab.freedesktop.org/dbus/dbus/-/issues/465
|
|
|
|
|
if(HAVE___GLIBC__ AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT HAVE__FILE_OFFSET_BITS)
|
|
|
|
|
set(_FILE_OFFSET_BITS 64)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(HAVE___GLIBC__ AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT HAVE__TIME_BITS)
|
|
|
|
|
set(_TIME_BITS 64)
|
|
|
|
|
endif()
|
|
|
|
|
|
2018-10-22 09:27:30 +02:00
|
|
|
check_struct_member(cmsgcred cmcred_pid "sys/types.h;sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c
|
2007-03-03 14:32:17 +00:00
|
|
|
|
2018-10-20 22:22:20 +02:00
|
|
|
CHECK_C_SOURCE_COMPILES("
|
|
|
|
|
#ifndef __linux__
|
|
|
|
|
#error This is not Linux
|
|
|
|
|
#endif
|
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
|
int main() {
|
|
|
|
|
epoll_create1 (EPOLL_CLOEXEC);
|
|
|
|
|
}" DBUS_HAVE_LINUX_EPOLL)
|
|
|
|
|
|
2018-10-21 11:34:13 +02:00
|
|
|
CHECK_C_SOURCE_COMPILES("
|
|
|
|
|
int main() {
|
|
|
|
|
int a = 4;
|
|
|
|
|
int b = __sync_sub_and_fetch(&a, 4);
|
2022-05-15 11:28:51 +01:00
|
|
|
return b;
|
2018-10-21 11:34:13 +02:00
|
|
|
}
|
|
|
|
|
" DBUS_USE_SYNC)
|
|
|
|
|
|
2022-08-14 16:28:56 +00:00
|
|
|
set(DBUS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
|
|
|
|
|
2007-03-03 14:32:17 +00:00
|
|
|
check_type_size("short" SIZEOF_SHORT)
|
|
|
|
|
check_type_size("int" SIZEOF_INT)
|
|
|
|
|
check_type_size("long" SIZEOF_LONG)
|
|
|
|
|
check_type_size("long long" SIZEOF_LONG_LONG)
|
|
|
|
|
check_type_size("__int64" SIZEOF___INT64)
|
2015-03-04 14:10:17 +01:00
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
|
2021-11-03 09:37:04 +01:00
|
|
|
check_type_size("socklen_t" HAVE_SOCKLEN_T) # dbus-sysdeps-unix.c
|
2015-03-04 14:10:17 +01:00
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES)
|
2007-03-03 14:32:17 +00:00
|
|
|
|
|
|
|
|
# DBUS_INT64_TYPE
|
|
|
|
|
if(SIZEOF_INT EQUAL 8)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT64_TYPE "int")
|
|
|
|
|
set(DBUS_INT64_CONSTANT "(val)")
|
|
|
|
|
set(DBUS_UINT64_CONSTANT "(val##U)")
|
2022-04-01 15:57:07 +01:00
|
|
|
set(DBUS_INT64_MODIFIER "")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF_LONG EQUAL 8)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT64_TYPE "long")
|
|
|
|
|
set(DBUS_INT64_CONSTANT "(val##L)")
|
|
|
|
|
set(DBUS_UINT64_CONSTANT "(val##UL)")
|
2022-04-01 15:57:07 +01:00
|
|
|
set(DBUS_INT64_MODIFIER "l")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF_LONG_LONG EQUAL 8)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT64_TYPE "long long")
|
|
|
|
|
set(DBUS_INT64_CONSTANT "(val##LL)")
|
|
|
|
|
set(DBUS_UINT64_CONSTANT "(val##ULL)")
|
2022-04-01 15:57:07 +01:00
|
|
|
set(DBUS_INT64_MODIFIER "ll")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF___INT64 EQUAL 8)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT64_TYPE "__int64")
|
|
|
|
|
set(DBUS_INT64_CONSTANT "(val##i64)")
|
|
|
|
|
set(DBUS_UINT64_CONSTANT "(val##ui64)")
|
2022-04-01 15:57:07 +01:00
|
|
|
set(DBUS_INT64_MODIFIER "I64")
|
2013-06-05 19:43:13 +01:00
|
|
|
else(SIZEOF_INT EQUAL 8)
|
2019-01-21 19:37:46 +01:00
|
|
|
message(FATAL_ERROR "Could not find a 64-bit integer type")
|
2019-01-23 21:26:22 +01:00
|
|
|
endif()
|
2007-03-03 14:32:17 +00:00
|
|
|
|
2022-04-01 15:57:07 +01:00
|
|
|
# MSVCRT.dll printf() doesn't support %lld
|
|
|
|
|
if(WIN32 AND NOT CYGWIN)
|
|
|
|
|
set(DBUS_INT64_MODIFIER "I64")
|
|
|
|
|
endif()
|
|
|
|
|
|
2007-03-03 14:32:17 +00:00
|
|
|
# DBUS_INT32_TYPE
|
|
|
|
|
if(SIZEOF_INT EQUAL 4)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT32_TYPE "int")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF_LONG EQUAL 4)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT32_TYPE "long")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF_LONG_LONG EQUAL 4)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT32_TYPE "long long")
|
2019-01-23 21:26:22 +01:00
|
|
|
endif()
|
2007-03-03 14:32:17 +00:00
|
|
|
|
|
|
|
|
# DBUS_INT16_TYPE
|
|
|
|
|
if(SIZEOF_INT EQUAL 2)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT16_TYPE "int")
|
2011-09-23 15:38:12 +02:00
|
|
|
elseif(SIZEOF_SHORT EQUAL 2)
|
2019-01-21 19:37:46 +01:00
|
|
|
set(DBUS_INT16_TYPE "short")
|
2019-01-23 21:26:22 +01:00
|
|
|
endif()
|
2007-03-03 14:32:17 +00:00
|
|
|
|
|
|
|
|
find_program(DOXYGEN doxygen)
|
|
|
|
|
find_program(XMLTO xmlto)
|