CMakePM: Find the right AUTOUIC generated header

Amends c4e15769ec

When using ui files in static libraries AUTOUIC reports fake header file
names.

By using the target that includes the source ui file we can find the
correct header file name.

Change-Id: I1c8e0b81ad2c670be87c3620f98bd0f5cce40cd1
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2023-08-08 19:21:46 +02:00
parent 4330736db3
commit 6528bd3eed

View File

@@ -654,15 +654,29 @@ FilePaths CMakeBuildSystem::filesGeneratedFrom(const FilePath &sourceFile) const
FilePath generatedFilePath = buildConfiguration()->buildDirectory().resolvePath(relativePath);
if (sourceFile.suffix() == "ui") {
const QString generatedFileSuffix = "ui_" + sourceFile.completeBaseName() + ".h";
const QString generatedFileName = "ui_" + sourceFile.completeBaseName() + ".h";
// If AUTOUIC reports the generated header file name, use that path
FilePaths generatedFilePaths = this->project()->files([generatedFileSuffix](const Node *n) {
return Project::GeneratedFiles(n) && n->filePath().endsWith(generatedFileSuffix);
});
auto targetNode = this->project()->nodeForFilePath(sourceFile);
while (!dynamic_cast<const CMakeTargetNode *>(targetNode))
targetNode = targetNode->parentFolderNode();
FilePaths generatedFilePaths;
if (targetNode) {
const QString autogenSignature = targetNode->buildKey() + "_autogen/include";
// If AUTOUIC reports the generated header file name, use that path
generatedFilePaths = this->project()->files(
[autogenSignature, generatedFileName](const Node *n) {
const FilePath filePath = n->filePath();
if (!filePath.contains(autogenSignature))
return false;
return Project::GeneratedFiles(n) && filePath.endsWith(generatedFileName);
});
}
if (generatedFilePaths.empty())
generatedFilePaths = {generatedFilePath.pathAppended(generatedFileSuffix)};
generatedFilePaths = {generatedFilePath.pathAppended(generatedFileName)};
return generatedFilePaths;
}