Skip to content

Commit

Permalink
Fix precompiled headers with clang-cl
Browse files Browse the repository at this point in the history
Clang-cl couldn't find the header given to it by -FI when it isn't in
any of the included directories.

Additionally clang-cl 8 has a bug with exported templated classes with
inline methods that causes it to have missing symbols at link time. We
work around this.

Fixes: QTBUG-74563
Change-Id: I7becf05fa8edb07bd4cefe12bee3737e5e1dfa14
Reviewed-by: Yuhang Zhao <[email protected]>
Reviewed-by: Mårten Nordheim <[email protected]>
Reviewed-by: Kai Koehne <[email protected]>
  • Loading branch information
Allan Sandfeld Jensen committed Apr 9, 2019
1 parent fe7a8d6 commit eaf2042
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 0 additions & 3 deletions mkspecs/win32-clang-msvc/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
# Leave QMAKE_LFLAGS_LTCG empty because lld-link doesn't need any additional parameters
QMAKE_LFLAGS_LTCG =

# Precompiled headers are not supported yet by clang
CONFIG -= precompile_header

load(qt_config)
16 changes: 12 additions & 4 deletions qmake/generators/win32/msvc_nmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ QString NmakeMakefileGenerator::var(const ProKey &value) const
|| value == "QMAKE_RUN_CXX_IMP"
|| value == "QMAKE_RUN_CXX");
if ((isRunCpp && usePCH) || (isRunC && usePCHC)) {
QFileInfo precompHInfo(fileInfo(precompH));
QString precompH_f = escapeFilePath(precompHInfo.fileName());
QString precompH_f = escapeFilePath(fileFixify(precompH, FileFixifyBackwards));
QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
.arg(precompH_f, precompH_f, escapeFilePath(isRunC ? precompPchC : precompPch));
// ### For clang_cl 8 we force inline methods to be compiled here instead
// linking them from a pch.o file. We do this by pretending we are also doing
// the pch.o generation step.
if (project->isActiveConfig("clang_cl"))
precompRule += QString(" -Xclang -building-pch-with-obj");
QString p = MakefileGenerator::var(value);
p.replace(QLatin1String("-c"), precompRule);
return p;
Expand Down Expand Up @@ -230,7 +234,10 @@ void NmakeMakefileGenerator::init()
precompObj = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
precompPch = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch.pch";
// Add linking of precompObj (required for whole precompiled classes)
project->values("OBJECTS") += precompObj;
// ### For clang_cl we currently let inline methods be generated in the normal objects,
// since the PCH object is buggy (as of clang 8.0.0)
if (!project->isActiveConfig("clang_cl"))
project->values("OBJECTS") += precompObj;
// Add pch file to cleanup
project->values("QMAKE_CLEAN") += precompPch;
// Return to variable pool
Expand All @@ -240,7 +247,8 @@ void NmakeMakefileGenerator::init()
if (usePCHC) {
precompObjC = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch_c" + Option::obj_ext;
precompPchC = var("PRECOMPILED_DIR") + project->first("TARGET") + "_pch_c.pch";
project->values("OBJECTS") += precompObjC;
if (!project->isActiveConfig("clang_cl"))
project->values("OBJECTS") += precompObjC;
project->values("QMAKE_CLEAN") += precompPchC;
project->values("PRECOMPILED_OBJECT_C") = ProStringList(precompObjC);
project->values("PRECOMPILED_PCH_C") = ProStringList(precompPchC);
Expand Down

0 comments on commit eaf2042

Please sign in to comment.