OrangesClangTidy

Provides functions to set up the clang-tidy static analysis tool.

Configure clang-tidy for a target

oranges_enable_clang_tidy
oranges_enable_clang_tidy (<target>
                          [CONFIG_FILE <file>] | [NO_DEFAULT_CONFIG]
                          [EXTRA_ARGS <args...>]
                          [LANGS <C|CXX|OBJC|OBJCXX>...])

Configures clang-tidy for the given <target> by manipulating the target’s <LANG>_CLANG_TIDY properties.

If the CLANGTIDY_OFF variable is set to ON, this function does nothing.

Options:

CONFIG_FILE

May be specified to provide a custom .clang-tidy file to be used for running clang-tidy on this target. If a relative path is given, it will be evaluated relative to the value of CMAKE_CURRENT_LIST_DIR when this function is called. If this argument is not specified, the value of the CLANGTIDY_CONFIG_FILE variable will be used, unless the NO_DEFAULT_CONFIG option is given. Providing this argument is equivalent to passing EXTRA_ARGS --config-file=<file>.

NO_DEFAULT_CONFIG

If this option is given, then the value of the CLANGTIDY_CONFIG_FILE variable will not be used as this target’s .clang-tidy file; instead, clang-tidy’s default behavior of searching for a .clang-tidy in a parent directory of the current source file will be used.

EXTRA_ARGS

Extra arguments that will be passed verbatim to the clang-tidy executable. If not specified, the value of the CLANGTIDY_EXTRA_ARGS variable will be used.

LANGS

Languages for which to enable clang-tidy. Valid values are C, CXX, OBJC, or OBJCXX. If no languages are specified, this function will configure clang-tidy for all four valid languages.

Configure clang-tidy globally

oranges_create_clang_tidy_target
oranges_create_clang_tidy_target ([CONFIG_FILE <file>] | [NO_DEFAULT_CONFIG]
                                  [EXTRA_ARGS <args...>]
                                  [COMPILE_COMMANDS_ONLY])

Creates a custom target named clang-tidy that executes clang-tidy over the entire source tree.

If the CLANGTIDY_OFF variable is set to ON, this function does nothing.

If the current CMake run will generate a CompileCommands.json file (supported by the Makefile and Ninja generators, and enabled with the CMAKE_EXPORT_COMPILE_COMMANDS option), then this file will be used for clang-tidy to process the source tree. Otherwise, source files will be globbed under CMAKE_SOURCE_DIR, unless the COMPILE_COMMANDS_ONLY option is provided.

Note that all arguments are optional. Options:

CONFIG_FILE

May be specified to provide a custom .clang-tidy file to be used for running clang-tidy. If a relative path is given, it will be evaluated relative to the value of CMAKE_CURRENT_LIST_DIR when this function is called. If this argument is not specified, the value of the CLANGTIDY_CONFIG_FILE variable will be used, unless the NO_DEFAULT_CONFIG option is given. Providing this argument is equivalent to passing EXTRA_ARGS --config-file=<file>.

NO_DEFAULT_CONFIG

If this option is given, then the value of the CLANGTIDY_CONFIG_FILE variable will not be used as the .clang-tidy file; instead, clang-tidy’s default behavior of searching for a .clang-tidy in a parent directory of the current source file will be used.

EXTRA_ARGS

Extra arguments that will be passed verbatim to the clang-tidy executable. If not specified, the value of the CLANGTIDY_EXTRA_ARGS variable will be used.

COMPILE_COMMANDS_ONLY

If this option is given, then the clang-tidy target will only be created if the current CMake run will produce a CompileCommands.json, and otherwise this function will do nothing and raise no warnings or errors (a VERBOSE message will be output).

Cache variables

CLANGTIDY_PROGRAM

Path to the clang-tidy executable, used by oranges_enable_clang_tidy(). An environment variable with this name may also be set.

CLANGTIDY_CONFIG_FILE

This variable may be set to a .clang-tidy file that will be used for all calls to oranges_enable_clang_tidy() that do not explicitly provide their own config file. The environment variable with this name, if set, will initialize this cache variable.

CLANGTIDY_EXTRA_ARGS

This variable may be set to a list of space-separated arguments that will be passed to clang-tidy verbatim for the oranges_enable_clang_tidy() command. The environment variable with this name, if set, will initialize this cache variable.

CLANGTIDY_OFF

When this variable is set to ON, calls to oranges_enable_clang_tidy() do nothing. If an environment variable with this name is set, it will initialize this cache variable’s value; otherwise, this variable will default to OFF.

Environment variables

CLANGTIDY_PROGRAM

Initializes the value of the CLANGTIDY_PROGRAM variable.

CLANGTIDY_CONFIG_FILE

Initializes the CLANGTIDY_CONFIG_FILE variable.

CLANGTIDY_EXTRA_ARGS

Initializes the CLANGTIDY_EXTRA_ARGS variable.

CLANGTIDY_OFF

Initializes the CLANGTIDY_OFF variable.

See also

Module OrangesCppcheck

Module for cppcheck

Module OrangesCpplint

Module for cpplint

Module OrangesIWYU

Module for include-what-you-use

Module OrangesStaticAnalysis

Aggregate module for enabling all static analysis tools