Skip to content
This repository has been archived by the owner on Mar 22, 2020. It is now read-only.

DaelDe/cmake_check

Repository files navigation

NPM

Build status Known Vulnerabilities

cmake_check

Cmake_check is a linter for the CMake language. It takes a set of user-defined rules and reports violations for CMakeLists.txt files and CMake modules.

Step 1: Download cmake_check (several methods, see below).

Step 2: Open a terminal (cmd.exe on Windows).

Step 3: Invoke cmake_check to check your CMake files or directories. The executable name differs depending on whether you use the development source version (cmake_check), a Windows executable (cmake_check.exe) or , a Linux executable (cmake_check). On this page, cmake_check is the generic term used to refer to any of these.

a file

prompt> cmake_check -i CMakeLists.txt -v
info: Checking CMakeLists.txt
CMakeLists(10).txt (66) : warning Whitelist: calls to some_custom_function are not allowed by whitelist
info: Checked 1 files
info: 0 files are clean
info: 1 files have 2 warnings
info: 0 files are ignored
info: took {"durationMs":28}

a directory

prompt> cmake_check -i project_folder -v
info: Checking files in project_folder
project_folder/libFoo/CMakeLists.txt (66) : warning Whitelist: calls to some_custom_function are not allowed by whitelist
project_folder/libBar/CMakeLists.txt (50) : warning Whitelist: calls to some_other_custom_function are not allowed by whitelist
...
info: Checked 769 files
info: 186 files are clean
info: 583 files have 1566 warnings
info: 0 files are ignored
info: took {"durationMs":2270}

Cmake_check is a linter for the CMake language. It takes a set of user-defined rules and reports violations for CMakeLists.txt files and CMake modules. CMake_check is a command line application suitable for continuous integration checks. This is especially useful for large source trees with hundreds of CMake files. Cmake_check can be used to enforce a certain coding style or project/company guidelines. It is written in TypeScript and runs on every platform where node.js is available.

Features are:

  • recursive check of all CMake files in a given directory
  • allows combination of checks to form custom rules
  • a rule may consist of any number of checks
  • provides warning output (msbuild format) that can be used by the jenkins warnings plugin

Available checks:

  • require commands to exist (or not exist)
  • allow white-listed commands only (to limit the use of custom functions)

Planned checks:

  • require a specific command order
  • constraints on specific command arguments
  • constraints on paths (e.g. no ..)
  • comment checks
  • maximum line length
  • indentation checks

Each release comes with a set of Linux and Windows binaries.

Install NodeJS (version > 8.11).

npm install -g cmake_check

Cmake_check uses semantic versioning.

The basic use is:

cmake_check -i <input folder or file>

or with custom configuration:

cmake_check -c <config file> -i <input folder or file>

All CMake files in the given input folders are analyzed with the given configuration. All warnings are written to stdout.

For more information and further available options call cmake_check -h.

The documentation for the cmake_check configuration is available on a separate page.

Cmake_check uses a parser-generator and a grammar to create a parser of the CMake language. All CMakeLists.txt files from input are parsed to a structured object. All configured checks are executed on that object. Failed checks are printed as warnings.

  • the language parser will fail on CMakeLists.txt files that do not conform to the CMake language
    • these errors are reported by CMake itself, a successful run of CMake on the input files is a precondition for cmake_check

See the development board for issues that are in work.