I am using precompiled headers in my project and I have observed that Cppcheck does not seem to work with them even though the information about precompiled headers is in compile_commands.json.
Simplified related piece of compile_commands.json.
The list of header files is used to generate a header file named cmake_pch.h|xx which is used to generate the precompiled header file (.pch, .gch, .pchi) artifact. The cmake_pch.h|xx header file will be force included (-include for GCC, /FI for MSVC) to all source files, so sources do not need to have #include "pch.h".
The last part is important - CMake force includes the precompiled header so you don't have to, i.e., CMake allows us to compile code that would not compile if you turned precompiled headers off. Precompiled headers are a convenience feature and projects should, in an ideal world, be able to compile with precompiled turned off, however, that is seldom the case.
The only solution, with Cppcheck 2.11, I can think of, is to make project compile with precompiled headers turned off. This might require a bit of work on project's side.
Last edit: Samuel Poláček 2023-08-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using precompiled headers in my project and I have observed that Cppcheck does not seem to work with them even though the information about precompiled headers is in compile_commands.json.
Simplified related piece of compile_commands.json.
Cppcheck does not parse -include from compile_commands.json (see
ImportProject::FileSettings::parseCommand()
).From Cmake's doc:
The last part is important - CMake force includes the precompiled header so you don't have to, i.e., CMake allows us to compile code that would not compile if you turned precompiled headers off. Precompiled headers are a convenience feature and projects should, in an ideal world, be able to compile with precompiled turned off, however, that is seldom the case.
The only solution, with Cppcheck 2.11, I can think of, is to make project compile with precompiled headers turned off. This might require a bit of work on project's side.
Last edit: Samuel Poláček 2023-08-30
This might be a way to disable precompiled headers in root CMakeLists.txt
Last edit: Samuel Poláček 2023-08-30