Skip to content

Commit

Permalink
qmake/vcxproj: Read C language standard from QMAKE_CFLAGS
Browse files Browse the repository at this point in the history
The vcxproj generator completely ignored QMAKE_CFLAGS and did only read
QMAKE_CXXFLAGS.  The msbuild-internal "cl compiler tool" contains the
flags for both, C and C++.  It is to risky to take all QMAKE_CFLAGS into
account for the "cl compiler tool", because this might collide with what
is specified in QMAKE_CXXFLAGS.  Therefore, we only read the
/std:... compiler option from QMAKE_CFLAGS and set the
LanguageStandard_C flag in the msbuild file.

Task-number: QTBUG-89296
Change-Id: I885061802c1350b293a7868d4c9a9367d30e2380
Reviewed-by: Alexandru Croitor <[email protected]>
(cherry picked from commit a6a216e)
  • Loading branch information
jobor committed Aug 30, 2021
1 parent 46a1616 commit ede7f85
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qmake/generators/win32/msvc_vcproj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <qcryptographichash.h>
#include <qhash.h>
#include <quuid.h>
#include <qregexp.h>

#include <stdlib.h>

Expand Down Expand Up @@ -1052,6 +1053,20 @@ void VcprojGenerator::initConfiguration()
initPreLinkEventTools();
}

// Filter from the given QMAKE_CFLAGS the options that are relevant
// for the vcxproj-global VCCLCompilerTool.
static ProStringList relevantCFlags(const ProStringList &flags)
{
ProStringList result;
static const QRegExp rex("^[/-]std:.*");
for (const ProString &flag : flags) {
if (rex.exactMatch(flag.toQString())) {
result.append(flag);
}
}
return result;
}

void VcprojGenerator::initCompilerTool()
{
QString placement = project->first("OBJECTS_DIR").toQString();
Expand All @@ -1074,6 +1089,7 @@ void VcprojGenerator::initCompilerTool()
conf.compiler.ForcedIncludeFiles = project->values("PRECOMPILED_HEADER").toQStringList();
}

conf.compiler.parseOptions(relevantCFlags(project->values("QMAKE_CFLAGS")));
conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));

if (project->isActiveConfig("windows"))
Expand Down

0 comments on commit ede7f85

Please sign in to comment.