CMake: fix missing _GNU_SOURCE macro in CYGWIN

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 <thiago.macieira@intel.com>
This commit is contained in:
Carlo Bramini 2025-01-01 15:40:11 +01:00
parent 6f891f3ccb
commit 1582dd5da1

View File

@ -279,6 +279,13 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
"$<$<AND:${not_disabled},${is_xcode15}>: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"