Skip to content

Commit

Permalink
TOOLS: Compile with c++11 by default if supported
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
criezy committed Sep 7, 2016
1 parent 03fc925 commit 100ae74
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
;;
Expand Down Expand Up @@ -875,34 +883,56 @@ 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.
# In addition, we set CXX_UPDATE_DEP_FLAG for GCC >= 3.0 and for ICC.
#
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.
Expand Down

0 comments on commit 100ae74

Please sign in to comment.