forked from qt-creator/qt-creator
CMakePM: Allow file rename / remove via variables
Lookup any variables found in the target definition function in order to
find the source files.
This works for something like this:
set(SOURCE_FILES myfile.cpp)
add_executable(myexe ${SOURCE_FILES})
Change-Id: I8a47ea64b4efa467074f03ed5e1d1d05b2b1bf00
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -422,6 +422,7 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
|
|||||||
if (!filePathArgument.Value.empty()) {
|
if (!filePathArgument.Value.empty()) {
|
||||||
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
||||||
} else {
|
} else {
|
||||||
|
// Check if the filename is part of globbing variable result
|
||||||
const auto globFunctions = std::get<0>(
|
const auto globFunctions = std::get<0>(
|
||||||
Utils::partition(cmakeListFile.Functions, [](const auto &f) {
|
Utils::partition(cmakeListFile.Functions, [](const auto &f) {
|
||||||
return f.LowerCaseName() == "file" && f.Arguments().size() > 2
|
return f.LowerCaseName() == "file" && f.Arguments().size() > 2
|
||||||
@@ -440,11 +441,43 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
|
|||||||
!= cmListFileArgument::Comment;
|
!= cmListFileArgument::Comment;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (haveGlobbing)
|
if (haveGlobbing) {
|
||||||
return ProjectFileArgumentPosition{filePathArgument,
|
return ProjectFileArgumentPosition{filePathArgument,
|
||||||
targetCMakeFile,
|
targetCMakeFile,
|
||||||
fileName,
|
fileName,
|
||||||
true};
|
true};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the filename is part of a variable set by the user
|
||||||
|
const auto setFunctions = std::get<0>(
|
||||||
|
Utils::partition(cmakeListFile.Functions, [](const auto &f) {
|
||||||
|
return f.LowerCaseName() == "set" && f.Arguments().size() > 1;
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (const auto &arg : func->Arguments()) {
|
||||||
|
if (arg.Delim == cmListFileArgument::Comment)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto matchedFunctions = Utils::filtered(setFunctions, [arg](const auto &f) {
|
||||||
|
return arg.Value == std::string("${") + f.Arguments()[0].Value + "}";
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto &f : matchedFunctions) {
|
||||||
|
filePathArgument
|
||||||
|
= Utils::findOrDefault(f.Arguments(),
|
||||||
|
[file_name = fileName.toStdString()](
|
||||||
|
const auto &arg) {
|
||||||
|
return arg.Delim != cmListFileArgument::Comment
|
||||||
|
&& arg.Value == file_name;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!filePathArgument.Value.empty()) {
|
||||||
|
return ProjectFileArgumentPosition{filePathArgument,
|
||||||
|
targetCMakeFile,
|
||||||
|
fileName};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user