From 5e3d14e2e932da0a3dc3314d2802bc3df0dc504c Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Sun, 22 Oct 2023 14:22:20 +0200 Subject: [PATCH] CMakePM: Allow CMAKE_SYSROOT to be taken from the CMake preset probe One could have a toolchainfile that sets the CMAKE_SYSROOT. We need to be able to read the value later, and not just from the CMake Presets cmakeCache array. Task-number: QTCREATORBUG-29643 Change-Id: I63697219195b043813516c8214329ce583dc0676 Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index 74d5056bf78..b8748bc6f98 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -264,6 +264,7 @@ static CMakeConfig configurationFromPresetProbe( const QString prefixPath = cache.stringValueOf("CMAKE_PREFIX_PATH"); const QString findRootPath = cache.stringValueOf("CMAKE_FIND_ROOT_PATH"); const QString qtHostPath = cache.stringValueOf("QT_HOST_PATH"); + const QString sysRoot = cache.stringValueOf("CMAKE_SYSROOT"); if (!cmakeMakeProgram.isEmpty()) { args.emplace_back( @@ -282,6 +283,9 @@ static CMakeConfig configurationFromPresetProbe( if (!qtHostPath.isEmpty()) { args.emplace_back(QStringLiteral("-DQT_HOST_PATH=%1").arg(qtHostPath)); } + if (!sysRoot.isEmpty()) { + args.emplace_back(QStringLiteral("-DCMAKE_SYSROOT=%1").arg(sysRoot)); + } } qCDebug(cmInputLog) << "CMake probing for compilers: " << cmakeExecutable.toUserOutput() @@ -745,9 +749,6 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, const CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value() : CMakeConfig(); - - data->sysroot = cache.filePathValueOf("CMAKE_SYSROOT"); - CMakeConfig config; const bool noCompilers = cache.valueOf("CMAKE_C_COMPILER").isEmpty() && cache.valueOf("CMAKE_CXX_COMPILER").isEmpty(); @@ -778,6 +779,8 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, configurePreset.generator.value().toUtf8()); } + data->sysroot = config.filePathValueOf("CMAKE_SYSROOT"); + const auto [qmake, cmakePrefixPath] = qtInfoFromCMakeCache(config, env); if (!qmake.isEmpty()) data->qt = findOrCreateQtVersion(qmake);