-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give preprocessor definitions to cppcheck #270
Comments
In almost all the packages, there are almost no compile definitions we need to pass. |
@ivanpauno Easy enough to check:
|
Even if we do manage to pass all platform and compiler-specific flags, cppcheck needs help to reason about, e.g. |
That was what I meant with "visibility macros". The problem is that we need to configure them for the current package and for all the dependencies. |
The second part does not seem that tricky:
and replace |
Ok. We should collect all exported compile definitions in |
We shouldn't have to even collect them, since CMake populates from link interface dependencies.
|
Yeah, what I mean is that we still have to collect the targets in the project, take the definitions, and pass them to cppcheck. |
There's some subtlety here. Because cppcheck is currently done on a per-directory basis, naively adding definitions with If we want definitions (and includes) to be correct, we need either to invoke |
@clalancette the suggestion in this comment is what I mentioned today: #270 (comment) |
Let's concretize this to "give |
Not sure to what extent. It should be able to find all headers in this case, but not sure if it'll take into consideration preprocessor definitions flags ( |
You certainly want to extract anything that's default to a real compiler and then give that explicitly to cppcheck's preprocessor. |
cppcheck
is unable to correctly analyze source code because it does not know the preprocessor definitions that the project will be compiled with. This may be responsible for the CI-breaking performance seen in #263 (since in the absence of precompiler definitions, cppcheck analyzes all preprocessor paths, which can be excessive, with each preprocessor conditional doubling the number of code paths to analyze).Limiting the headers to reclaim manageable performance causes numerous spurious downstream false failures for missing macros ros2/ros2#942
Ideally, the list of include paths and compile definitions should be correct on the file level, possibly with the help of
compile_commands.json
, which can be generated with CMake.Although it would not fully resolve this issue, telling cppcheck the include paths and compile definitions at the target or directory level might be a good enough stopgap. Compile options can be specified per build file, but the target level is usually as specific as these get. (I attempted this approach in #269, but unfortunately was not able to finish).
The text was updated successfully, but these errors were encountered: