From 45a275e054655c5290cf4227c24dfed0a50cb8ae Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 29 Sep 2022 15:47:05 +0200 Subject: [PATCH] CMakePM: Use architecture and toolset for project import This fixes issues with Visual C++ generator, which needs the right parameters to pinpoint the right compilers. Also use CMAKE_TOOLCHAIN_FILE for qmake detection. Change-Id: I6edc84c7ed1a892fbc5545ff61dc06ac20720f0a Reviewed-by: Alessandro Portale --- .../cmakeprojectimporter.cpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index be51a7d47cb..2c207226f2f 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -165,6 +165,14 @@ static CMakeConfig configurationFromPresetProbe( args.emplace_back("-G"); args.emplace_back(configurePreset.generator.value()); } + if (configurePreset.architecture && configurePreset.architecture.value().value) { + args.emplace_back("-A"); + args.emplace_back(configurePreset.architecture.value().value.value()); + } + if (configurePreset.toolset && configurePreset.toolset.value().value) { + args.emplace_back("-T"); + args.emplace_back(configurePreset.toolset.value().value.value()); + } if (configurePreset.cacheVariables) { const CMakeConfig cache = configurePreset.cacheVariables @@ -233,7 +241,9 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config) prefixPath = config.stringValueOf("CMAKE_PREFIX_PATH"); } qCDebug(cmInputLog) << "PrefixPath:" << prefixPath; - if (prefixPath.isEmpty()) + + FilePath toolchainFile = config.filePathValueOf(QByteArray("CMAKE_TOOLCHAIN_FILE")); + if (prefixPath.isEmpty() && toolchainFile.isEmpty()) return FilePath(); // Run a CMake project that would do qmake probing @@ -284,9 +294,10 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config) cmake.setTimeOutMessageBoxEnabled(false); QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR")); + QString cmakeGeneratorPlatform = config.stringValueOf(QByteArray("CMAKE_GENERATOR_PLATFORM")); + QString cmakeGeneratorToolset = config.stringValueOf(QByteArray("CMAKE_GENERATOR_TOOLSET")); FilePath cmakeExecutable = config.filePathValueOf(QByteArray("CMAKE_COMMAND")); FilePath cmakeMakeProgram = config.filePathValueOf(QByteArray("CMAKE_MAKE_PROGRAM")); - FilePath toolchainFile = config.filePathValueOf(QByteArray("CMAKE_TOOLCHAIN_FILE")); FilePath hostPath = config.filePathValueOf(QByteArray("QT_HOST_PATH")); QStringList args; @@ -296,6 +307,14 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config) args.push_back(qtcQMakeProbeDir.filePath("build").path()); args.push_back("-G"); args.push_back(cmakeGenerator); + if (!cmakeGeneratorPlatform.isEmpty()) { + args.push_back("-A"); + args.push_back(cmakeGeneratorPlatform); + } + if (!cmakeGeneratorToolset.isEmpty()) { + args.push_back("-T"); + args.push_back(cmakeGeneratorToolset); + } if (!cmakeMakeProgram.isEmpty()) { args.push_back(QStringLiteral("-DCMAKE_MAKE_PROGRAM=%1").arg(cmakeMakeProgram.toString())); @@ -303,7 +322,8 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config) if (toolchainFile.isEmpty()) { args.push_back(QStringLiteral("-DCMAKE_PREFIX_PATH=%1").arg(prefixPath)); } else { - args.push_back(QStringLiteral("-DCMAKE_FIND_ROOT_PATH=%1").arg(prefixPath)); + if (!prefixPath.isEmpty()) + args.push_back(QStringLiteral("-DCMAKE_FIND_ROOT_PATH=%1").arg(prefixPath)); args.push_back(QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=%1").arg(toolchainFile.toString())); } if (!hostPath.isEmpty()) {