From 9455d3542a3f8fa8feb96cddfc96db0c34e2ed15 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 20 Oct 2018 22:25:06 +0200 Subject: [PATCH 1/8] Use same name for DBUS_HAVE_LINUX_EPOLL cpp macro and Automake conditional Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- configure.ac | 2 +- dbus/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 05c18b5e..51a016dc 100644 --- a/configure.ac +++ b/configure.ac @@ -1011,7 +1011,7 @@ fi if test x$have_linux_epoll = xyes; then AC_DEFINE([DBUS_HAVE_LINUX_EPOLL], 1, [Define to use epoll(4) on Linux]) fi -AM_CONDITIONAL([HAVE_LINUX_EPOLL], [test x$have_linux_epoll = xyes]) +AM_CONDITIONAL([DBUS_HAVE_LINUX_EPOLL], [test x$have_linux_epoll = xyes]) # kqueue checks if test x$enable_kqueue = xno ; then diff --git a/dbus/Makefile.am b/dbus/Makefile.am index e4a7f5a8..c003b399 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -120,7 +120,7 @@ DBUS_UTIL_arch_sources = \ $(NULL) endif -if HAVE_LINUX_EPOLL +if DBUS_HAVE_LINUX_EPOLL DBUS_UTIL_arch_sources += dbus-socket-set-epoll.c endif From 2934dedd1c71aa9af20a266c827c3f8e02c13cd5 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 20 Oct 2018 22:22:20 +0200 Subject: [PATCH 2/8] Add cmake support for DBUS_HAVE_LINUX_EPOLL Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 10 ++++++++++ cmake/config.h.cmake | 3 +++ cmake/dbus/CMakeLists.txt | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 1b767e0d..b45ab763 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -3,6 +3,7 @@ include(CheckIncludeFiles) include(CheckSymbolExists) include(CheckStructMember) include(CheckTypeSize) +include(CheckCSourceCompiles) check_include_file(alloca.h HAVE_ALLOCA_H) check_include_file(byteswap.h HAVE_BYTESWAP_H) @@ -69,6 +70,15 @@ check_symbol_exists(setrlimit "sys/resource.h;sys/time.h" HAVE_SETRLIMIT) check_struct_member(cmsgcred cmcred_pid "sys/types.h;sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c +CHECK_C_SOURCE_COMPILES(" +#ifndef __linux__ +#error This is not Linux +#endif +#include +int main() { +epoll_create1 (EPOLL_CLOEXEC); +}" DBUS_HAVE_LINUX_EPOLL) + # missing: # DBUS_HAVE_GCC33_GCOV diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index c296c05a..71a02837 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -217,6 +217,9 @@ #cmakedefine HAVE_SETRLIMIT 1 #cmakedefine HAVE_UNIX_FD_PASSING 1 +/* Define to use epoll(4) on Linux */ +#cmakedefine DBUS_HAVE_LINUX_EPOLL 1 + // structs /* Define to 1 if you have struct cmsgred */ #cmakedefine HAVE_CMSGCRED 1 diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index 33f2be60..6c11a4ce 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -233,6 +233,13 @@ else (WIN32) ) endif (WIN32) +if(DBUS_HAVE_LINUX_EPOLL) + set(DBUS_UTIL_SOURCES + ${DBUS_UTIL_SOURCES} + ${DBUS_DIR}/dbus-socket-set-epoll.c + ) +endif() + set(libdbus_SOURCES ${DBUS_LIB_SOURCES} ${DBUS_SHARED_SOURCES} From bd6ece893a45e8103a696ee64adc1baa2096c422 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 20 Oct 2018 22:34:33 +0200 Subject: [PATCH 3/8] Refactor cmake checks for DBUS_VA_COPY and DBUS_VA_COPY_ARRAY For test case execution, CheckCSourceCompiles is now used instead of try_compile and the determination of DBUS_VA_AS_ARRAY is performed with a separate test instead of evaluating the result of HAVE_VA_COPY and HAVE___VA_COPY. The tests are performed for all supported compilers. Since older MSVC compilers (< 2013) do not support va_copy(), the macro _DBUS_VA_ASSIGN(a1,a2) with the implementation { a1 = a2; } is used as a fallback. Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 114 ++++++++++++++++++++---------------- cmake/config.h.cmake | 16 ++--- 2 files changed, 69 insertions(+), 61 deletions(-) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index b45ab763..b31d5b6b 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -79,6 +79,69 @@ int main() { epoll_create1 (EPOLL_CLOEXEC); }" DBUS_HAVE_LINUX_EPOLL) +CHECK_C_SOURCE_COMPILES(" +#include +#include +static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); +} +int main() { + f (0, 42); + return 0; +} +" HAVE_VA_COPY) + +CHECK_C_SOURCE_COMPILES(" +#include +#include +static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + __va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); +} +int main() { + f (0, 42); + return 0; +} +" HAVE___VA_COPY) + +if(HAVE_VA_COPY) + set(DBUS_VA_COPY va_copy CACHE STRING "va_copy function") +elseif(HAVE___VA_COPY) + set(DBUS_VA_COPY __va_copy CACHE STRING "va_copy function") +else() + # this is used for msvc < 2013 + set(DBUS_VA_COPY _DBUS_VA_COPY_ASSIGN) +endif() + +CHECK_C_SOURCE_COMPILES(" +#include +#include +static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + args2 = args1; + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); +} +int main() { + f (0, 42); + return 0; +} +" VA_COPY_AS_ARRAY) +if (NOT VA_COPY_AS_ARRAY) + set(DBUS_VA_COPY_AS_ARRAY 1 CACHE STRING "'va_lists' cannot be copies as values") +endif() + # missing: # DBUS_HAVE_GCC33_GCOV @@ -130,54 +193,3 @@ endif(SIZEOF_INT EQUAL 2) find_program(DOXYGEN doxygen) find_program(XMLTO xmlto) - -if(MSVC) - SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN") -else(MSVC) -write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include - #include - static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); - } - int main() { - f (0, 42); - return 0; - } -") -try_compile(DBUS_HAVE_VA_COPY - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c) - -if(DBUS_HAVE_VA_COPY) - SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function") -else(DBUS_HAVE_VA_COPY) - write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include - #include - static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - __va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); - } - int main() { - f (0, 42); - return 0; - } - ") - try_compile(DBUS_HAVE___VA_COPY - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c) - if(DBUS_HAVE___VA_COPY) - SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function") - else(DBUS_HAVE___VA_COPY) - SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values") - endif(DBUS_HAVE___VA_COPY) -endif(DBUS_HAVE_VA_COPY) -endif(MSVC) # _not_ MSVC diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 71a02837..dc5d990b 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -66,18 +66,14 @@ # define DBUS_ENABLE_X11_AUTOLAUNCH 1 #endif +/* A 'va_copy' style function */ +#cmakedefine DBUS_VA_COPY @DBUS_VA_COPY@ + +/* for msvc */ #define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; } -#cmakedefine DBUS_VA_COPY_FUNC -#if (defined DBUS_VA_COPY_FUNC) -# define DBUS_VA_COPY @DBUS_VA_COPY_FUNC@ -#endif - -#ifdef DBUS_VA_COPY_FUNC -#undef DBUS_VA_COPY_FUNC -#endif - -#cmakedefine DBUS_VA_COPY_AS_ARRAY @DBUS_VA_COPY_AS_ARRAY@ +/* 'va_lists' cannot be copies as values */ +#cmakedefine DBUS_VA_COPY_AS_ARRAY 1 #cmakedefine DBUS_WITH_GLIB 1 #cmakedefine GLIB_VERSION_MIN_REQUIRED @GLIB_VERSION_MIN_REQUIRED@ From 6c95c7e39556c3686cff6945035c0586975b111a Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sun, 21 Oct 2018 11:34:13 +0200 Subject: [PATCH 4/8] Add cmake check for DBUS_USE_SYNC Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 8 ++++++++ cmake/config.h.cmake | 3 +++ 2 files changed, 11 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index b31d5b6b..39c2ed5b 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -142,6 +142,14 @@ if (NOT VA_COPY_AS_ARRAY) set(DBUS_VA_COPY_AS_ARRAY 1 CACHE STRING "'va_lists' cannot be copies as values") endif() +CHECK_C_SOURCE_COMPILES(" +int main() { + int a = 4; + int b = __sync_sub_and_fetch(&a, 4); + exit(b); +} +" DBUS_USE_SYNC) + # missing: # DBUS_HAVE_GCC33_GCOV diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index dc5d990b..1235a450 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -216,6 +216,9 @@ /* Define to use epoll(4) on Linux */ #cmakedefine DBUS_HAVE_LINUX_EPOLL 1 +/* Use the gcc __sync extension */ +#cmakedefine DBUS_USE_SYNC 1 + // structs /* Define to 1 if you have struct cmsgred */ #cmakedefine HAVE_CMSGCRED 1 From ba8a5e509c34aadd0097b29144ba4dd8c65412ed Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 22 Oct 2018 13:27:46 +0200 Subject: [PATCH 5/8] Add cmake check for HAVE_DIRFD Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 12 +++++++++++- cmake/config.h.cmake | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 39c2ed5b..cee6a927 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -59,7 +59,6 @@ check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) # set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2) check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4) -check_symbol_exists(dirfd "dirent.h" HAVE_DIRFD) check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1) check_symbol_exists(SCM_RIGHTS "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING) check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL) @@ -150,6 +149,17 @@ int main() { } " DBUS_USE_SYNC) +CHECK_C_SOURCE_COMPILES(" +#include +#include +int main( + DIR *dirp; + dirp = opendir(\".\"); + dirfd(dirp); + closedir(dirp); +) +" HAVE_DIRFD) + # missing: # DBUS_HAVE_GCC33_GCOV diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 1235a450..531bc835 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -204,7 +204,10 @@ #cmakedefine HAVE_PIPE2 1 #cmakedefine HAVE_ACCEPT4 1 + +/* Have dirfd function */ #cmakedefine HAVE_DIRFD 1 + #cmakedefine HAVE_INOTIFY_INIT1 1 #cmakedefine HAVE_GETRLIMIT 1 #cmakedefine HAVE_PRCTL 1 From 72b0aebb6eed5c93822e815ac9d9e553ec10f97e Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sun, 21 Oct 2018 11:36:16 +0200 Subject: [PATCH 6/8] Add cmake check for HAVE_DDFD Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 15 +++++++++++++++ cmake/config.h.cmake | 3 +++ 2 files changed, 18 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index cee6a927..c14421ff 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -160,6 +160,21 @@ int main( ) " HAVE_DIRFD) +if(NOT HAVE_DIRFD) + CHECK_C_SOURCE_COMPILES(" + #include + #include + int main() + { + DIR *dirp; + int fd; + dirp = opendir(\".\"); + fd = dirp->dd_fd; + closedir(dirp); + } + " HAVE_DDFD) +endif() + # missing: # DBUS_HAVE_GCC33_GCOV diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 531bc835..f46454aa 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -208,6 +208,9 @@ /* Have dirfd function */ #cmakedefine HAVE_DIRFD 1 +/* Have the ddfd member of DIR */ +#cmakedefine HAVE_DDFD 1 + #cmakedefine HAVE_INOTIFY_INIT1 1 #cmakedefine HAVE_GETRLIMIT 1 #cmakedefine HAVE_PRCTL 1 From fd00c5fdef430900d0c848414493a20e59c76b4b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 22 Oct 2018 17:03:52 +0200 Subject: [PATCH 7/8] Add cmake support for HAVE_GNUC_VARARGS and HAVE_ISO_VARARGS Reviewed-by: Simon McVittie Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/ConfigureChecks.cmake | 22 ++++++++++++++++++++++ cmake/config.h.cmake | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index c14421ff..88331d7d 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -175,6 +175,28 @@ if(NOT HAVE_DIRFD) " HAVE_DDFD) endif() +CHECK_C_SOURCE_COMPILES(" +int a(int p1, int p2, int p3) +{ +} +int main() +{ + #define call_a(params...) a(1,params) + call_a(2,3); +} +" HAVE_GNUC_VARARGS) + +CHECK_C_SOURCE_COMPILES(" +int a(int p1, int p2, int p3) +{ +} +int main() +{ + #define call_a(...) a(1,__VA_ARGS__) + call_a(2,3); +} +" HAVE_ISO_VARARGS) + # missing: # DBUS_HAVE_GCC33_GCOV diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index f46454aa..af19a805 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -12,8 +12,13 @@ * Variables defined by AC_DEFINE in ../configure.ac * should be placed in this file */ + +/* Have GNU-style varargs macros */ #cmakedefine HAVE_GNUC_VARARGS 1 +/* Have ISO C99 varargs macros */ +#cmakedefine HAVE_ISO_VARARGS 1 + #cmakedefine DBUS_CONSOLE_AUTH_DIR "@DBUS_CONSOLE_AUTH_DIR@" #cmakedefine DBUS_DATADIR "@DBUS_DATADIR@" #cmakedefine DBUS_BINDIR "@DBUS_BINDIR@" From 7bba42587bf07c1308bec950311131fd04a82215 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sun, 21 Oct 2018 10:40:28 +0200 Subject: [PATCH 8/8] Remove todo(s) for cmake build system Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18 --- cmake/CMakeLists.txt | 2 -- cmake/ConfigureChecks.cmake | 3 --- 2 files changed, 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a18cb48b..d7b9c438 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -298,8 +298,6 @@ set(DBUS_INCLUDES) ENABLE_TESTING() ########### command line options ############### -# TODO: take check from configure.in - option (DBUS_BUILD_TESTS "enable unit test code" ON) if(DBUS_BUILD_TESTS) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 88331d7d..9f2008a1 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -197,9 +197,6 @@ int main() } " HAVE_ISO_VARARGS) -# missing: -# DBUS_HAVE_GCC33_GCOV - check_type_size("short" SIZEOF_SHORT) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG)