forked from qt-creator/qt-creator
CMakePM: Update missing expandable CMake variables at project load
The following variables:
"CMAKE_C_COMPILER",
"CMAKE_CXX_COMPILER",
"QT_QMAKE_EXECUTABLE",
"QT_HOST_PATH",
"CMAKE_PREFIX_PATH",
"CMAKE_FIND_ROOT_PATH",
"CMAKE_PROJECT_INCLUDE_BEFORE",
"CMAKE_TOOLCHAIN_FILE"
will be checked to see if the existing values have the same values
from the initial cmake parameters list.
Only the CMakeCache.txt values that do not exist on the file system
will be updated.
If not, the updated value will be presented in the dialog for upgrade,
or marked as bold in the settings dialog.
CMAKE_PROJECT_INCLUDE_BEFORE is dependent on Qt Creator version / path
and needs to be updated.
Fixes: QTCREATORBUG-24443
Change-Id: I1eeb44df3a7914051084ef405af5f5621cc5a4e2
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -691,6 +691,8 @@ void CMakeBuildSystem::updateProjectData()
|
||||
}
|
||||
updateQmlJSCodeModel(extraHeaderPaths, moduleMappings);
|
||||
}
|
||||
updateInitialCMakeExpandableVars();
|
||||
|
||||
emit cmakeBuildConfiguration()->buildTypeChanged();
|
||||
|
||||
qCDebug(cmakeBuildSystemLog) << "All CMake project data up to date.";
|
||||
@@ -1243,5 +1245,67 @@ void CMakeBuildSystem::updateQmlJSCodeModel(const QStringList &extraHeaderPaths,
|
||||
modelManager->updateProjectInfo(projectInfo, p);
|
||||
}
|
||||
|
||||
void CMakeBuildSystem::updateInitialCMakeExpandableVars()
|
||||
{
|
||||
const CMakeConfig &cm = cmakeBuildConfiguration()->configurationFromCMake();
|
||||
const CMakeConfig &initialConfig =
|
||||
CMakeConfigItem::itemsFromArguments(cmakeBuildConfiguration()->initialCMakeArguments());
|
||||
|
||||
CMakeConfig config;
|
||||
|
||||
// Replace path values that do not exist on file system
|
||||
const QByteArrayList singlePathList = {
|
||||
"CMAKE_C_COMPILER",
|
||||
"CMAKE_CXX_COMPILER",
|
||||
"QT_QMAKE_EXECUTABLE",
|
||||
"QT_HOST_PATH",
|
||||
"CMAKE_PROJECT_INCLUDE_BEFORE",
|
||||
"CMAKE_TOOLCHAIN_FILE"
|
||||
};
|
||||
for (const auto &var : singlePathList) {
|
||||
auto it = std::find_if(cm.cbegin(), cm.cend(), [var](const CMakeConfigItem &item) {
|
||||
return item.key == var;
|
||||
});
|
||||
|
||||
if (it != cm.cend()) {
|
||||
const QByteArray initialValue = CMakeConfigItem::expandedValueOf(kit(), var, initialConfig).toUtf8();
|
||||
if (!initialValue.isEmpty()
|
||||
&& it->value != initialValue
|
||||
&& !FilePath::fromString(QString::fromUtf8(it->value)).exists()) {
|
||||
CMakeConfigItem item(*it);
|
||||
item.value = initialValue;
|
||||
|
||||
config << item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepend new values to existing path lists
|
||||
const QByteArrayList multiplePathList = {
|
||||
"CMAKE_PREFIX_PATH",
|
||||
"CMAKE_FIND_ROOT_PATH"
|
||||
};
|
||||
for (const auto &var : multiplePathList) {
|
||||
auto it = std::find_if(cm.cbegin(), cm.cend(), [var](const CMakeConfigItem &item) {
|
||||
return item.key == var;
|
||||
});
|
||||
|
||||
if (it != cm.cend()) {
|
||||
const QByteArray initialValue = CMakeConfigItem::expandedValueOf(kit(), var, initialConfig).toUtf8();
|
||||
if (!initialValue.isEmpty() && !it->value.contains(initialValue)) {
|
||||
CMakeConfigItem item(*it);
|
||||
item.value = initialValue;
|
||||
item.value.append(";");
|
||||
item.value.append(it->value);
|
||||
|
||||
config << item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.isEmpty())
|
||||
emit cmakeBuildConfiguration()->configurationChanged(config);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
Reference in New Issue
Block a user