Skip to content

Commit

Permalink
CMake: WITH_NETWORK_GET_BUFFER requires _GNU_SOURCE
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pcercuei committed May 19, 2021
1 parent fe9612f commit 3b29bfc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)
check_c_source_compiles("#define _GNU_SOURCE=1\n#include <fcntl.h>\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 <sys/eventfd.h>\nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" WITH_NETWORK_EVENTFD)
endif()
check_c_source_compiles("#include <sys/eventfd.h>\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 <unistd.h>\n#include <fcntl.h>\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 <unistd.h>\n#include <fcntl.h>\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)
Expand Down

0 comments on commit 3b29bfc

Please sign in to comment.