Add TDE_CXX_COMPILE_STDCXX macro to check and enforce C++ standard.

The macro is a simplified form of AX_CXX_COMPILE_STDCXX from autoconf.
To verify the C++ standard supported by the compiler, only the value
of the __cplusplus constant defined by the compiler is checked,
instead of testing examples of using individual C++ features.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/14/head
Slávek Banko 3 years ago
parent 133b3127ab
commit b9fb6ca397
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -6451,3 +6451,215 @@ EOF
AC_SUBST(LIBSQLITE3) AC_SUBST(LIBSQLITE3)
fi fi
]) ])
# ===========================================================================
#
# SYNOPSIS
#
# TDE_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# 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).
#
# 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 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
# required and that the macro should error out if no mode with that
# support is found. If specified 'optional', then configuration proceeds
# regardless, after defining HAVE_CXX${VERSION} if and only if a
# supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# 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 Slávek Banko <slavek.banko@axis.cz>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
dnl This macro is simplified version of the macro AX_CXX_COMPILE_STDCXX
AC_DEFUN([TDE_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [tde_cxx_compile_alternatives="11 0x"],
[$1], [14], [tde_cxx_compile_alternatives="14 1y"],
[$1], [17], [tde_cxx_compile_alternatives="17 1z"],
[m4_fatal([invalid first argument `$1' to TDE_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
[$2], [noext], [],
[m4_fatal([invalid second argument `$2' to TDE_CXX_COMPILE_STDCXX])])dnl
m4_if([$3], [], [tde_cxx_compile_cxx$1_required=true],
[$3], [mandatory], [tde_cxx_compile_cxx$1_required=true],
[$3], [optional], [tde_cxx_compile_cxx$1_required=false],
[m4_fatal([invalid third argument `$3' to TDE_CXX_COMPILE_STDCXX])])
AC_LANG_PUSH([C++])dnl
ac_success=no
m4_if([$2], [], [dnl
AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
tde_cv_cxx_compile_cxx$1,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_TDE_CXX_COMPILE_STDCXX_testbody_$1])],
[tde_cv_cxx_compile_cxx$1=yes],
[tde_cv_cxx_compile_cxx$1=no])])
if test x$tde_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 ${tde_cxx_compile_alternatives}; do
switch="-std=gnu++${alternative}"
cachevar=AS_TR_SH([tde_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_TDE_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
if eval test x\$$cachevar = xyes; then
CXX="$CXX $switch"
if test -n "$CXXCPP" ; then
CXXCPP="$CXXCPP $switch"
fi
ac_success=yes
break
fi
done
fi])
m4_if([$2], [ext], [], [dnl
if test x$ac_success = xno; then
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"
for alternative in ${tde_cxx_compile_alternatives}; do
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
cachevar=AS_TR_SH([tde_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_TDE_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
if eval test x\$$cachevar = xyes; then
CXX="$CXX $switch"
if test -n "$CXXCPP" ; then
CXXCPP="$CXXCPP $switch"
fi
ac_success=yes
break
fi
done
if test x$ac_success = xyes; then
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$tde_cxx_compile_cxx$1_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
fi
fi
if test x$ac_success = xno; then
HAVE_CXX$1=0
AC_MSG_NOTICE([No compiler with C++$1 support was found])
else
HAVE_CXX$1=1
AC_DEFINE(HAVE_CXX$1,1,
[define if the compiler supports basic C++$1 syntax])
fi
AC_SUBST(HAVE_CXX$1)
])
dnl Test body for checking C++11 support
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_11],
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_11
)
dnl Test body for checking C++14 support
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_14],
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_11
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_14
)
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_17],
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_11
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_14
_TDE_CXX_COMPILE_STDCXX_testbody_new_in_17
)
dnl Tests for new features in C++11
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
#error "This is not a C++11 compiler"
#endif // __cplusplus >= 201103L
]])
dnl Tests for new features in C++14
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201402L
#error "This is not a C++14 compiler"
#endif // __cplusplus >= 201402L
]])
dnl Tests for new features in C++17
m4_define([_TDE_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201703L
#error "This is not a C++17 compiler"
#endif // __cplusplus >= 201703L
]])

Loading…
Cancel
Save