Detect which C++ standard edition the compiler defaults to
authorThiago Macieira <thiago.macieira@intel.com>
Sat, 1 Aug 2015 20:31:35 +0000 (13:31 -0700)
committerKai Koehne <kai.koehne@theqtcompany.com>
Tue, 25 Aug 2015 06:25:11 +0000 (06:25 +0000)
Change-Id: I2991557a5cc74cd18e88ffff13f670bf25d5423e
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
config.tests/common/c++default/c++default.cpp [new file with mode: 0644]
config.tests/common/c++default/c++default.pro [new file with mode: 0644]
configure
tools/configure/configureapp.cpp
tools/configure/configureapp.h

diff --git a/config.tests/common/c++default/c++default.cpp b/config.tests/common/c++default/c++default.cpp
new file mode 100644 (file)
index 0000000..018963b
--- /dev/null
@@ -0,0 +1 @@
+__cplusplus
diff --git a/config.tests/common/c++default/c++default.pro b/config.tests/common/c++default/c++default.pro
new file mode 100644 (file)
index 0000000..7e6bcef
--- /dev/null
@@ -0,0 +1,14 @@
+TEMPLATE = aux
+CONFIG -= qt c++11
+PREPROCESSOR_SOURCES += c++default.cpp
+
+preprocessor.commands = $(CXX) $(CXXFLAGS) $(INCPATH) -o $@ -E $<
+msvc:preprocessor.commands = $(CXX) $(CXXFLAGS) $(INCPATH) -E ${QMAKE_FILE_IN} > ${QMAKE_FILE_OUT}
+preprocessor.output = ${QMAKE_FILE_BASE}.ii
+preprocessor.input = PREPROCESSOR_SOURCES
+preprocessor.variable_out = GENERATED_FILES
+QMAKE_EXTRA_COMPILERS += preprocessor
+
+all.target = all
+all.depends += c++default.ii
+QMAKE_EXTRA_TARGETS += all
index d3e1f2e74325034577f072dd468e860538d53be8..afe741c30382fb03ee5b90ddf9195e31d4526fcb 100755 (executable)
--- a/configure
+++ b/configure
@@ -4343,6 +4343,21 @@ if [ "$CFG_CXX11" != "no" ]; then
     fi
 fi
 
+# Detect which edition of the C++ standard the compiler defaults to
+CFG_STDCXX_DEFAULT=199711
+if compileTest common/c++default "default C++ standard edition"; then
+    if [ -e "$outpath/config.tests/common/c++default/c++default.ii" ]; then
+        CFG_STDCXX_DEFAULT=`sed -n '/^[0-9]/s/L//p' "$outpath/config.tests/common/c++default/c++default.ii"`
+    else
+        if [ "$OPT_VERBOSE" = "yes" ]; then
+            echo "Failed to run the preprocessor, something is wrong with your compiler"
+        fi
+        if [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
+            exit 101
+        fi
+    fi
+fi
+
 # detect sse2 support
 if [ "${CFG_SSE2}" = "auto" ]; then
     if compileTest common/sse2 "sse2"; then
@@ -6894,6 +6909,7 @@ fi
 if [ -n "$RPATH_FLAGS" ]; then
     echo "QMAKE_RPATHDIR += $RPATH_FLAGS" >> "$QTCONFIG.tmp"
 fi
+echo "QT_COMPILER_STDCXX = $CFG_STDCXX_DEFAULT" >> "$QTCONFIG.tmp"
 if [ -n "$QT_GCC_MAJOR_VERSION" ]; then
     echo "QT_GCC_MAJOR_VERSION = $QT_GCC_MAJOR_VERSION" >> "$QTCONFIG.tmp"
     echo "QT_GCC_MINOR_VERSION = $QT_GCC_MINOR_VERSION" >> "$QTCONFIG.tmp"
index c4455eeb63a62a144ba888c7c71d28545b64594c..6a7a2174464be01e054eb46feee7b9fd0036c69c 100644 (file)
@@ -2343,6 +2343,22 @@ void Configure::autoDetection()
             dictionary["C++11"] = tryCompileProject("common/c++11") ? "yes" : "no";
     }
 
+    if (!dictionary["QMAKESPEC"].contains("msvc")) {
+        if (tryCompileProject("common/c++default", QString(), false)) {
+            QFile iiFile(buildPath + "/config.tests/common/c++default/c++default.ii");
+            if (iiFile.open(QIODevice::ReadOnly)) {
+                QString content = QString::fromUtf8(iiFile.readAll());
+                QRegExp expr("\\b([0-9]+)L\\b");
+                if (expr.indexIn(content) != -1)
+                    dictionary["CFG_STDCXX_DEFAULT"] = expr.cap(1);
+            }
+        }
+        if (dictionary["CFG_STDCXX_DEFAULT"].isEmpty()) {
+            cout << "Could not determine the C++ standard the compiler uses by default, assuming C++98." << endl;
+            dictionary["CFG_STDCXX_DEFAULT"] = "199711";
+        }
+    }
+
     // Style detection
     if (dictionary["STYLE_WINDOWSXP"] == "auto")
         dictionary["STYLE_WINDOWSXP"] = checkAvailability("STYLE_WINDOWSXP") ? defaultTo("STYLE_WINDOWSXP") : "no";
@@ -2681,6 +2697,8 @@ void Configure::generateOutputVars()
 
     if (dictionary[ "C++11" ] == "yes")
         qtConfig += "c++11";
+    if (!dictionary[ "CFG_STDCXX_DEFAULT" ].isEmpty())
+        qmakeVars += "QT_COMPILER_STDCXX = " + dictionary[ "CFG_STDCXX_DEFAULT" ];
 
     if (dictionary[ "USE_GOLD_LINKER" ] == "yes")
         qmakeConfig += "use_gold_linker";
@@ -3289,7 +3307,8 @@ void Configure::detectArch()
     QDir::setCurrent(oldpwd);
 }
 
-bool Configure::tryCompileProject(const QString &projectPath, const QString &extraOptions)
+bool Configure::tryCompileProject(const QString &projectPath, const QString &extraOptions,
+                                  bool distClean)
 {
     QString oldpwd = QDir::currentPath();
 
@@ -3332,7 +3351,8 @@ bool Configure::tryCompileProject(const QString &projectPath, const QString &ext
         //cout << output << endl;
 
         // clean up
-        Environment::execute(command + " distclean 2>&1");
+        if (distClean)
+            Environment::execute(command + " distclean 2>&1");
     }
 
     QDir::setCurrent(oldpwd);
index e58a0feb2b5d4a71c2521e2f185ef73256d5b791..de8d1a2469c615d240411f3b607d7060901a89d9 100644 (file)
@@ -158,7 +158,8 @@ private:
     void saveCmdLine();
 
     void addSysroot(QString *command);
-    bool tryCompileProject(const QString &projectPath, const QString &extraOptions = QString());
+    bool tryCompileProject(const QString &projectPath, const QString &extraOptions = QString(),
+                           bool distClean = true);
     bool compilerSupportsFlag(const QString &compilerAndArgs);
 
     void desc(const char *description, int startingAt = 0, int wrapIndent = 0);