diff options
author | Cristian Adam <cristian.adam@qt.io> | 2023-03-31 19:53:45 +0200 |
---|---|---|
committer | Cristian Adam <cristian.adam@qt.io> | 2023-04-17 15:03:53 +0000 |
commit | 45faec05e555fec99c6cf75b3fc8844b37084919 (patch) | |
tree | b8527d2aa83549c10b915b360cf9a6d2e2a0bc64 | |
parent | 8304f3c576d20949235ab9bcdfa23b513ceb1827 (diff) |
CMakePM: expand macros for all configure cacheVariables
Fixes: QTCREATORBUG-28982
Change-Id: Iabbf39b815ed7477a9d272a320308f320a31adbc
Reviewed-by: hjk <hjk@qt.io>
4 files changed, 61 insertions, 22 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index b0fab0894a..ecf3228d31 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -98,7 +98,9 @@ Internal::PresetsData CMakeProject::combinePresets(Internal::PresetsData &cmakeP auto resolveInherits = [](auto &presetsHash, auto &presetsList) { Utils::sort(presetsList, [](const auto &left, const auto &right) { - if (!left.inherits || left.inherits.value().contains(right.name)) + const bool sameInheritance = left.inherits && right.inherits + && left.inherits.value() == right.inherits.value(); + if (!left.inherits || left.inherits.value().contains(right.name) || sameInheritance) return false; return true; }); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index a89ae82e1f..dc752f0a9f 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -209,23 +209,11 @@ static CMakeConfig configurationFromPresetProbe( ? configurePreset.cacheVariables.value() : CMakeConfig(); - auto expandCacheValue = - [configurePreset, env, sourceDirectory, cache](const QString &key) -> QString { - QString result = cache.stringValueOf(key.toUtf8()); - CMakePresets::Macros::expand(configurePreset, env, sourceDirectory, result); - - // all usages involve file paths, so make sure they are cleaned up - const FilePaths paths = transform(result.split(";"), &FilePath::fromUserInput); - result = transform(paths, &FilePath::path).join(";"); - - return result; - }; - - const QString cmakeMakeProgram = expandCacheValue("CMAKE_MAKE_PROGRAM"); - const QString toolchainFile = expandCacheValue("CMAKE_TOOLCHAIN_FILE"); - const QString prefixPath = expandCacheValue("CMAKE_PREFIX_PATH"); - const QString findRootPath = expandCacheValue("CMAKE_FIND_ROOT_PATH"); - const QString qtHostPath = expandCacheValue("QT_HOST_PATH"); + const QString cmakeMakeProgram = cache.stringValueOf("CMAKE_MAKE_PROGRAM"); + const QString toolchainFile = cache.stringValueOf("CMAKE_TOOLCHAIN_FILE"); + 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"); if (!cmakeMakeProgram.isEmpty()) { args.emplace_back( @@ -662,6 +650,8 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath, projectDirectory(), data->buildDirectory); + CMakePresets::Macros::updateCacheVariables(configurePreset, env, projectDirectory()); + const CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value() : CMakeConfig(); @@ -710,10 +700,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath, data->cmakePresetDefaultConfigHash = CMakeConfigurationKitAspect::computeDefaultConfigHash(config, data->cmakeBinary); - QString cmakeBuildType = QString::fromUtf8(cache.valueOf("CMAKE_BUILD_TYPE")); - CMakePresets::Macros::expand(configurePreset, env, projectDirectory(), cmakeBuildType); - - QByteArrayList buildConfigurationTypes = {cmakeBuildType.toUtf8()}; + QByteArrayList buildConfigurationTypes = {cache.valueOf("CMAKE_BUILD_TYPE")}; if (buildConfigurationTypes.front().isEmpty()) { buildConfigurationTypes.clear(); QByteArray buildConfigurationTypesString = cache.valueOf("CMAKE_CONFIGURATION_TYPES"); diff --git a/src/plugins/cmakeprojectmanager/presetsmacros.cpp b/src/plugins/cmakeprojectmanager/presetsmacros.cpp index c1007b202f..af5524216f 100644 --- a/src/plugins/cmakeprojectmanager/presetsmacros.cpp +++ b/src/plugins/cmakeprojectmanager/presetsmacros.cpp @@ -4,6 +4,7 @@ #include "presetsmacros.h" #include "presetsparser.h" +#include <utils/algorithm.h> #include <utils/environment.h> #include <utils/filepath.h> #include <utils/hostosinfo.h> @@ -304,6 +305,47 @@ void updateInstallDir(PresetsDetails::ConfigurePreset &configurePreset, } +void updateCacheVariables(PresetsDetails::ConfigurePreset &configurePreset, + const Utils::Environment &env, + const Utils::FilePath &sourceDirectory) +{ + using namespace Utils; + + if (!configurePreset.cacheVariables) + return; + + CMakeConfig cache = configurePreset.cacheVariables.value(); + + static const QSet<QByteArray> pathKeys{"CMAKE_C_COMPILER", + "CMAKE_CXX_COMPILER", + "CMAKE_PREFIX_PATH", + "CMAKE_FIND_ROOT_PATH", + "CMAKE_MAKE_PROGRAM", + "CMAKE_TOOLCHAIN_FILE", + "QT_HOST_PATH", + "QT_QMAKE_EXECUTABLE", + "CMAKE_SYSROOT"}; + + auto expandCacheValue = + [configurePreset, env, sourceDirectory, cache](const QByteArray &key) { + QString result = cache.stringValueOf(key); + CMakePresets::Macros::expand(configurePreset, env, sourceDirectory, result); + + if (pathKeys.contains(key)) { + const FilePaths paths = transform(result.split(";"), &FilePath::fromUserInput); + result = transform(paths, &FilePath::path).join(";"); + } + + return result.toUtf8(); + }; + + for (auto &item : cache) + item.value = expandCacheValue(item.key); + + configurePreset.cacheVariables = cache; +} + + template<class PresetType> void expandConditionValues(const PresetType &preset, const Utils::Environment &env, diff --git a/src/plugins/cmakeprojectmanager/presetsmacros.h b/src/plugins/cmakeprojectmanager/presetsmacros.h index 7d71514739..49e47a71b1 100644 --- a/src/plugins/cmakeprojectmanager/presetsmacros.h +++ b/src/plugins/cmakeprojectmanager/presetsmacros.h @@ -60,6 +60,14 @@ void updateToolchainFile(PresetsDetails::ConfigurePreset &configurePreset, void updateInstallDir(PresetsDetails::ConfigurePreset &configurePreset, const Utils::Environment &env, const Utils::FilePath &sourceDirectory); + +/** + * Updates the cacheVariables parameter of the configurePreset with the expanded prameter values. + * Including macro expansion and relative paths resolving. + */ +void updateCacheVariables(PresetsDetails::ConfigurePreset &configurePreset, + const Utils::Environment &env, + const Utils::FilePath &sourceDirectory); /** * Expands the condition values and then evaluates the condition object of the preset and returns * the boolean result. |