From 3accdb8086cca78fc006cfbe0d8b6eb66ebcc307 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 1 Aug 2015 13:31:35 -0700 Subject: Detect which C++ standard edition the compiler defaults to Change-Id: I2991557a5cc74cd18e88ffff13f670bf25d5423e Reviewed-by: Kai Koehne --- config.tests/common/c++default/c++default.cpp | 1 + config.tests/common/c++default/c++default.pro | 14 ++++++++++++++ configure | 16 ++++++++++++++++ tools/configure/configureapp.cpp | 24 ++++++++++++++++++++++-- tools/configure/configureapp.h | 3 ++- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 config.tests/common/c++default/c++default.cpp create mode 100644 config.tests/common/c++default/c++default.pro diff --git a/config.tests/common/c++default/c++default.cpp b/config.tests/common/c++default/c++default.cpp new file mode 100644 index 0000000000..018963beb3 --- /dev/null +++ b/config.tests/common/c++default/c++default.cpp @@ -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 index 0000000000..7e6bcefe69 --- /dev/null +++ b/config.tests/common/c++default/c++default.pro @@ -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 diff --git a/configure b/configure index d3e1f2e743..afe741c303 100755 --- 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" diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index c4455eeb63..6a7a217446 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -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); diff --git a/tools/configure/configureapp.h b/tools/configure/configureapp.h index e58a0feb2b..de8d1a2469 100644 --- a/tools/configure/configureapp.h +++ b/tools/configure/configureapp.h @@ -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); -- cgit v1.2.3