Bug 407444

Summary: Background parser gets confused by gcc-generated precompiled headers
Product: [Applications] kdevelop Reporter: nospam7777123
Component: Build tools: CMakeAssignee: kdevelop-bugs-null
Status: REPORTED ---    
Severity: normal CC: eugene.shalygin+bugzilla.kde, justusranvier, krzysio.kurek, silverunicorn2011
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: remove CMake-generated precompiled headers from Clang arguments

Description nospam7777123 2019-05-12 08:18:24 UTC
SUMMARY
When using the pch-feature of cotire (https://github.com/sakra/cotire) (or I guess precompiled headers created by gcc in general) the clang-pluging (background parser) is trying to use them and fails, resulting in non-working code-completing.

STEPS TO REPRODUCE
1. Create c++ cmake project, include cotire
2. add_executable(<target name> <at least a couple of sources>)
3. cotire(<target name>)

OBSERVED RESULT
No code-completion in kdevelop

EXPECTED RESULT
Working code-completion in kdevelop

SOFTWARE/OS VERSIONS
observed with all kde5/kdevelop5/qt5/cmake3.x/cotire versions so far
Comment 1 Eugene Shalygin 2020-03-06 02:59:15 UTC
Now with the precompiled headers available in the core CMake, it is even easier to trigger this bug.
Comment 2 Justus Ranvier 2022-01-19 19:06:45 UTC
(In reply to Eugene Shalygin from comment #1)
> Now with the precompiled headers available in the core CMake, it is even
> easier to trigger this bug.

That's exactly what happened to me which is how I found this my way to this issue. I started using target_precompile_headers in my project and suddenly the parser stopped working in kdevelop unless I use clang as the compiler.
Comment 3 Justus Ranvier 2022-01-19 19:14:21 UTC
*** Bug 427002 has been marked as a duplicate of this bug. ***
Comment 4 Eugene Shalygin 2023-04-15 13:24:05 UTC
Created attachment 158128 [details]
remove CMake-generated precompiled headers from Clang arguments

While we are waiting for a proper fix, I'd like to share my workaround for GCC and CMake. It simply drops cmake-generated -include path/to/cmake_pch.h[xx] arguments from clang invocation command line.
Comment 5 Vitaliy 2023-05-06 18:00:34 UTC
Even if you use clang as the compiler, the parser may still fail with errors like
> error: GNU extensions was enabled in PCH file but is currently disabled
> error: C11 was enabled in PCH file but is currently disabled
(happens with SDL3 on my system). So removing the include may be necessary on it too. Of course it would be better if KDevelop used the exact same compilation mode the build system uses but that may be tricky and in some cases outright impossible.