Detect which C++ standard edition the compiler defaults to
Change-Id: I2991557a5cc74cd18e88ffff13f670bf25d5423e Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
parent
31fb4379c8
commit
3accdb8086
1
config.tests/common/c++default/c++default.cpp
Normal file
1
config.tests/common/c++default/c++default.cpp
Normal file
@ -0,0 +1 @@
|
||||
__cplusplus
|
14
config.tests/common/c++default/c++default.pro
Normal file
14
config.tests/common/c++default/c++default.pro
Normal file
@ -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
|
16
configure
vendored
16
configure
vendored
@ -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"
|
||||
|
@ -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,6 +3351,7 @@ bool Configure::tryCompileProject(const QString &projectPath, const QString &ext
|
||||
//cout << output << endl;
|
||||
|
||||
// clean up
|
||||
if (distClean)
|
||||
Environment::execute(command + " distclean 2>&1");
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user