summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murraycu@google.com>2023-02-25 14:33:17 +0100
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2023-03-05 18:12:05 +0100
commit7c1ee8c49b4d2e536ead630424200067b1ef2a73 (patch)
tree17b8510c8ded055c41f6539964f575559045af10
parent191c5f3ff1e4d3a375f63e54b76a848789156b7e (diff)
downloadmm-common-7c1ee8c49b4d2e536ead630424200067b1ef2a73.tar.gz
MM_AX_CXX_COMPILE_STDCXX: Merge in changes from upstream AX_CXX_COMPILE_STDCXXHEADmaster
Take recent changes from http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_cxx_compile_stdcxx.m4 and add MM/_MM prefixes where appropriate. This adds support for 20 as an argument for MM_AX_CXX_COMPILE_STDCXX().
-rw-r--r--macros/mm-ax_cxx_compile_stdcxx.m489
1 files changed, 78 insertions, 11 deletions
diff --git a/macros/mm-ax_cxx_compile_stdcxx.m4 b/macros/mm-ax_cxx_compile_stdcxx.m4
index ebd372f..7301d91 100644
--- a/macros/mm-ax_cxx_compile_stdcxx.m4
+++ b/macros/mm-ax_cxx_compile_stdcxx.m4
@@ -10,13 +10,13 @@
#
# Check for baseline language coverage in the compiler for the specified
# version of the C++ standard. If necessary, add switches to CXX and
-# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
-# or '14' (for the C++14 standard).
+# CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for
+# the respective C++ standard version.
#
# The second argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
-# preference for an extended mode.
+# preference for no added switch, and then for an extended mode.
#
# The third argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline support for the specified C++ standard is
@@ -35,6 +35,8 @@
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
+# Copyright (c) 2020 Jason Merrill <jason@redhat.com>
+# Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
@@ -47,12 +49,13 @@
#serial 11
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
-dnl (serial version number 13).
+dnl (serial version number 18).
AC_DEFUN([MM_AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
+ [$1], [20], [ax_cxx_compile_alternatives="20"],
[m4_fatal([invalid first argument `$1' to MM_AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
@@ -65,6 +68,16 @@ AC_DEFUN([MM_AX_CXX_COMPILE_STDCXX], [dnl
AC_LANG_PUSH([C++])dnl
ac_success=no
+ m4_if([$2], [], [dnl
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
+ ax_cv_cxx_compile_cxx$1,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [ax_cv_cxx_compile_cxx$1=yes],
+ [ax_cv_cxx_compile_cxx$1=no])])
+ if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
+ ac_success=yes
+ fi])
+
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
for alternative in ${ax_cxx_compile_alternatives}; do
@@ -94,9 +107,18 @@ AC_DEFUN([MM_AX_CXX_COMPILE_STDCXX], [dnl
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
dnl Cray's crayCC needs "-h std=c++11"
+ dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
for alternative in ${ax_cxx_compile_alternatives}; do
- for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
- cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
+ if test x"$switch" = xMSVC; then
+ dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
+ dnl with -std=c++17. We suffix the cache variable name with _MSVC to
+ dnl avoid this.
+ switch=-std:c++${alternative}
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
+ else
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ fi
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
@@ -143,7 +165,6 @@ m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_11],
_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
)
-
dnl Test body for checking C++14 support
m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_14],
@@ -151,12 +172,24 @@ m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_14],
_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)
+dnl Test body for checking C++17 support
+
m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_17],
_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
)
+dnl Test body for checking C++20 support
+
+m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_20],
+ _MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+ _MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
+ _MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_20
+)
+
+
dnl Tests for new features in C++11
m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
@@ -168,7 +201,11 @@ m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
#error "This is not a C++ compiler"
-#elif __cplusplus < 201103L
+// MSVC always sets __cplusplus to 199711L in older versions; newer versions
+// only set it correctly if /Zc:__cplusplus is specified as well as a
+// /std:c++NN switch:
+// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
+#elif __cplusplus < 201103L && !defined _MSC_VER
#error "This is not a C++11 compiler"
@@ -459,7 +496,7 @@ m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
#error "This is not a C++ compiler"
-#elif __cplusplus < 201402L
+#elif __cplusplus < 201402L && !defined _MSC_VER
#error "This is not a C++14 compiler"
@@ -583,7 +620,7 @@ m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
#error "This is not a C++ compiler"
-#elif __cplusplus < 201703L
+#elif __cplusplus < 201703L && !defined _MSC_VER
#error "This is not a C++17 compiler"
@@ -949,6 +986,36 @@ namespace cxx17
} // namespace cxx17
-#endif // __cplusplus < 201703L
+#endif // __cplusplus < 201703L && !defined _MSC_VER
+
+]])
+
+
+dnl Tests for new features in C++20
+
+m4_define([_MM_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 202002L && !defined _MSC_VER
+
+#error "This is not a C++20 compiler"
+
+#else
+
+#include <version>
+
+namespace cxx20
+{
+
+// As C++20 supports feature test macros in the standard, there is no
+// immediate need to actually test for feature availability on the
+// Autoconf side.
+
+} // namespace cxx20
+
+#endif // __cplusplus < 202002L && !defined _MSC_VER
]])