Pārlūkot izejas kodu

CMake compilation: do not use compiler extensions

For now, compiler extensions are no longer activated on CMake sources.
However these extensions are still used for various third parties.

This MR is a partial answer to the issue #20454.
Marc Chevrier 5 gadi atpakaļ
vecāks
revīzija
f034b0f663

+ 5 - 0
Source/CMakeLists.txt

@@ -1,6 +1,11 @@
 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
 # file Copyright.txt or https://cmake.org/licensing for details.
 
+# To ensure maximum portability across various compilers and platforms
+# deactivate any compiler extensions
+set(CMAKE_C_EXTENSIONS FALSE)
+set(CMAKE_CXX_EXTENSIONS FALSE)
+
 include(CheckIncludeFile)
 # Check if we can build support for ELF parsing.
 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")

+ 5 - 0
Source/CPack/WiX/cmWIXFilesSourceWriter.cxx

@@ -1,5 +1,10 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
+#if defined(__CYGWIN__)
+// For S_IWRITE symbol
+#  define _DEFAULT_SOURCE
+#endif
+
 #include "cmWIXFilesSourceWriter.h"
 
 #include "cm_sys_stat.h"

+ 10 - 0
Source/cmLoadCommandCommand.cxx

@@ -1,5 +1,15 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
+
+#if !defined(_WIN32) && !defined(__sun)
+// POSIX APIs are needed
+#  define _POSIX_C_SOURCE 200809L
+#endif
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+// For isascii
+#  define _XOPEN_SOURCE 700
+#endif
+
 #include "cmLoadCommandCommand.h"
 
 #include <csignal>

+ 13 - 0
Source/cmStandardLexer.h

@@ -3,6 +3,19 @@
 #ifndef cmStandardLexer_h
 #define cmStandardLexer_h
 
+#if !defined(_WIN32) && !defined(__sun)
+/* POSIX APIs are needed */
+#  define _POSIX_C_SOURCE 200809L
+#endif
+#if defined(__sun) && defined(__GNUC__) && !defined(__cplusplus)
+/* C sources: for fileno and strdup */
+#  define _XOPEN_SOURCE 600
+#endif
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+/* For isascii */
+#  define _XOPEN_SOURCE 700
+#endif
+
 #include "cmsys/Configure.h" // IWYU pragma: keep
 
 /* Disable some warnings.  */

+ 10 - 0
Source/cmSystemTools.cxx

@@ -1,5 +1,15 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
+
+#if !defined(_WIN32) && !defined(__sun)
+// POSIX APIs are needed
+#  define _POSIX_C_SOURCE 200809L
+#endif
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+// For isascii
+#  define _XOPEN_SOURCE 700
+#endif
+
 #include "cmSystemTools.h"
 
 #include <cmext/algorithm>

+ 10 - 0
Source/cmTimestamp.cxx

@@ -1,5 +1,15 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
+
+#if !defined(_WIN32) && !defined(__sun)
+// POSIX APIs are needed
+#  define _POSIX_C_SOURCE 200809L
+#endif
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+// For isascii
+#  define _XOPEN_SOURCE 700
+#endif
+
 #include "cmTimestamp.h"
 
 #include <cstdlib>

+ 4 - 0
Utilities/std/CMakeLists.txt

@@ -1,4 +1,8 @@
 
+# To ensure maximum portability across various compilers and platforms
+# deactivate any compiler extensions
+set(CMAKE_CXX_EXTENSIONS FALSE)
+
 # source files for CMake std library
 set(SRCS cm/bits/string_view.cxx
          cm/memory