summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-04-22 21:25:16 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-04-22 21:25:16 +0200
commitaeb1b0c9dfba7a3abc47dca709b639c6cdcaa459 (patch)
treeb56339bee5c8618d56be277d1d6420b2035cee8c
parentf026667287f1239227ae67f7d8d91cc0b3fa4228 (diff)
downloadqtbase-compiledb.tar.gz
Change-Id: I239f7f82780db7754a62bb20c2d377c844b187fe
-rw-r--r--qmake/generators/makefile.cpp58
-rw-r--r--qmake/generators/makefile.h2
2 files changed, 53 insertions, 7 deletions
diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp
index 2918a2ee58..5633955372 100644
--- a/qmake/generators/makefile.cpp
+++ b/qmake/generators/makefile.cpp
@@ -1107,13 +1107,7 @@ MakefileGenerator::write()
if (compileCommands) {
QFileInfo outputMakeFileInfo(fileInfo(Option::output.fileName()));
- QString compileCommandsFileName = "compile_commands";
- QString infix = outputMakeFileInfo.completeSuffix();
- if (!infix.isEmpty()) {
- compileCommandsFileName += '_';
- compileCommandsFileName += infix;
- }
- compileCommandsFileName += ".json";
+ QString compileCommandsFileName = CompileCommandRecorder::compilationDatabaseFileNameForMakefile(outputMakeFileInfo);
QFile f(compileCommandsFileName);
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
f.write(QJsonDocument(compileCommands->commands).toJson());
@@ -2719,6 +2713,44 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubT
}
}
+ if (project->isActiveConfig("create_compile_commands") && !targets.isEmpty()) {
+#if 1
+ QString commands;
+ commands += "sed";
+ for (QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it) {
+ if ((*it)->profile.isEmpty())
+ continue;
+ auto subtarget = *it;
+ QString out_directory = subtarget->out_directory;
+ if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep))
+ out_directory += Option::dir_sep;
+ commands += " " + out_directory + CompileCommandRecorder::compilationDatabaseFileNameForMakefile(fileInfo(subtarget->makefile));
+ project->values("create_compile_commands.recurse") += subtarget->name;
+ }
+
+ project->values("create_compile_commands.commands") += commands;
+ project->values("create_compile_commands.CONFIG") += "recursive";
+ project->values("create_compile_commands.recurse_target") += "create_compile_commands";
+ project->values("QMAKE_EXTRA_TARGETS") += "create_compile_commands";
+#else
+ t << "\ncreate_compile_commands:";
+ if(!targets.isEmpty()) {
+ t << "\n\tsed";
+ for (QList<SubTarget*>::Iterator it = targets.begin(); it != targets.end(); ++it) {
+ if ((*it)->profile.isEmpty())
+ continue;
+ auto subtarget = *it;
+ QString out_directory = subtarget->out_directory;
+ if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep))
+ out_directory += Option::dir_sep;
+ t << " " << out_directory + CompileCommandRecorder::compilationDatabaseFileNameForMakefile(fileInfo(subtarget->makefile));
+ }
+ t << " > compile_commands.json";
+ }
+ t << "\n";
+#endif
+ }
+
// user defined targets
const ProStringList &qut = project->values("QMAKE_EXTRA_TARGETS");
for (ProStringList::ConstIterator qut_it = qut.begin(); qut_it != qut.end(); ++qut_it) {
@@ -3502,4 +3534,16 @@ QString MakefileGenerator::shellQuote(const QString &str)
return isWindowsShell() ? IoUtils::shellQuoteWin(str) : IoUtils::shellQuoteUnix(str);
}
+QString CompileCommandRecorder::compilationDatabaseFileNameForMakefile(const QFileInfo &makeFileInfo)
+{
+ QString compileCommandsFileName = "compile_commands";
+ QString infix = makeFileInfo.completeSuffix();
+ if (!infix.isEmpty()) {
+ compileCommandsFileName += '_';
+ compileCommandsFileName += infix;
+ }
+ compileCommandsFileName += ".json";
+ return compileCommandsFileName;
+}
+
QT_END_NAMESPACE
diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h
index f81fc3cb54..9cc1550fb5 100644
--- a/qmake/generators/makefile.h
+++ b/qmake/generators/makefile.h
@@ -40,6 +40,7 @@
QT_BEGIN_NAMESPACE
+// ### rename to compilation database
struct CompileCommandRecorder
{
QJsonArray commands;
@@ -47,6 +48,7 @@ struct CompileCommandRecorder
// values are coded in the makefile and also supplied here, for expansion before writing
// compile_commands.json.
QHash<QString, QString> compilerVariables;
+ static QString compilationDatabaseFileNameForMakefile(const QFileInfo &makeFileInfo);
};
#ifdef Q_OS_WIN32