Skip to main content

A simple linter for CMake.

Project description

check-cmake

A simple linter for CMake.

Installation

check-cmake requires Python 3.8 or higher.

pip3 install check-cmake

Usage

check-cmake is a command-line application

usage: check-cmake [-h] [-v] [--version] [--recurse | --no-recurse] [--limit LIMIT] [root]

CMake checker for C and C++ projects.

positional arguments:
  root                  path to the project root (default: .)

options:
  -h, --help            show this help message and exit
  -v, --verbose         enable verbose output
  --version             print the version and exit
  --recurse, --no-recurse
                        recurse into subfolders (default: True)
  --limit LIMIT         maximum errors to emit (default: 0)

v0.3.0 - github.com/marzer/check-cmake

Exit codes

Value Meaning
0 No issues were found
N, where N is a positive integer N issues were found in total
-1 A fatal error occurred

Example output

error: /my_lib/CMakeLists.txt:29:9: language standard level should be set on a per-target basis using target_compile_features()
  Context:
    29 | set_target_properties(
    30 |     my_lib
    31 |     PROPERTIES
    32 |         CXX_STANDARD 14
    33 |         CXX_STANDARD_REQUIRED ON
    34 |         CXX_EXTENSIONS OFF
    35 | )
  Replace with:
    target_compile_features(): https://cmake.org/cmake/help/latest/command/target_compile_features.html
  More information:
    CMAKE_CXX_KNOWN_FEATURES: https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
    CMAKE_C_KNOWN_FEATURES: https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_C_KNOWN_FEATURES.html

found 1 error in 1 file.

Suppressing checks

Checks can be suppressed using comment-based 'pragmas' at the end of the source line:

set_target_properties(
    my_lib
    PROPERTIES
        CXX_STANDARD 14 # nocheck
        CXX_STANDARD_REQUIRED ON
        CXX_EXTENSIONS OFF
)

For compatibility with other tools, any the following will also work:

# nolint

# check-cmake ignore
# lint-cmake ignore
# cmake-check ignore
# cmake-lint ignore

# check-cmake disable
# lint-cmake disable
# cmake-check disable
# cmake-lint disable

# check-cmake: ignore
# lint-cmake: ignore
# cmake-check: ignore
# cmake-lint: ignore

# check-cmake: disable
# lint-cmake: disable
# cmake-check: disable
# cmake-lint: disable

Changelog

v0.5.1

  • Fixed false positive for incorrect use of SYSTEM in target_include_directories() in some cases

v0.5.0

  • Added check for add_library() with implicit type (STATIC, SHARED, et cetera)

v0.4.0

  • Fixed line numbers sometimes being wrong in context snippets
  • Added check for incorrectly-placed SYSTEM in target_include_directories()
  • Added check for extraneous space in ExternalProject_Add() CMAKE_ARGS

v0.3.0

  • Fixed #nocheck

v0.2.0

  • Added pragmas for ignoring checks on a line
  • Added check for cmake_minimum_required() when project() is present
  • Fixed minor formatting issues

v0.1.0

  • First public release 🎉️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

check_cmake-0.5.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

check_cmake-0.5.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file check_cmake-0.5.1.tar.gz.

File metadata

  • Download URL: check_cmake-0.5.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for check_cmake-0.5.1.tar.gz
Algorithm Hash digest
SHA256 50a8aa4a0d8afc3a2b49b8f2eecdc0559667f477ad85cf7c9a7d818bc0bcc421
MD5 6961c41b38bb2a1e4bc3f1cd7a328421
BLAKE2b-256 e8ba0c5bb54eec33451e62508b5f80b98f5dd80283e77edb48273bd472ec2c11

See more details on using hashes here.

File details

Details for the file check_cmake-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: check_cmake-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for check_cmake-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d04acc7f03d372b7f8981cf7a2843018129f26ea0d7005dd76315a00d8a85d3d
MD5 a1475278a45127ec48af735e100a3d21
BLAKE2b-256 fe6c1e2aedee0395a8b0d5a0ee5bea84fd93ef4f51709a73b85de277c458e0c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page