configure: check for -std=c++11 support and enable st/mesa test accordingly
authorGert Wollny <gw.fossdev@gmail.com>
Wed, 18 Oct 2017 15:05:25 +0000 (17:05 +0200)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 8 Nov 2017 16:03:34 +0000 (16:03 +0000)
Add a check that tests whether the c++ compiler supports c++11, either
by default, by adding the compiler flag -std=c++11, or by adding a
compiler flag that the user has specified via the environment variable
CXX11_CXXFLAGS.

The test only does a very shallow check of c++11 support, i.e. it tests
whether the define  __cplusplus >= 201103L to confirm language support
by the compiler, and it checks whether the header <tuple> is available
to test the availability of the c++11 standard library.

A make file conditional HAVE_STD_CXX11 is provided that is used in this
patch to enable the test in st/mesa if C++11 support is available.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102665
Acked-by: Emil Velikov <emil.velikov@collabora.com>
configure.ac
src/mesa/state_tracker/tests/Makefile.am

index c69c7d6b0c9deedc05877dbd247b51680bfad83e..14236c9dc990beb4ca4f6dfc795dd735aac94c95 100644 (file)
@@ -111,6 +111,10 @@ dnl Check for progs
 AC_PROG_CPP
 AC_PROG_CC
 AC_PROG_CXX
+dnl add this here, so the help for this environmnet variable is close to
+dnl other CC/CXX flags related help
+AC_ARG_VAR([CXX11_CXXFLAGS], [Compiler flag to enable C++11 support (only needed if not
+                              enabled by default and different  from -std=c++11)])
 AM_PROG_CC_C_O
 AM_PROG_AS
 AX_CHECK_GNU_MAKE
@@ -120,6 +124,7 @@ AC_PROG_MKDIR_P
 
 AC_SYS_LARGEFILE
 
+
 LT_PREREQ([2.2])
 LT_INIT([disable-static])
 
@@ -327,6 +332,56 @@ if test "x$GCC" = xyes; then
     fi
 fi
 
+dnl
+dnl Check whether C++11 is supported, if the environment variable
+dnl CXX11_CXXFLAGS is set it takes precedence.
+dnl
+
+AC_LANG_PUSH([C++])
+
+check_cxx11_available() {
+    output_support=$1
+    AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([
+             #if !(__cplusplus >= 201103L)
+             #error
+             #endif
+             #include <tuple>
+        ])
+    ], [
+         AC_MSG_RESULT(yes)
+         cxx11_support=yes
+    ], AC_MSG_RESULT(no))
+    eval "$output_support=\$cxx11_support"
+}
+
+HAVE_CXX11=no
+save_CXXFLAGS="$CXXFLAGS"
+
+dnl If the user provides a flag to enable c++11, then we test only this
+if test "x$CXX11_CXXFLAGS" != "x"; then
+   CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
+   AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
+   check_cxx11_available HAVE_CXX11
+else
+   dnl test whether c++11 is enabled by default
+   AC_MSG_CHECKING(whether c++11 is enabled by default)
+   check_cxx11_available HAVE_CXX11
+
+   dnl C++11 not enabled by default, test whether -std=c++11 does the job
+   if test "x$HAVE_CXX11" != "xyes"; then
+       CXX11_CXXFLAGS=-std=c++11
+       CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
+       AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
+       check_cxx11_available HAVE_CXX11
+   fi
+fi
+
+CXXFLAGS="$save_CXXFLAGS"
+AM_CONDITIONAL(HAVE_STD_CXX11, test "x$HAVE_CXX11" = "xyes")
+AC_SUBST(CXX11_CXXFLAGS)
+AC_LANG_POP([C++])
+
 dnl even if the compiler appears to support it, using visibility attributes isn't
 dnl going to do anything useful currently on cygwin apart from emit lots of warnings
 case "$host_os" in
@@ -3114,6 +3169,7 @@ defines=`echo $DEFINES | $SED 's/^ *//;s/  */ /;s/ *$//'`
 echo ""
 echo "        CFLAGS:          $cflags"
 echo "        CXXFLAGS:        $cxxflags"
+echo "        CXX11_CXXFLAGS:  $CXX11_CXXFLAGS"
 echo "        LDFLAGS:         $ldflags"
 echo "        Macros:          $defines"
 echo ""
index f32957608e730d93331d0e022ad6ea1ff4ae1d3d..6c58d3676949085454db067911afac23fd00fc3d 100644 (file)
@@ -5,7 +5,7 @@ AM_CFLAGS = \
 
 AM_CXXFLAGS = \
        $(GALLIUM_DRIVER_CXXFLAGS) \
-       -std=c++11
+       $(CXX11_CXXFLAGS)
 
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/gtest/include \
@@ -15,8 +15,10 @@ AM_CPPFLAGS = \
        -I$(top_builddir)/src/compiler/glsl \
        $(DEFINES)
 
+if HAVE_STD_CXX11
 TESTS = st-renumerate-test
 check_PROGRAMS = st-renumerate-test
+endif
 
 st_renumerate_test_SOURCES =                   \
        test_glsl_to_tgsi_lifetime.cpp