Skip to content

Commit 3b29bfc

Browse files
committed
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 <[email protected]>
1 parent fe9612f commit 3b29bfc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,24 @@ if(WITH_NETWORK_BACKEND)
303303
option(WITH_NETWORK_GET_BUFFER "Enable experimental zero-copy transfers" OFF)
304304
if (WITH_NETWORK_GET_BUFFER)
305305
include(CheckCSourceCompiles)
306-
check_c_source_compiles("#include <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)
306+
check_c_source_compiles("#define _GNU_SOURCE=1\n#include <fcntl.h>\nint main(void) { return O_TMPFILE; }"
307+
HAS_O_TMPFILE)
307308

308309
if (NOT HAS_O_TMPFILE)
309310
message(SEND_ERROR "Zero-copy requires the O_TMPFILE flag, which is not available on the system.")
310311
endif()
311312
endif()
312313

313-
check_c_source_compiles("#include <sys/eventfd.h>\nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" WITH_NETWORK_EVENTFD)
314-
endif()
314+
check_c_source_compiles("#include <sys/eventfd.h>\nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }"
315+
WITH_NETWORK_EVENTFD)
316+
if (NOT WITH_NETWORK_EVENTFD)
317+
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); }"
318+
HAS_PIPE2)
319+
endif()
315320

316-
if(NOT WIN32)
317-
include(CheckCSourceCompiles)
318-
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)
321+
if (WITH_NETWORK_GET_BUFFER OR HAS_PIPE2)
322+
add_definitions(-D_GNU_SOURCE=1)
323+
endif()
319324
endif()
320325

321326
list(APPEND LIBIIO_CFILES network.c)

0 commit comments

Comments
 (0)