From 3b29bfc5f508eaff99c040cb68b19742dd08dd98 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 14 May 2021 14:58:44 +0100 Subject: [PATCH] CMake: WITH_NETWORK_GET_BUFFER requires _GNU_SOURCE Fixes the compilation checks for O_TMPFILE and pipe2(), which require _GNU_SOURCE, and make sure this macro is defined if one of these two checks succeeded. Signed-off-by: Paul Cercueil --- CMakeLists.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3ed0a2cd..b3c99edbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,19 +303,24 @@ if(WITH_NETWORK_BACKEND) option(WITH_NETWORK_GET_BUFFER "Enable experimental zero-copy transfers" OFF) if (WITH_NETWORK_GET_BUFFER) include(CheckCSourceCompiles) - check_c_source_compiles("#include \nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE) + check_c_source_compiles("#define _GNU_SOURCE=1\n#include \nint main(void) { return O_TMPFILE; }" + HAS_O_TMPFILE) if (NOT HAS_O_TMPFILE) message(SEND_ERROR "Zero-copy requires the O_TMPFILE flag, which is not available on the system.") endif() endif() - check_c_source_compiles("#include \nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" WITH_NETWORK_EVENTFD) - endif() + check_c_source_compiles("#include \nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" + WITH_NETWORK_EVENTFD) + if (NOT WITH_NETWORK_EVENTFD) + check_c_source_compiles("#define _GNU_SOURCE=1\n#include \n#include \nint main(void) { int fd[2]; return pipe2(fd, O_CLOEXEC | O_NONBLOCK); }" + HAS_PIPE2) + endif() - if(NOT WIN32) - include(CheckCSourceCompiles) - check_c_source_compiles("#include \n#include \nint main(void) { int fd[2]; return pipe2(fd, O_CLOEXEC | O_NONBLOCK); }" HAS_PIPE2) + if (WITH_NETWORK_GET_BUFFER OR HAS_PIPE2) + add_definitions(-D_GNU_SOURCE=1) + endif() endif() list(APPEND LIBIIO_CFILES network.c)