I'm working with CMake and the --project option of cppcheck to do some
static code analysis and I've encountered an error when trying to check
files generated by the protoc compiler. Cppcheck tells me that there is
a preprocessorErrorDirective in one of the generated classes. The error
results from this check here:
#if 3017003 < PROTOBUF_MIN_PROTOC_VERSION#error This file was generated by an older version of protoc which is#error incompatible with your Protocol Buffer headers. Please#error regenerate this file with a newer version of protoc.#endif
It seems that cppcheck assumes that PROTOBUF_MIN_PROTOC_VERSION is
not defined, although it get's defined earlier by an include of
<google protobuf="" port_def.inc="">. The problem only arises when I add a target_compile_definitions in CMake. If I leave this out, cppcheck
correctly expands the macro.</google>
I've attached an example test case where you can reproduce the error
with the current 2.7.4 version of cppcheck. To run the test, build the
docker image with docker builder . and run the image with docker run
-it --rm -v "$(pwd)":/workspace {HASH_FROM_BUILD}. Run cd /workspace
&& ./runtest.sh inside the docker image. You can toggle target_compile_definitions inside the CMake file and see the
behavior.
I'm facing the same issue. Adding "-I${Protobuf_INCLUDE_DIRS}" to the CMAKE_CXX_CPPCHECK bypass this error, but then it fails like this:
/usr/local/include/google/protobuf/stubs/port.h:123:0:error:#error"Protobuf requires at least C++11."[preprocessorErrorDirective]#error"Protobuf requires at least C++11."
The error happens even though I'm using C++14, very likely because the cplusplus macro is not received by cppcheck.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Same issue.
Here is the current solution I found:
Need to replace isystem include to Protobuf path by -I include.
As @mMontu, the same error appears.
So, I generated default predefine: echo | g++ -dM -E -x c++ - > gcc_predefined.h
And finally, using cppcheck by adding --include=./gcc_predefined.h
Do you have a better solution?
Is possible that ccpcheck retrieve by itself theses defines that gcc is able to dump?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm working with CMake and the --project option of cppcheck to do some
static code analysis and I've encountered an error when trying to check
files generated by the protoc compiler. Cppcheck tells me that there is
a preprocessorErrorDirective in one of the generated classes. The error
results from this check here:
It seems that cppcheck assumes that
PROTOBUF_MIN_PROTOC_VERSION
isnot defined, although it get's defined earlier by an include of
<google protobuf="" port_def.inc="">. The problem only arises when I add a
target_compile_definitions
in CMake. If I leave this out, cppcheckcorrectly expands the macro.</google>
I've attached an example test case where you can reproduce the error
with the current 2.7.4 version of cppcheck. To run the test, build the
docker image with
docker builder .
and run the image withdocker run -it --rm -v "$(pwd)":/workspace {HASH_FROM_BUILD}
. Runcd /workspace && ./runtest.sh
inside the docker image. You can toggletarget_compile_definitions
inside the CMake file and see thebehavior.
BR Kai
Hi
I'm facing the same issue. Adding "-I${Protobuf_INCLUDE_DIRS}" to the CMAKE_CXX_CPPCHECK bypass this error, but then it fails like this:
The error happens even though I'm using C++14, very likely because the cplusplus macro is not received by cppcheck.
Hello,
Same issue.
Here is the current solution I found:
Need to replace isystem include to Protobuf path by -I include.
As @mMontu, the same error appears.
So, I generated default predefine: echo | g++ -dM -E -x c++ - > gcc_predefined.h
And finally, using cppcheck by adding --include=./gcc_predefined.h
Do you have a better solution?
Is possible that ccpcheck retrieve by itself theses defines that gcc is able to dump?