diff options
author | Simon McVittie <smcv@collabora.com> | 2022-04-01 15:57:07 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-04-19 18:27:47 +0000 |
commit | 6130ac4267842a6d3851ff4c1d8480532a2ba8cd (patch) | |
tree | 317d6487dc2c054a4d3dd26d6bdcfeca06537e91 /cmake | |
parent | 8972fcb029ca664a948ec9a219ea5b32a8266a33 (diff) | |
download | dbus-6130ac4267842a6d3851ff4c1d8480532a2ba8cd.tar.gz |
build: Define DBUS_INT64_MODIFIER, analogous to G_GINT64_MODIFIER
Using PRId64, etc. to print dbus_int64_t or dbus_uint64_t is not 100%
portable. On platforms where both long and long long are 64-bit (such as
Linux and macOS), we will prefer to define dbus_int64_t as long.
If the operating system has chosen to define int64_t as long long,
which is apparently the case on macOS, then the compiler can warn that
we are passing a long argument to PRId64, which is "lld" and therefore
expects a long long argument (even though that ends up with the same
bit-pattern being used).
We can't necessarily just use int64_t and uint64_t directly, even if all
our supported platforms have them available now, because swapping
dbus_int64_t between long and long long might change C++ name mangling,
causing ABI breaks in third-party libraries if they define C++ functions
that take a dbus_int64_t argument.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/ConfigureChecks.cmake | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 45136cc3..98f27db7 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -181,22 +181,31 @@ if(SIZEOF_INT EQUAL 8) set(DBUS_INT64_TYPE "int") set(DBUS_INT64_CONSTANT "(val)") set(DBUS_UINT64_CONSTANT "(val##U)") + set(DBUS_INT64_MODIFIER "") elseif(SIZEOF_LONG EQUAL 8) set(DBUS_INT64_TYPE "long") set(DBUS_INT64_CONSTANT "(val##L)") set(DBUS_UINT64_CONSTANT "(val##UL)") + set(DBUS_INT64_MODIFIER "l") elseif(SIZEOF_LONG_LONG EQUAL 8) set(DBUS_INT64_TYPE "long long") set(DBUS_INT64_CONSTANT "(val##LL)") set(DBUS_UINT64_CONSTANT "(val##ULL)") + set(DBUS_INT64_MODIFIER "ll") elseif(SIZEOF___INT64 EQUAL 8) set(DBUS_INT64_TYPE "__int64") set(DBUS_INT64_CONSTANT "(val##i64)") set(DBUS_UINT64_CONSTANT "(val##ui64)") + set(DBUS_INT64_MODIFIER "I64") else(SIZEOF_INT EQUAL 8) message(FATAL_ERROR "Could not find a 64-bit integer type") endif() +# MSVCRT.dll printf() doesn't support %lld +if(WIN32 AND NOT CYGWIN) + set(DBUS_INT64_MODIFIER "I64") +endif() + # DBUS_INT32_TYPE if(SIZEOF_INT EQUAL 4) set(DBUS_INT32_TYPE "int") |