changeset 30671:9c98df2035a3 stable

build: Check for compiler option to enable GNU extensions (bug #61812). * configure.ac: Check for compiler option to enable C++17 support if configured with --enable-std-pmr-polymorphic-allocator. Prefer compiler options that enable GNU extensions.
author Markus Mützel <markus.muetzel@gmx.de>
date Mon, 24 Jan 2022 20:02:17 +0100
parents 7a9d358fb66d
children 1db5815926f4 3ca33008c4a9
files configure.ac
diffstat 1 files changed, 37 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Mon Jan 24 22:13:13 2022 +0100
+++ b/configure.ac	Mon Jan 24 20:02:17 2022 +0100
@@ -332,8 +332,43 @@
 AC_PROG_CXX
 AC_PROG_CXXCPP
 
-## Ensure that the C++ compiler fully supports C++11.
-AX_CXX_COMPILE_STDCXX(11, [], [])
+ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=no
+AC_ARG_ENABLE(std-pmr-polymorphic-allocator,
+  [AS_HELP_STRING([--enable-std-pmr-polymorphic-allocator],
+    [build libraries requiring std::pmr::polymorphic_allocator if possible. This allows more efficient transfer of arrays at the .mex file interface. That also means that all libraries including Octave headers (e.g., .oct files) must be able to compile with that C++17 feature.])],
+  [case $enableval in
+     yes) ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=yes ;;
+     no) ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=no ;;
+     *) AC_MSG_ERROR([bad value $enableval for --enable-std-pmr-polymorphic-allocator]) ;;
+   esac])
+
+### Check compiler capabilities.
+
+if test $ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR = yes; then
+  ## Test for flags to fully support C++17 (with GNU extensions).
+  AX_CXX_COMPILE_STDCXX(17, ext, [])
+  if test "$HAVE_CXX17" = 0; then
+    ## A compiler supporting C++17 with GNU extensions couldn't be found.
+    ## Try without forcing GNU extensions.
+    AX_CXX_COMPILE_STDCXX(17, [], [])
+  fi
+else
+  HAVE_CXX17=0
+fi
+if test "$HAVE_CXX17" = 0; then
+  ## Ensure that the C++ compiler fully supports C++11 preferably with GNU
+  ## extensions.
+  AX_CXX_COMPILE_STDCXX(11, ext, [])
+  if test "$HAVE_CXX11" = 0; then
+    ## A compiler supporting C++11 with GNU extensions couldn't be found.
+    ## Try without forcing GNU extensions.  Fail if that's not the case.
+    AX_CXX_COMPILE_STDCXX(11, [], mandatory)
+  fi
+fi
+
+if test $ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR = yes; then
+  OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR
+fi
 
 ### Determine which C compiler to use (we expect to find gcc).
 
@@ -400,20 +435,6 @@
   OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h])
 fi
 
-ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=no
-AC_ARG_ENABLE(std-pmr-polymorphic-allocator,
-  [AS_HELP_STRING([--enable-std-pmr-polymorphic-allocator],
-    [build libraries requiring std::pmr::polymorphic_allocator if possible. This allows more efficient transfer of arrays at the .mex file interface. That also means that all libraries including Octave headers (e.g., .oct files) must be able to compile with that C++17 feature.])],
-  [case $enableval in
-     yes) ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=yes ;;
-     no) ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR=no ;;
-     *) AC_MSG_ERROR([bad value $enableval for --enable-std-pmr-polymorphic-allocator]) ;;
-   esac])
-
-if test $ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR = yes; then
-  OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR
-fi
-
 ### Check version number when using gcc.
 dnl It might be different from the g++ version number.