forked from qt-creator/qt-creator
CMakePM: expand macros for all configure cacheVariables
Fixes: QTCREATORBUG-28982 Change-Id: Iabbf39b815ed7477a9d272a320308f320a31adbc Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
@@ -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");
|
||||
|
@@ -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,
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user