Skip to content

Commit 80841c3

Browse files
committed
manual [skip ci]
1 parent 82f33cd commit 80841c3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

man/manual.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,21 @@ To ignore certain folders in the project you can use `-i`. This will skip the an
287287

288288
cppcheck --project=foobar.cppcheck -ifoo
289289

290-
## CMake
290+
## Compilation database (cmake etc)
291291

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:
293294

294295
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
295296

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:
297298

298299
cppcheck --project=compile_commands.json
299300

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+
300305
To ignore certain folders you can use `-i`. This will skip analysis of source files in the `foo` folder.
301306

302307
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
338343

339344
## Other
340345

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
342349

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:
344351

345352
bear -- make
346353

354+
If you don't use Linux; there are python scripts that converts a Makefile into a compilation database.
355+
347356
# Preprocessor Settings
348357

349358
If you use `--project` then Cppcheck will automatically use the preprocessor settings in the imported project file and
@@ -388,21 +397,28 @@ Example:
388397
cppcheck test.c
389398

390399
# 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
392401
cppcheck -DA test.c
393402

394403
# only test configuration "-DA -DC"
395404
# The first bug is found
396405
cppcheck -DA -DC test.c
397406

398-
# The configuration "-DC" is tested
407+
# Test all configurations that does not define "A"
399408
# The last bug is found
400409
cppcheck -UA test.c
401410

402411
# All configurations with "-DA" are tested
403412
# The two first bugs are found
404413
cppcheck --force -DA test.c
405414

415+
# only test 1 valid configuration
416+
# Bug(s) will be found
417+
cppcheck --max-configs=1 test.c
418+
419+
# test 2 valid configurations with "X" defined.
420+
# Bug(s) will be found
421+
cppcheck --max-configs=2 -DX test.c
406422

407423
## Include paths
408424

0 commit comments

Comments
 (0)