From ebe44543ee874b5a03f4a05b62d89169899a3dc2 Mon Sep 17 00:00:00 2001 From: Pavel Otchertsov Date: Thu, 25 Mar 2021 11:09:13 +0300 Subject: [PATCH] cmake: check if _GNU_SOURCE is already defined --- CMakeLists.txt | 5 ++++- lib/CMakeLists.txt | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e94757cdf..7966444be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -658,7 +658,10 @@ if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR endif() if (LWS_HAVE_PTHREAD_H AND NOT LWS_PLAT_FREERTOS) - CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE + CHECK_C_SOURCE_COMPILES(" + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif #include int main(void) { pthread_t th = 0; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5494341ec..7f132c877 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -103,7 +103,15 @@ endif() # ideally we want to use pipe2() -CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include \nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2) +CHECK_C_SOURCE_COMPILES(" + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif + #include + int main(void) { + int fd[2]; + return pipe2(fd, 0); + }" LWS_HAVE_PIPE2) # tcp keepalive needs this on linux to work practically... but it only exists # after kernel 2.6.37