By default Cppcheck will check all preprocessor configurations (except those that has #error in them). This is the recommended behaviour.
But if you want to manually limit the checking you can do so with
-D
.
Beware that only the macros, which are given here and the macros defined in source files and known header files are considered. That excludes all the macros defined in some system header files, which are by default not examined by cppcheck.
The usage: if you, for example, want to limit the checking so the only configuration to check should be "DEBUG=1;__cplusplus" then something like this can be used:
cppcheck -DDEBUG=1 -D__cplusplus path
An alternative for -D is to use #error.
#if LIB_VERSION <= 3 #error "lib version must be greater than 3" #endif
Using #error instead of -D have some advantages:
the compiler will not be able to compile the code when invalid defines are given. So #error makes your source code safer/better.
Cppcheck will check all valid configurations instead of a single configuration.
This information is added to the source code which means you don't need to provide this information to Cppcheck (makes it simpler to use Cppcheck)