Check for coding style issues in CMake files

Overview

cmakelint parses CMake files and reports style issues.

cmakelint requires Python.

Installation

sudo pip install cmakelint

Usage

Syntax: cmakelint [--config=file] [--filter=-x,+y] <file> [file] ...
filter=-x,+y,...
  Specify a comma separated list of filters to apply

config=file
  Use the given file for configuration. By default the file
  $HOME/.cmakelintrc is used if it exists.  Use the value "None" to use no
  configuration file (./None for a file called literally None)
  Only the option "filter=" is currently supported in this file.

Run the --filter= option with no filter to see available options. Currently these are:

convention/filename
linelength
package/consistency
readability/logic
readability/mixedcase
readability/wonkycase
syntax
whitespace/eol
whitespace/extra
whitespace/indent
whitespace/mismatch
whitespace/newline
whitespace/tabs

An example .cmakelintrc file would be as follows:

filter=-whitespace/indent

With this file in your home directory, running these commands would have the same effect:

cmakelint.py CMakeLists.txt
cmakelint.py --filter=-whitespace/indent CMakeLists.txt

Output status codes

The program should exit with the following status codes:

  • 0 if everything went fine
  • 1 if an error message was issued
  • 32 on usage error

Changes

1.4

  • Add --quiet flag to suppress "Total Errors: 0"
  • Add --linelength=N flag to allow longer default lines (default remains 80)

1.3.4

  • fix false positives in indented blocks

1.3.3

  • fix crash on invalid # lint_cmake: pragma line
  • fix deprecation warning with Python 3.4
  • fix false positive warnings related to non-CMake quoted chunks (Issue #2)

1.3.2

  • return error code 0, 1, 32 on error

1.3.1

  • fix version number

1.3

  • individual CMake files can control filters with # lint_cmake: pragma comment
  • improved SetFilters function to allow spaces around the commas
  • use ${XDG_CONFIG_HOME} for the cmakelintrc file, with backwards compatible check for ~/.cmakelintrc

1.2.01

  • Published on pypi

1.2

  • Moved to github
Issues
  • allow files to control filters with a CMake comment

    allow files to control filters with a CMake comment

    Now you can add a filter, which is only for the current file, using a comment which starts with # lint_cmake: and is followed with a list of filters, separated by commas.

    Example:

    ...
    # Suppress linter warnings about FindPackageHandleStandardArgs and file name.
    # lint_cmake: -package/consistency, -convention/filename
    ...
    
    opened by wjwwood 4
  • Add command line argument to specify allowed line length

    Add command line argument to specify allowed line length

    Some projects might have convention to have longer lines in their CMake rules. For such cases added a command line argument --linelength which can be set to any value.

    This corresponds to Google cpplint's --linelength argument which is a nice thing.

    opened by sergeyvfx 3
  • Add --quiet command line argument

    Add --quiet command line argument

    Quiet makes output quiet unless errors occurs.

    Mainly used by automation tools when parsing huge amount of files. In those cases actual error might get lost in the pile of other stats prints.

    This argument is also handy for build system integration, so it's possible to add automated lint target to a project and invoke it via build system and have no pollution of terminals or IDE.

    For example when hooking cmakelint to a Ninja project without this argument oen will have screen filled with "Total Errors: 0" messages, which defeats all the idea of clean Ninja output.

    opened by sergeyvfx 1
  • improved the SetFilters function's implementation

    improved the SetFilters function's implementation

    It can now take a list or a comma separated string.

    The string can have spaces after the commas or not.

    Any other type results in a ValueError.

    Passing in filters from the command line still works.

    opened by wjwwood 1
  • standard wrapping for pypi projects

    standard wrapping for pypi projects

    Hi Richard,

    So getting things onto pypi is rather simple. Get a free account on pypi, add a setup.py to your project, then call $ python setup.py register # checks whether name is available and reservers it for you $ python setup.py sdist upload # creates an egg file for other to download

    Once this is done, people can install using pip.

    Commits from this pull request do that (create a setup.py), first shuffling files around a bit to be a bit more standards comformant. I took the liberty to put this on pypi (so people can as of now install using pip), but if you want to do this from now on, I can remove my cmakelint project from pypi and you can do that. Just let me know.

    Else for fun I also added my fork to travis-ci (It's free and works well with github), and then modified a few lines to make it run on py3k: https://travis-ci.org/tkruse/cmake-lint

    Since I had just done that with cpplint, and a lot of code seems to be similar between cpplint and cmakelint, it was not too hard to do (Did you create both, or just copy from one another?). One of these days I might also make the code more pep8 conformant.

    Also I changed the executable name from cmakelint.py to just cmakelint.

    opened by tkruse 0
  • Make the regular expression strings raw.

    Make the regular expression strings raw.

    This gets rid of DepcreationWarning about backslashes when running under python with debug enabled.

    Signed-off-by: Chris Lalancette [email protected]

    opened by clalancette 1
Owner
Richard Quirk
Richard Quirk
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.3k Aug 7, 2022
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 59 Jul 7, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 385 Aug 2, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 156 Jun 20, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 105 Jul 18, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 77 Jul 3, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 29 Apr 26, 2022
A program that automatically generates CMake and Meson configuration files for your Vala project

Autovala is a program and a library designed to help in the creation of projects with Vala and CMake. It also has support for Genie.

Sergio Costas 107 Apr 7, 2021
CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp

FindIDL CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp. Introduction Requirements Usage find_package() add_idl() ad

Apriorit Inc. 16 Jul 26, 2022
CMake project for BL602 RISC-V processor

bl602_cmake_base CMake project for BL602 RISC-V processor How to build NOTE : This project uses a pre-compiled version of the Buffalo SDK (bl_iot_sdk)

null 9 Jan 6, 2022
A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development

A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development

Alexander Widerberg 1.3k Aug 2, 2022
curl cmake module libcurl build with msvc x86

curl-msvc Infomation curl cmake module libcurl build with MSVC10.0 arch (x86 | i386) source from https://github.com/curl/curl tags: curl-7_79_1 Usage

Jason Payne 0 May 16, 2022
NeoWorld is a resampler using the CMake build system

NeoWorld is a resampler using the CMake build system. It's designed for utsu, OpenUTAU, and UTAU.

null 4 Jun 24, 2022
A CMake addon that avoids you writing boilerplate code for resource management.

SHader INJ(I)ector SHINJI (originally SHader INJector) is a CMake addon that avoids you writing boilerplate code for resource management and exposes s

Lorenzo Rutayisire 6 Mar 21, 2022
A CMake starter template using CPM

Cmake Starter About A lightweight Cmake project meant for a binary application (not a shared library), tests with catch2 are configured, CPM is the pa

Matt Williams 1 Jul 14, 2022
Non-intrusive CMake dependency management

cmodule Non-intrusive CMake dependency management. Normally CMake's find_package() looks for packages installed on host system (and compiled for host

scapix.com 13 Jun 16, 2022
Simple library for embedding static resources into C++ binaries using CMake

libromfs libromfs is an easy way to bundle resources directly into any C++ application and access them through a simple interface. The main advantage

WerWolv 25 Jul 29, 2022