From 100ae745826e3fe9c2b93659c89ea344194a1606 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Wed, 7 Sep 2016 23:14:59 +0100 Subject: [PATCH] TOOLS: Compile with c++11 by default if supported This also adds an option to disable the use of c++11 and compile with -ansi instead as we did before. But compilation of GUI tools with a recent version of g++ will break when using -ansi. --- configure | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 5cb81816..c80cb24f 100755 --- a/configure +++ b/configure @@ -85,6 +85,7 @@ _debug_build=auto _release_build=auto _verbose_build=no _enable_prof=no +_use_cxx11=yes # Default commands _ranlib=ranlib _strip=strip @@ -335,6 +336,7 @@ Special configuration feature: --host=HOST cross-compile to target HOST (arm-linux, ...) Optional Features: + --disable-c++11 disable building as C++11 when the compiler allows that --disable-debug disable building with debugging symbols --enable-Werror treat warnings as errors --enable-profiling enable profiling @@ -463,6 +465,12 @@ for ac_option in $@; do --disable-debug) _debug_build=no ;; + --enable-c++11) + _use_cxx11=yes + ;; + --disable-c++11) + _use_cxx11=no + ;; --enable-Werror) CXXFLAGS="$CXXFLAGS -Werror" ;; @@ -875,6 +883,18 @@ else echo found non-gcc compiler version ${cxx_version} fi +# +# Check whether the compiler supports C++11 +# +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 +fi + # # Setup compiler specific CXXFLAGS now that we know the compiler version. # Foremost, this means enabling various warnings. @@ -882,27 +902,37 @@ fi # if test "$have_gcc" = yes ; then if test "$_cxx_major" -ge "3" ; then - case $_host_os in - # newlib-based system include files suppress non-C89 function - # declarations under __STRICT_ANSI__ - amigaos* | android | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | wii | wince ) - ;; - *) - CXXFLAGS="$CXXFLAGS -ansi" - ;; - esac + # Try to use ANSI mode when C++11 is disabled. + if test "$_use_cxx11" = "no" ; then + case $_host_os in + # newlib-based system include files suppress non-C89 function + # declarations under __STRICT_ANSI__ + amigaos* | android | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | wii | wince ) + ;; + *) + CXXFLAGS="$CXXFLAGS -ansi" + ;; + esac + fi CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter" add_line_to_config_mk 'HAVE_GCC3 = 1' add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP' - fi; + fi if test "$_cxx_major" -eq 4 && test "$_cxx_minor" -ge 3 || \ test "$_cxx_major" -gt 4 ; then CXXFLAGS="$CXXFLAGS -Wno-empty-body" else CXXFLAGS="$CXXFLAGS -Wconversion" - fi; -fi; + fi +fi + +echo_n "Building as C++11... " +if test "$_use_cxx11" = "yes" ; then + CXXFLAGS="$CXXFLAGS -std=c++11" +fi +echo $_use_cxx11 + # By default, we add -pedantic to the CXXFLAGS to catch some potentially # non-portable constructs, like use of GNU extensions.