Permalink
Browse files

BUILD: Add improved automatic detection of C++ standard version support

This detects and addresses a problem with the AmigaOS compiler that
prevents standard C++ versions from working correctly due to a
missing vsnprintf.
  • Loading branch information...
csnover authored and ccawley2011 committed Dec 5, 2017
1 parent 9033038 commit 563970790fcf0eb9834b10bf2d4c34aa2f6ef93f
Showing with 59 additions and 17 deletions.
  1. +59 −17 configure
@@ -165,7 +165,7 @@ _libunity=auto
_debug_build=auto
_release_build=auto
_optimizations=auto
_use_cxx11=yes
_cxx_std=c++14
_verbose_build=no
_text_console=no
_mt32emu=yes
@@ -1321,7 +1321,7 @@ for ac_option in $@; do
--enable-c++11)
;;
--disable-c++11|--force-c++98)
_use_cxx11=no
_cxx_std=no
;;
--enable-debug)
_debug_build=yes
@@ -2037,15 +2037,21 @@ if test "$cxx_verc_fail" = yes ; then
fi

#
# Check whether the compiler supports C++11
# Check C++ version support
#
have_cxx11=no
cat > $TMPC << EOF
int main(int argc, char *argv[]) { if (argv == nullptr) return -1; else return 0; }
EOF
cc_check -std=c++11 && have_cxx11=yes
if test "$_use_cxx11" = "yes" ; then
_use_cxx11=$have_cxx11
if test "$_cxx_std" = "no"; then
_cxx_std=
elif echo "int main() { return 0'000; }" > $TMPC && cc_check -std=c++14 ; then
_cxx_std=c++14
elif echo "int main(int argc, char *argv[]) { if (argv == nullptr) return -1; else return 0; }" > $TMPC && cc_check -std=c++11 ; then
_cxx_std=c++11
elif echo "int main() { return 0; }" > $TMPC && cc_check -std=c++03 ; then
_cxx_std=c++03
elif echo "int main() { return 0; }" > $TMPC && cc_check ; then
_cxx_std=
else
echo "ERROR: compiler is broken!"
exit 1
fi

#
@@ -2055,8 +2061,7 @@ fi
#
if test "$have_gcc" = yes ; then
if test "$_cxx_major" -ge "3" ; then
# Try to use ANSI mode when C++11 is disabled.
if test "$_use_cxx11" = "no" ; then
if test "$_cxx_std" = "" ; then
case $_host_os in
# newlib-based system include files suppress non-C89 function
# declarations under __STRICT_ANSI__
@@ -2066,6 +2071,41 @@ if test "$have_gcc" = yes ; then
append_var CXXFLAGS "-ansi"
;;
esac
else
need_gnu=no
gnu_std=`echo $_cxx_std | sed 's/c++/gnu++/'`

# This is only a problem until we can use variadic templates (i.e.
# C++11 is the minimum baseline), at which point vsnprintf goes
# away, or until the AmigaOS standard library is fixed:
# https://github.com/sba1/adtools/issues/19
echocheck "whether vsnprintf needs -std=gnu"
cat > $TMPC << EOF
#include <stdarg.h>
#include <stdio.h>
int foo(const char *fmt, ...) {
va_list list;
va_start(list, fmt);
char buf[1];
vsnprintf(buf, 1, fmt, list);
va_end(list);
}
int main(void) { foo(""); return 0; }
EOF
if ! cc_check_no_clean -std=$_cxx_std ; then
if ! cc_check_no_clean -std=$gnu_std ; then
echo "vsprintf is broken"
exit 1
else
need_gnu=yes
fi
fi
cc_check_clean
echo $need_gnu

if test "$need_gnu" = "yes"; then
_cxx_std=$gnu_std
fi
fi
append_var CXXFLAGS "-W -Wno-unused-parameter"
add_line_to_config_mk 'HAVE_GCC3 = 1'
@@ -2083,13 +2123,15 @@ elif test "$have_icc" = yes ; then
fi;

#
# Update status about C++11 mode
# Update status about C++ language standard
#
echo_n "Building as C++11... "
if test "$_use_cxx11" = "yes" ; then
append_var CXXFLAGS "-std=c++11"
echocheck "best C++ language standard"
if test "$_cxx_std" != "" ; then
append_var CXXFLAGS "-std=$_cxx_std"
echo $_cxx_std
else
echo "ancient"
fi
echo $_use_cxx11

# By default, we add -pedantic to the CXXFLAGS to catch some potentially
# non-portable constructs, like use of GNU extensions.

0 comments on commit 5639707

Please sign in to comment.