forked from qt-creator/qt-creator
CMakePM: Improve CMake presets kit config hashing
Amends a3153c535d
QT_QMAKE_EXECUTABLE was not taken into consideration and this would
result in not matching kits.
Also Visual Studio generator will not have a CMAKE_C|XX_COMPILER values
in the cache.
On Windows there could be paths with "C:" vs "c:" and the hashes again
wouldn't match.
Change-Id: I5da5fafbd29f3d1fd8c9615c41b7659e63c30ff1
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1145,7 +1145,10 @@ void CMakeConfigurationKitAspect::setKitDefaultConfigHash(ProjectExplorer::Kit *
|
||||
expanded.value = item.expandedValue(k).toUtf8();
|
||||
return expanded;
|
||||
});
|
||||
const QByteArray kitHash = computeDefaultConfigHash(defaultConfigExpanded);
|
||||
const CMakeTool *const tool = CMakeKitAspect::cmakeTool(k);
|
||||
const QByteArray kitHash = computeDefaultConfigHash(defaultConfigExpanded,
|
||||
tool ? tool->cmakeExecutable()
|
||||
: FilePath());
|
||||
|
||||
CMakeConfig config = configuration(k);
|
||||
config.append(CMakeConfigItem(QTC_KIT_DEFAULT_CONFIG_HASH, CMakeConfigItem::INTERNAL, kitHash));
|
||||
@@ -1161,7 +1164,8 @@ CMakeConfigItem CMakeConfigurationKitAspect::kitDefaultConfigHashItem(const Proj
|
||||
});
|
||||
}
|
||||
|
||||
QByteArray CMakeConfigurationKitAspect::computeDefaultConfigHash(const CMakeConfig &config)
|
||||
QByteArray CMakeConfigurationKitAspect::computeDefaultConfigHash(const CMakeConfig &config,
|
||||
const FilePath &cmakeBinary)
|
||||
{
|
||||
const CMakeConfig defaultConfig = defaultConfiguration(nullptr);
|
||||
const QByteArray configValues = std::accumulate(defaultConfig.begin(),
|
||||
@@ -1171,7 +1175,11 @@ QByteArray CMakeConfigurationKitAspect::computeDefaultConfigHash(const CMakeConf
|
||||
const CMakeConfigItem &item) {
|
||||
return sum += config.valueOf(item.key);
|
||||
});
|
||||
return QCryptographicHash::hash(configValues, QCryptographicHash::Md5).toHex();
|
||||
return QCryptographicHash::hash(cmakeBinary.caseSensitivity() == Qt::CaseInsensitive
|
||||
? configValues.toLower()
|
||||
: configValues,
|
||||
QCryptographicHash::Md5)
|
||||
.toHex();
|
||||
}
|
||||
|
||||
QVariant CMakeConfigurationKitAspect::defaultValue(const Kit *k) const
|
||||
|
@@ -93,7 +93,8 @@ public:
|
||||
|
||||
static void setKitDefaultConfigHash(ProjectExplorer::Kit *k);
|
||||
static CMakeConfigItem kitDefaultConfigHashItem(const ProjectExplorer::Kit *k);
|
||||
static QByteArray computeDefaultConfigHash(const CMakeConfig &config);
|
||||
static QByteArray computeDefaultConfigHash(const CMakeConfig &config,
|
||||
const Utils::FilePath &cmakeBinary);
|
||||
|
||||
// KitAspect interface
|
||||
ProjectExplorer::Tasks validate(const ProjectExplorer::Kit *k) const final;
|
||||
|
@@ -464,6 +464,35 @@ void updateCompilerPaths(CMakeConfig &config, const Environment &env)
|
||||
updateRelativePath("CMAKE_CXX_COMPILER");
|
||||
}
|
||||
|
||||
void updateConfigWithDirectoryData(CMakeConfig &config, const std::unique_ptr<DirectoryData> &data)
|
||||
{
|
||||
auto updateCompilerValue = [&config, &data](const QByteArray &key, const Utils::Id &language) {
|
||||
auto it = std::find_if(config.begin(), config.end(), [&key](const CMakeConfigItem &ci) {
|
||||
return ci.key == key;
|
||||
});
|
||||
|
||||
auto tcd = Utils::findOrDefault(data->toolChains,
|
||||
[&language](const ToolChainDescription &t) {
|
||||
return t.language == language;
|
||||
});
|
||||
|
||||
if (it != config.end() && it->value.isEmpty())
|
||||
it->value = tcd.compilerPath.toString().toUtf8();
|
||||
else
|
||||
config << CMakeConfigItem(key,
|
||||
CMakeConfigItem::FILEPATH,
|
||||
tcd.compilerPath.toString().toUtf8());
|
||||
};
|
||||
|
||||
updateCompilerValue("CMAKE_C_COMPILER", ProjectExplorer::Constants::C_LANGUAGE_ID);
|
||||
updateCompilerValue("CMAKE_CXX_COMPILER", ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
|
||||
if (data->qt.qt)
|
||||
config << CMakeConfigItem("QT_QMAKE_EXECUTABLE",
|
||||
CMakeConfigItem::FILEPATH,
|
||||
data->qt.qt->qmakeFilePath().toString().toUtf8());
|
||||
}
|
||||
|
||||
QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
QString *warningMessage) const
|
||||
{
|
||||
@@ -550,8 +579,6 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
CMakeConfigItem::STRING,
|
||||
configurePreset.generator.value().toUtf8());
|
||||
}
|
||||
data->cmakePresetDefaultConfigHash = CMakeConfigurationKitAspect::computeDefaultConfigHash(
|
||||
config);
|
||||
|
||||
const FilePath qmake = qmakeFromCMakeCache(config);
|
||||
if (!qmake.isEmpty())
|
||||
@@ -560,6 +587,12 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
// ToolChains:
|
||||
data->toolChains = extractToolChainsFromCache(config);
|
||||
|
||||
// Update QT_QMAKE_EXECUTABLE and CMAKE_C|XX_COMPILER config values
|
||||
updateConfigWithDirectoryData(config, data);
|
||||
|
||||
data->cmakePresetDefaultConfigHash
|
||||
= CMakeConfigurationKitAspect::computeDefaultConfigHash(config, data->cmakeBinary);
|
||||
|
||||
QByteArrayList buildConfigurationTypes = {cache.valueOf("CMAKE_BUILD_TYPE")};
|
||||
if (buildConfigurationTypes.front().isEmpty()) {
|
||||
buildConfigurationTypes.clear();
|
||||
|
@@ -12,7 +12,7 @@
|
||||
"generator": "Ninja",
|
||||
"installDir": "../inst-${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_PREFIX_PATH": "$env{SYSTEMDRIVE}/Qt/6.3.2/mingw_64"
|
||||
"CMAKE_PREFIX_PATH": "$env{SYSTEMDRIVE}/Qt/6.4.2/mingw_64"
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
@@ -34,7 +34,7 @@
|
||||
"inherits" : "mingw",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_PREFIX_PATH": "$env{SystemDrive}/Qt/6.3.2/mingw_64"
|
||||
"CMAKE_PREFIX_PATH": "$env{SystemDrive}/Qt/6.4.2/mingw_64"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -56,7 +56,7 @@
|
||||
},
|
||||
"environment" : {
|
||||
"HOST_SYSTEM_NAME": "Windows",
|
||||
"QT_VERSION": "6.3.2"
|
||||
"QT_VERSION": "6.4.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -64,7 +64,7 @@
|
||||
"displayName": "Visual C++ 2019 x64 Ninja",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||
"toolchainFile" : "c:/Qt/6.3.2/msvc2019_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||
"toolchainFile" : "c:/Qt/6.4.2/msvc2019_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
},
|
||||
@@ -92,7 +92,7 @@
|
||||
"displayName": "Linux GCC",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||
"toolchainFile" : "$env{HOME}/Qt/6.3.2/gcc_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||
"toolchainFile" : "$env{HOME}/Qt/6.4.2/gcc_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||
"condition" : {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
|
Reference in New Issue
Block a user