diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index 33d9684acbc..eaf2261b06c 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -217,10 +218,17 @@ void CMakeManager::buildFile(Node *node) CMakeTargetNode *targetNode = dynamic_cast(fileNode->parentProjectNode()); if (!targetNode) return; + Utils::FilePath filePath = fileNode->filePath(); + if (filePath.fileName().contains(".h")) { + bool wasHeader = false; + const QString sourceFile = CppEditor::correspondingHeaderOrSource(filePath.toString(), &wasHeader); + if (wasHeader && !sourceFile.isEmpty()) + filePath = Utils::FilePath::fromString(sourceFile); + } Target *target = project->activeTarget(); QTC_ASSERT(target, return); const QString generator = CMakeGeneratorKitAspect::generator(target->kit()); - const QString relativeSource = fileNode->filePath().relativeChildPath(targetNode->filePath()).toString(); + const QString relativeSource = filePath.relativeChildPath(targetNode->filePath()).toString(); const QString objExtension = Utils::HostOsInfo::isWindowsHost() ? QString(".obj") : QString(".o"); Utils::FilePath targetBase; BuildConfiguration *bc = target->activeBuildConfiguration();