]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Refactor cmake checks for DBUS_VA_COPY and DBUS_VA_COPY_ARRAY
authorRalf Habacker <ralf.habacker@freenet.de>
Sat, 20 Oct 2018 20:34:33 +0000 (22:34 +0200)
committerRalf Habacker <ralf.habacker@freenet.de>
Wed, 24 Oct 2018 08:03:30 +0000 (10:03 +0200)
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 <smcv@collabora.com>
Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/18

cmake/ConfigureChecks.cmake
cmake/config.h.cmake

index b45ab7635f4d4df3d8144727b69f837e67e96b47..b31d5b6bd996087d1e8628e200dedf76cce62cfa 100644 (file)
@@ -79,6 +79,69 @@ int main() {
 epoll_create1 (EPOLL_CLOEXEC);
 }" DBUS_HAVE_LINUX_EPOLL)
 
+CHECK_C_SOURCE_COMPILES("
+#include <stdarg.h>
+#include <stdlib.h>
+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 <stdarg.h>
+#include <stdlib.h>
+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 <stdarg.h>
+#include <stdlib.h>
+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 <stdarg.h>
-       #include <stdlib.h>
-        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 <stdarg.h>
-          #include <stdlib.h>
-         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
index 71a0283790b4887b12cfe4bc6b4ae45902e121b2..dc5d990b1f7e473b81382bdbed0b382651aced71 100644 (file)
 # define DBUS_ENABLE_X11_AUTOLAUNCH 1
 #endif
 
-#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
+/* A 'va_copy' style function */
+#cmakedefine DBUS_VA_COPY @DBUS_VA_COPY@
 
-#ifdef DBUS_VA_COPY_FUNC
-#undef DBUS_VA_COPY_FUNC
-#endif
+/* for msvc */
+#define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; }
 
-#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@