Home

Awesome

CPPCheck Target CMake

Per-target CPPCheck for CMake

Status

[![Travis](https://travis-ci.org/polysquare/cppcheck-target- cmake.svg?branch=master)](https://travis-ci.org/polysquare/cppcheck-target- cmake)

Platform-specific installation notes

On Windows, the chocolatey package for cppcheck is broken, so cppcheck must be installed manually. There is no unattended installer for cppcheck which permits installation into a non-administrator directory, so the AppVeyor build does not test this module as completely as it should.

Usage

Static analysis on a group of sources

Every check asides from a check for unused methods or functions can be performed on any group of sources after any target in the build has been run. If any checks fail, a fatal error to the build is raised.

Headers will be checked by default if they are part of the check sources, using a technique to scan source files for includes. If header files are part of the sources, they must be listed after sources that include them, such that the language for cppcheck to use will be correct.

To check all sources for a target just before the target links, use cppcheck_target_sources. For example:

cppcheck_target_sources (my_target INCLUDES ${INCLUDES})

To check an arbitrary list of sources before some arbitrary target links, use cppcheck_sources. For example:

cppcheck_sources (my_target SOURCES ${SOURCES} INCLUDES ${INCLUDES})

The following options may affect the checks run on sources:

Checking for unused functions

Checks for unused functions are generally run over all sources in large group, usually all the sources in a particular library and set of executables or tests using that library.

Sources can be added to an unused function check group with cppcheck_add_to_unused_function_check. For example

cppcheck_add_to_unused_function_check (check_unused_functions
                                       TARGETS library
                                       SOURCES ${SOURCES}
                                       INCLUDES ${INCLUDES})

If check_unused_functions did not exist as an unused function check group, then a new target called check_unused_functions is created. For existing or new targets, the specified sources and include directories are added to it.

If TARGETS are specified, then the unused function check target will be made to depend on the TARGETS as listed. This is useful to ensure that the unused function check is run when those targets are out of date.

If CHECK_GENERATED is specified, then source files marked GENERATED will also be checked for unused functions.

Once all sources have been added to an unused function check, it can be "committed" and added to the build with cppcheck_add_unused_function_check_with_name

cppcheck_add_unused_function_check_with_name (check_unused_functions)