aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2022-10-23 14:36:47 +0200
committerCristian Adam <cristian.adam@qt.io>2022-10-25 20:54:59 +0000
commit7dfc7c627b428524b0d3f021e822d5bf20910f98 (patch)
tree9add71478103d85c1fd2e4a57921ae2a771b3019
parent869597884df823b6e2eade4d1bead81b7710daa3 (diff)
CMakePM: Allow presets without generator specified
This allows presets that do not have a generator specified to proper work. On Windows CMake will detect "Visual Studio" as generator. This change sets the generator and the architecture values accordingly. Change-Id: I943e082430445c4b16cf9eaf4ae5ae2500b2bd2b Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
index a64ad830d63..e82491953d8 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
@@ -412,6 +412,27 @@ static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfi
return result;
}
+static QString extractVisualStudioPlatformFromConfig(const CMakeConfig &config)
+{
+ const QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR"));
+ QString platform;
+ if (cmakeGenerator.contains("Visual Studio")) {
+ const FilePath linker = config.filePathValueOf("CMAKE_LINKER");
+ const QString toolsDir = linker.parentDir().fileName();
+ if (toolsDir.compare("x64", Qt::CaseInsensitive) == 0) {
+ platform = "x64";
+ } else if (toolsDir.compare("x86", Qt::CaseInsensitive) == 0) {
+ platform = "Win32";
+ } else if (toolsDir.compare("arm64", Qt::CaseInsensitive) == 0) {
+ platform = "ARM64";
+ } else if (toolsDir.compare("arm", Qt::CaseInsensitive) == 0) {
+ platform = "ARM";
+ }
+ }
+
+ return platform;
+}
+
QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
QString *warningMessage) const
{
@@ -476,6 +497,17 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
QApplication::setOverrideCursor(Qt::WaitCursor);
config = configurationFromPresetProbe(importPath, configurePreset);
QApplication::restoreOverrideCursor();
+
+ if (!configurePreset.generator) {
+ QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR"));
+ configurePreset.generator = cmakeGenerator;
+ data->generator = cmakeGenerator;
+ data->platform = extractVisualStudioPlatformFromConfig(config);
+ if (!data->platform.isEmpty()) {
+ configurePreset.architecture = PresetsDetails::ValueStrategyPair();
+ configurePreset.architecture->value = data->platform;
+ }
+ }
} else {
config = cache;
config << CMakeConfigItem("CMAKE_COMMAND",
@@ -566,6 +598,8 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
data->generator = config.stringValueOf("CMAKE_GENERATOR");
data->extraGenerator = config.stringValueOf("CMAKE_EXTRA_GENERATOR");
data->platform = config.stringValueOf("CMAKE_GENERATOR_PLATFORM");
+ if (data->platform.isEmpty())
+ data->platform = extractVisualStudioPlatformFromConfig(config);
data->toolset = config.stringValueOf("CMAKE_GENERATOR_TOOLSET");
data->sysroot = config.filePathValueOf("CMAKE_SYSROOT");