From f5ba46ccbdc90d06cd3aa2e161ab69e79f349dbe Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 18 Mar 2024 12:15:25 +0100 Subject: [PATCH] CppEditor: Tell clangd about path to CUDA At the very least, this fixes an ugly warning message for .cu files. May or may not improve other things as well. Task-number: QTCREATORBUG-23113 Change-Id: If389fd67a153f7da13e5d4d465189aaef352c976 Reviewed-by: Cristian Adam Reviewed-by: Christian Stenger Reviewed-by: Qt CI Bot Reviewed-by: --- src/plugins/cppeditor/projectpart.cpp | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/plugins/cppeditor/projectpart.cpp b/src/plugins/cppeditor/projectpart.cpp index 680723750f8..24f9dc42e85 100644 --- a/src/plugins/cppeditor/projectpart.cpp +++ b/src/plugins/cppeditor/projectpart.cpp @@ -12,6 +12,7 @@ #include using namespace ProjectExplorer; +using namespace Utils; namespace CppEditor { @@ -115,6 +116,32 @@ static QStringList getIncludedFiles(const RawProjectPart &rpp, const RawProjectP return !rpp.includedFiles.isEmpty() ? rpp.includedFiles : flags.includedFiles; } +static QStringList getExtraCodeModelFlags(const RawProjectPart &rpp, const ProjectFiles &files) +{ + if (!Utils::anyOf(files, [](const ProjectFile &f) { return f.kind == ProjectFile::CudaSource; })) + return {}; + + Utils::FilePath cudaPath; + for (const HeaderPath &hp : rpp.headerPaths) { + if (hp.type == HeaderPathType::BuiltIn) + continue; + if (!hp.path.endsWith("/include")) + continue; + const Utils::FilePath includeDir = Utils::FilePath::fromString(hp.path); + if (!includeDir.pathAppended("cuda.h").exists()) + continue; + for (FilePath dir = includeDir.parentDir(); cudaPath.isEmpty() && !dir.isRootPath(); + dir = dir.parentDir()) { + if (dir.pathAppended("nvvm").exists()) + cudaPath = dir; + } + break; + } + if (!cudaPath.isEmpty()) + return {"--cuda-path=" + cudaPath.toUserOutput()}; + return {}; +} + ProjectPart::ProjectPart(const Utils::FilePath &topLevelProject, const RawProjectPart &rpp, const QString &displayName, @@ -149,7 +176,7 @@ ProjectPart::ProjectPart(const Utils::FilePath &topLevelProject, toolchainInstallDir(tcInfo.installDir), compilerFilePath(tcInfo.compilerFilePath), warningFlags(flags.warningFlags), - extraCodeModelFlags(tcInfo.extraCodeModelFlags), + extraCodeModelFlags(tcInfo.extraCodeModelFlags + getExtraCodeModelFlags(rpp, files)), compilerFlags(flags.commandLineFlags), m_macroReport(getToolchainMacros(flags, tcInfo, language)), languageFeatures(deriveLanguageFeatures())