summaryrefslogtreecommitdiff
path: root/cmake/ConfigureChecks.cmake
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2018-10-25 20:14:24 +0200
committerSimon McVittie <smcv@collabora.com>2018-11-15 15:18:22 +0000
commita0503f0c9914dd2ee4d26f1c049f658f17774d8e (patch)
tree099a17cf143d92686b4df5c439d983d006c0616b /cmake/ConfigureChecks.cmake
parent0732d3ee1b432446661ba7ddcd3dad9ae155786b (diff)
downloaddbus-a0503f0c9914dd2ee4d26f1c049f658f17774d8e.tar.gz
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.
Diffstat (limited to 'cmake/ConfigureChecks.cmake')
-rw-r--r--cmake/ConfigureChecks.cmake115
1 files changed, 64 insertions, 51 deletions
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index 4afa5bd0..8f2ad315 100644
--- a/cmake/ConfigureChecks.cmake
+++ b/cmake/ConfigureChecks.cmake
@@ -4,6 +4,7 @@ include(CheckSymbolExists)
include(CheckStructMember)
include(CheckTypeSize)
include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
check_include_file(alloca.h HAVE_ALLOCA_H)
check_include_file(byteswap.h HAVE_BYTESWAP_H)
@@ -79,6 +80,69 @@ 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_RUNS("
+#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 "Set to 1 if va_list cannot be copied as a value")
+endif()
+
+CHECK_C_SOURCE_COMPILES("
int main() {
int a = 4;
int b = __sync_sub_and_fetch(&a, 4);
@@ -182,54 +246,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