From 1582dd5da1775fa3595f10ab8278c3d12dcd319f Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Wed, 1 Jan 2025 15:40:11 +0100 Subject: [PATCH] CMake: fix missing _GNU_SOURCE macro in CYGWIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compiling qtbase in CYGWIN shows several errors like this one: In file included from qtbase/include/QtCore/6.9.0/QtCore/private/qcore_unix_p.h:1, from qtbase/src/corelib/global/qlogging.cpp:61: qtbase/src/corelib/kernel/qcore_unix_p.h: In function ‘int qt_safe_pipe(int*, int)’: qtbase/src/corelib/kernel/qcore_unix_p.h:283:14: error: ‘::pipe2’ has not been declared; did you mean ‘pipe’? 233 | return ::pipe2(pipefd, flags); // pipe2 is documented not to return EINTR | ^~~~~ | pipe Actually, the error happens because pipe2() is available only when _GNU_SOURCE is defined: https://man7.org/linux/man-pages/man2/pipe.2.html CYGWIN doesn't define this macro by default, so this is reason because the error happens. In my opinion, the best way for fixing the trouble is adding the missing _GNU_SOURCE macro by using CMake. Using qplatformdefs.h, which is also broken for cygwin-g++ target, doesn't fix the issue, so the only way to solve the problem is to set it with CMake or forcing it externally by using CPPFLAGS. Change-Id: I6917630999b29582556258eee11d9989f439c37c Reviewed-by: Thiago Macieira --- cmake/QtInternalTargets.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index 1235efbd879..c3bd6ab9f71 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -279,6 +279,13 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") "$<$:LINKER:-no_warn_duplicate_libraries>") endif() +if(CYGWIN) + # CYGWIN doesn't define _GNU_SOURCE by default for better support with W32API + target_compile_definitions(PlatformCommonInternal INTERFACE + "_GNU_SOURCE" + ) +endif() + if(MSVC) target_compile_definitions(PlatformCommonInternal INTERFACE "_CRT_SECURE_NO_WARNINGS"