CMake: Remove magic configuration from CMake

Get rid of magic configuration handling in the CMakeProjectManager.

* Use CMakeCache.txt as the sole source of truth, do not keep
  a shadow copy of configuration in the .user file
* Have initial CMake arguments that are easy to edit in batch
  (Fixes: QTCREATORBUG-18179) used whenever no CMakeCache.txt
  file is in the build directory. These allow for any thing that
  can be passed to CMake on the command line.
  (Fixes: QTCREATORBUG-16296)
* Ask when changes to CMake configuration were not applied
  (Fixes: QTCREATORBUG-18504)
* Run cmake with arguments effecting its configuration only when
  the CMake settings are changed in the UI, run CMake without any
  special arguments in all other cases.
* Get rid of the confusing dialog used to keep settings in sync between
  what is in CMakeCache.txt and Creator (Fixes: QTCREATORBUG-23218)

Change-Id: I26d55be7df733f084f5691ecf7d7b4352f58b8e7
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Tobias Hunger
2020-04-02 14:49:05 +02:00
parent c02a0037d5
commit 01b0d4f8f5
18 changed files with 433 additions and 505 deletions

View File

@@ -99,47 +99,63 @@ void FileApiReader::resetData()
m_knownHeaders.clear();
}
void FileApiReader::parse(bool forceCMakeRun, bool forceConfiguration)
void FileApiReader::parse(bool forceCMakeRun,
bool forceInitialConfiguration,
bool forceExtraConfiguration)
{
qCDebug(cmakeFileApiMode) << "Parse called with arguments: ForceCMakeRun:" << forceCMakeRun
<< " - forceConfiguration:" << forceConfiguration;
<< " - forceConfiguration:" << forceInitialConfiguration
<< " - forceExtraConfiguration:" << forceExtraConfiguration;
startState();
if (forceConfiguration) {
// Initial create:
qCDebug(cmakeFileApiMode) << "FileApiReader: Starting CMake with forced configuration.";
const FilePath path = m_parameters.workDirectory.pathAppended("qtcsettings.cmake");
startCMakeState(QStringList({QString("-C"), path.toUserOutput()}));
// Keep m_isParsing enabled!
return;
}
const QStringList args = (forceInitialConfiguration ? m_parameters.initialCMakeArguments
: QStringList())
+ (forceExtraConfiguration ? m_parameters.extraCMakeArguments
: QStringList());
qCDebug(cmakeFileApiMode) << "Parameters request these CMake arguments:" << args;
const QFileInfo replyFi = FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory);
// Only need to update when one of the following conditions is met:
// * The user forces the update,
// * The user forces the cmake run,
// * The user provided arguments,
// * There is no reply file,
// * One of the cmakefiles is newer than the replyFile and the user asked
// for creator to run CMake as needed,
// * A query file is newer than the reply file
const bool mustUpdate = forceCMakeRun || !replyFi.exists()
|| (m_parameters.cmakeTool() && m_parameters.cmakeTool()->isAutoRun()
&& anyOf(m_cmakeFiles,
[&replyFi](const FilePath &f) {
return f.toFileInfo().lastModified()
> replyFi.lastModified();
}))
|| anyOf(FileApiParser::cmakeQueryFilePaths(m_parameters.workDirectory), [&replyFi](const QString &qf) {
return QFileInfo(qf).lastModified() > replyFi.lastModified();
});
const bool hasArguments = !args.isEmpty();
const bool replyFileMissing = !replyFi.exists();
const bool cmakeFilesChanged = m_parameters.cmakeTool() && m_parameters.cmakeTool()->isAutoRun()
&& anyOf(m_cmakeFiles, [&replyFi](const FilePath &f) {
return f.toFileInfo().lastModified()
> replyFi.lastModified();
});
const bool queryFileChanged = anyOf(FileApiParser::cmakeQueryFilePaths(
m_parameters.workDirectory),
[&replyFi](const QString &qf) {
return QFileInfo(qf).lastModified()
> replyFi.lastModified();
});
const bool mustUpdate = forceCMakeRun || hasArguments || replyFileMissing || cmakeFilesChanged
|| queryFileChanged;
qCDebug(cmakeFileApiMode) << QString("Do I need to run CMake? %1 "
"(force: %2 | args: %3 | missing reply: %4 | "
"cmakeFilesChanged: %5 | "
"queryFileChanged: %6)")
.arg(mustUpdate)
.arg(forceCMakeRun)
.arg(hasArguments)
.arg(replyFileMissing)
.arg(cmakeFilesChanged)
.arg(queryFileChanged);
if (mustUpdate) {
qCDebug(cmakeFileApiMode) << "FileApiReader: Starting CMake with no arguments.";
startCMakeState(QStringList());
// Keep m_isParsing enabled!
return;
qCDebug(cmakeFileApiMode) << QString("FileApiReader: Starting CMake with \"%1\".")
.arg(args.join("\", \""));
startCMakeState(args);
} else {
endState(replyFi);
}
endState(replyFi);
}
void FileApiReader::stop()