Metadata-Version: 2.4
Name: check_cmake
Version: 0.6.0
Summary: A simple linter for CMake.
Author-email: Mark Gillard <mark.gillard@outlook.com.au>
License-Expression: MIT
Project-URL: Source, https://github.com/marzer/check-cmake
Project-URL: Tracker, https://github.com/marzer/check-cmake/issues
Project-URL: Funding, https://github.com/sponsors/marzer
Keywords: c++,cmake
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: C
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: misk>=0.8.1
Requires-Dist: colorama
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff==0.15.14; extra == "dev"
Requires-Dist: pyright==1.1.409; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Dynamic: license-file

# check-cmake

A simple linter for CMake.

## Installation

`check-cmake` requires Python 3.9 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.5.3 - github.com/marzer/check-cmake
```

## Exit codes

| Value | Meaning                                |
| :---- | :------------------------------------- |
| 0     | No issues were found                   |
| 1     | Issues were found                      |
| 2     | The arguments were invalid             |
| 255   | A fatal error occurred (-1 on Windows) |

## 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:

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

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

```cmake
# 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
```

## Contributing

See [CONTRIBUTING.md](https://github.com/marzer/check-cmake/blob/main/CONTRIBUTING.md).

# Changelog

## v0.6.0 - 2026-10-15

- fixed `--limit` stopping only the current directory, so later directories still reported issues
- fixed output order varying with the file system's directory order
- fixed the `Threads::Threads` example printing a literal `\n`
- fixed the `ExternalProject_Add()` example printing `${{CMAKE_CXX_COMPILER}}`
- fixed context snippets not highlighting an issue at the very end of the snippet
- fixed `--help` showing the `--recurse` default twice on older Python versions
- raised the minimum Python version to 3.9

## v0.5.3 - 2025-08-07

- Fixed `# nocheck` not working in some rare circumstances

## v0.5.2 - 2025-01-04

- Fixed internal `Path.relative_to()` error when used inside a virtual environment

## v0.5.1 - 2024-10-15

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

## v0.5.0 - 2024-03-25

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

## v0.4.0 - 2024-01-17

- 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 - 2024-01-13

- Fixed `#nocheck`

## v0.2.0 - 2024-01-11

- 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 - 2024-01-10

- First public release 🎉
