Home

Awesome

Polysquare CMake Tooling Utility Functions

Utility and common library for all polysquare cmake tools.

Status

Travis CI (Ubuntu)AppVeyor (Windows)CoverageBiicodeLicence
TravisAppVeyorCoverallsBiicodeLicense

Description

tooling-cmake-util is used as a support library by modules like polysquare/veracpp-cmake, polysquare/cppcheck-target-cmakeand polysquare/clang-tidy-target-cmake. It provides functions useful to modules which provide integration with various static analysis tools for C++.

Usage

Running a static analysis tool on each source of a target

The most common pattern is to use psq_run_tool_for_each_source

psq_run_tool_for_each_source

Run a static analysis tool on each source file for TARGET. All of the target's C and C++ sources are extracted from its definition and the specified COMMAND is run on each of them. The string @SOURCE@ is replaced with the source file name in the arguments for COMMAND.

You can also run a tool on a single source file.

psq_run_tool_on_source

Run a static analysis tool on a source file during TARGET. All of the target's C and C++ sources are extracted from its definition and the specified COMMAND is run on each of them. The string @SOURCE@ is replaced with the source file name in the arguments for COMMAND.

Making a JSON Compilation Database

Some tools use the CMake JSON Compilation Database standard in order to mimic compiler invocations. This can usually be generated with CMAKE_EXPORT_COMPILE_COMMANDS but it doesn't capture everything. In particular, it will miss generated files.

tooling-cmake-util provides a psq_make_compilation_db function to ensure that a JSON compilation database is always written out in relation to a particular target specified during the configure stage.

psq_make_compilation_db

Creates a JSON Compilation Database in relation to the specified TARGET.

TARGET: Target to create JSON compilation database for. CUSTOM_COMPILATION_DB_DIR_RETURN: Variable to store location of compilation database for the specified TARGET

Filtering between source file types

Sometimes you need to distinguish between different types of source files when running static analysis tools. For instance, you might wish to avoid generated code when running style checks, or C source files when running a tool that assumes the language is C++. tooling-cmake-util provides helper functions for these cases.

psq_filter_out_generated_sources

Filter out generated sources from SOURCES and store the resulting list of sources in RESULT_VARIABLE.

For most projects, the convention is to not filter source files where CHECK_GENERATED is passed. A psq_handle_check_generated_option with a similar signature, and the first argument being the PREFIX argument passed to cmake_parse_arguments is provided. This detects if CHECK_GENERATED has been set and filters source arguments accordingly.

psq_sort_sources_to_languages

Separate headers from non-headers and C++ source files from C source files.

Utility functions

psq_add_switch

Specify certain command line switches depending on value of boolean variable.

psq_append_each_to_options_with_prefix

Append items in ARGN to MAIN_LIST, giving each PREFIX.

psq_get_list_intersection

Get the logical intersection between two lists and store it in DESTINATION.

psq_append_to_global_property_unique

Append ITEM to the global property PROPERTY, only if it is not already part of the list.

PROPERTY: Global property to append to. ITEM: Item to append, only if not present.