You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix #11824 (Option --max-configs has no effect if -D is used) (#7980)
Number of checked configurations:
cppcheck file.c => 12
cppcheck -DX file.c => 1
cppcheck -DX --max-configs=6 file.c => 6
move logic from cmdlineparser to Settings class where the code can be
reused (from GUI). The `Settings::checkAllConfigs` is removed.
Copy file name to clipboardExpand all lines: man/manual.md
+23-7Lines changed: 23 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -287,16 +287,21 @@ To ignore certain folders in the project you can use `-i`. This will skip the an
287
287
288
288
cppcheck --project=foobar.cppcheck -ifoo
289
289
290
-
## CMake
290
+
## Compilation database (cmake etc)
291
291
292
-
Generate a compile database (a JSON file containing compilation commands for each source file):
292
+
Many build systems can generate a compilation database (a JSON file containing compilation commands for each source file).
293
+
Example `cmake` command to generate the file:
293
294
294
295
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
295
296
296
-
The file `compile_commands.json`is created in the current folder. Now run Cppcheck like this:
297
+
When you have a `compile_commands.json`file you can run Cppcheck like this:
297
298
298
299
cppcheck --project=compile_commands.json
299
300
301
+
By default only 1 configuration is checked because that is consistent with the compilation. If you want to check more configurations you can use `--max-configs` or `--force`. For example:
302
+
303
+
cppcheck --project=compile_commands.json --force
304
+
300
305
To ignore certain folders you can use `-i`. This will skip analysis of source files in the `foo` folder.
301
306
302
307
cppcheck --project=compile_commands.json -ifoo
@@ -338,12 +343,16 @@ To ignore certain folders in the project you can use `-i`. This will skip analys
338
343
339
344
## Other
340
345
341
-
If you can generate a compile database, then it is possible to import that in Cppcheck.
346
+
If you generate a compilation database, then it is possible to import that in Cppcheck.
347
+
348
+
### Makefile
342
349
343
-
In Linux you can use for instance the `bear` (build ear) utility to generate a compile database from arbitrary build tools:
350
+
In Linux you can convert a Makefile to a compile_commands.json using for instance `bear` (build ear) utility:
344
351
345
352
bear -- make
346
353
354
+
If you don't use Linux; there are python scripts that converts a Makefile into a compilation database.
355
+
347
356
# Preprocessor Settings
348
357
349
358
If you use `--project` then Cppcheck will automatically use the preprocessor settings in the imported project file and
@@ -388,21 +397,28 @@ Example:
388
397
cppcheck test.c
389
398
390
399
# only test configuration "-DA"
391
-
# No bug is found (#error)
400
+
# No bug is found; because C is not defined the #error will cause a preprocessor error
392
401
cppcheck -DA test.c
393
402
394
403
# only test configuration "-DA -DC"
395
404
# The first bug is found
396
405
cppcheck -DA -DC test.c
397
406
398
-
# The configuration "-DC" is tested
407
+
# Test all configurations that does not define "A"
0 commit comments