forked from qt-creator/qt-creator
CMake: Write creators settings into build directory
Write a file qtcsettings.cmake into the build directory. This file contains all applicable CMake configuration settings that creator wants to set. Use "cmake -C qtcsettings.cmake .." to reconfigure on the command line to make use of this file. Change-Id: I4a69d082c50bb66e60b4eec1b3155df53e00734d Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -231,6 +231,28 @@ bool BuildDirManager::hasConfigChanged()
|
||||
return mustReparse || kcit != targetConfig.constEnd();
|
||||
}
|
||||
|
||||
void BuildDirManager::writeConfigurationIntoBuildDirectory(const Utils::MacroExpander *expander)
|
||||
{
|
||||
QTC_ASSERT(expander, return );
|
||||
|
||||
const FilePath buildDir = workDirectory(m_parameters);
|
||||
QTC_ASSERT(buildDir.exists(), return );
|
||||
|
||||
const FilePath settingsFile = buildDir.pathAppended("qtcsettings.cmake");
|
||||
|
||||
QByteArray contents;
|
||||
contents.append("# This file is managed by Qt Creator, do not edit!\n\n");
|
||||
contents.append(
|
||||
transform(m_parameters.configuration,
|
||||
[expander](const CMakeConfigItem &item) { return item.toCMakeSetLine(expander); })
|
||||
.join('\n')
|
||||
.toUtf8());
|
||||
|
||||
QFile file(settingsFile.toString());
|
||||
QTC_ASSERT(file.open(QFile::WriteOnly | QFile::Truncate), return );
|
||||
file.write(contents);
|
||||
}
|
||||
|
||||
bool BuildDirManager::isParsing() const
|
||||
{
|
||||
return m_reader && m_reader->isParsing();
|
||||
@@ -358,6 +380,8 @@ void BuildDirManager::parse()
|
||||
}
|
||||
}
|
||||
|
||||
writeConfigurationIntoBuildDirectory(m_parameters.expander);
|
||||
|
||||
qCDebug(cmakeBuildDirManagerLog) << "Asking reader to parse";
|
||||
m_reader->parse(reparseParameters & REPARSE_FORCE_CMAKE_RUN,
|
||||
reparseParameters & REPARSE_FORCE_CONFIGURATION);
|
||||
|
||||
@@ -127,6 +127,7 @@ private:
|
||||
|
||||
bool hasConfigChanged();
|
||||
|
||||
void writeConfigurationIntoBuildDirectory(const Utils::MacroExpander *expander);
|
||||
|
||||
void becameDirty();
|
||||
|
||||
|
||||
@@ -149,6 +149,24 @@ CMakeConfigItem::Type CMakeConfigItem::typeStringToType(const QByteArray &type)
|
||||
return CMakeConfigItem::INTERNAL;
|
||||
}
|
||||
|
||||
QString CMakeConfigItem::typeToTypeString(const CMakeConfigItem::Type t)
|
||||
{
|
||||
switch (t) {
|
||||
case CMakeProjectManager::CMakeConfigItem::FILEPATH:
|
||||
return "FILEPATH";
|
||||
case CMakeProjectManager::CMakeConfigItem::PATH:
|
||||
return "PATH";
|
||||
case CMakeProjectManager::CMakeConfigItem::STRING:
|
||||
return "STRING";
|
||||
case CMakeProjectManager::CMakeConfigItem::INTERNAL:
|
||||
return "INTERNAL";
|
||||
case CMakeProjectManager::CMakeConfigItem::STATIC:
|
||||
return "STATIC";
|
||||
case CMakeConfigItem::BOOL:
|
||||
return "BOOL";
|
||||
}
|
||||
}
|
||||
|
||||
Utils::optional<bool> CMakeConfigItem::toBool(const QByteArray &value)
|
||||
{
|
||||
// Taken from CMakes if(<constant>) documentation:
|
||||
@@ -367,6 +385,18 @@ QString CMakeConfigItem::toArgument(const Utils::MacroExpander *expander) const
|
||||
return "-D" + toString(expander);
|
||||
}
|
||||
|
||||
QString CMakeConfigItem::toCMakeSetLine(const Utils::MacroExpander *expander) const
|
||||
{
|
||||
if (isUnset) {
|
||||
return QString("unset(\"%1\" CACHE)").arg(QString::fromUtf8(key));
|
||||
}
|
||||
return QString("set(\"%1\" \"%2\" CACHE \"%3\" \"%4\" FORCE)")
|
||||
.arg(QString::fromUtf8(key))
|
||||
.arg(expandedValue(expander))
|
||||
.arg(typeToTypeString(type))
|
||||
.arg(QString::fromUtf8(documentation));
|
||||
}
|
||||
|
||||
bool CMakeConfigItem::operator==(const CMakeConfigItem &o) const
|
||||
{
|
||||
// type, isAdvanced and documentation do not matter for a match!
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
const QList<CMakeConfigItem> &input);
|
||||
static QStringList cmakeSplitValue(const QString &in, bool keepEmpty = false);
|
||||
static Type typeStringToType(const QByteArray &typeString);
|
||||
static QString typeToTypeString(const Type t);
|
||||
static Utils::optional<bool> toBool(const QByteArray &value);
|
||||
bool isNull() const { return key.isEmpty(); }
|
||||
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
static QList<CMakeConfigItem> itemsFromFile(const Utils::FilePath &input, QString *errorMessage);
|
||||
QString toString(const Utils::MacroExpander *expander = nullptr) const;
|
||||
QString toArgument(const Utils::MacroExpander *expander = nullptr) const;
|
||||
QString toCMakeSetLine(const Utils::MacroExpander *expander = nullptr) const;
|
||||
|
||||
bool operator==(const CMakeConfigItem &o) const;
|
||||
|
||||
|
||||
@@ -84,13 +84,6 @@ CMakeProcess::~CMakeProcess()
|
||||
}
|
||||
}
|
||||
|
||||
QStringList CMakeProcess::toArguments(const CMakeConfig &config,
|
||||
const Utils::MacroExpander *expander) {
|
||||
return Utils::transform(config, [expander](const CMakeConfigItem &i) -> QString {
|
||||
return i.toArgument(expander);
|
||||
});
|
||||
}
|
||||
|
||||
void CMakeProcess::run(const BuildDirParameters ¶meters, const QStringList &arguments)
|
||||
{
|
||||
QTC_ASSERT(!m_process && !m_parser && !m_future, return);
|
||||
|
||||
@@ -47,8 +47,6 @@ public:
|
||||
CMakeProcess(const CMakeProcess&) = delete;
|
||||
~CMakeProcess();
|
||||
|
||||
static QStringList toArguments(const CMakeConfig &config, const Utils::MacroExpander *expander);
|
||||
|
||||
void run(const BuildDirParameters ¶meters, const QStringList &arguments);
|
||||
|
||||
QProcess::ProcessState state() const;
|
||||
|
||||
@@ -131,8 +131,8 @@ void FileApiReader::parse(bool forceCMakeRun, bool forceConfiguration)
|
||||
if (forceConfiguration) {
|
||||
// Initial create:
|
||||
qCDebug(cmakeFileApiMode) << "FileApiReader: Starting CMake with forced configuration.";
|
||||
startCMakeState(
|
||||
CMakeProcess::toArguments(m_parameters.configuration, m_parameters.expander));
|
||||
const FilePath path = m_parameters.buildDirectory.pathAppended("qtcsettings.cmake");
|
||||
startCMakeState(QStringList({QString("-C"), path.toUserOutput()}));
|
||||
// Keep m_isParsing enabled!
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ void TeaLeafReader::parse(bool forceCMakeRun, bool forceConfiguration)
|
||||
const QFileInfo cbpFileFi = cbpFile.isEmpty() ? QFileInfo() : QFileInfo(cbpFile);
|
||||
if (!cbpFileFi.exists() || forceConfiguration) {
|
||||
// Initial create:
|
||||
startCMake(CMakeProcess::toArguments(m_parameters.configuration, m_parameters.expander));
|
||||
const FilePath path = m_parameters.buildDirectory.pathAppended("qtcsettings.cmake");
|
||||
startCMake(QStringList({QString("-C"), path.toUserOutput()}));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user