{"id":4908,"library":"cmakelang","title":"CMake Language Tools","description":"The `cmakelang` project provides Quality Assurance (QA) and other language tools for CMake. It includes command-line tools like `cmake-annotate` for generating HTML, `cmake-format` for source code formatting, `cmake-lint` for checking common issues, and `ctest-to` for parsing CTest output. The project, currently at version 0.6.13, is actively maintained with a regular release cadence. While the PyPI package is now `cmakelang`, the GitHub repository is still named `cmake_format`.","status":"active","version":"0.6.13","language":"en","source_language":"en","source_url":"https://github.com/cheshirekow/cmakelang","tags":["cmake","linter","formatter","qa","build-system","code-quality"],"install":[{"cmd":"pip install cmakelang","lang":"bash","label":"Standard Install"},{"cmd":"pip install cmakelang[YAML]","lang":"bash","label":"Install with YAML config support"},{"cmd":"pip install cmakelang[html-gen]","lang":"bash","label":"Install with HTML annotator support"}],"dependencies":[{"reason":"Required for reading YAML-formatted configuration files.","package":"pyyaml","optional":true},{"reason":"Required for generating HTML annotations with cmake-annotate.","package":"jinja2","optional":true},{"reason":"Optional dependency for shell command completion.","package":"argcomplete","optional":true}],"imports":[{"note":"The `cmakelang` library primarily exposes its functionality via command-line tools like `cmake-format` and `cmake-lint`, rather than a public Python API for direct programmatic import into application code. Direct imports from submodules are generally not considered part of the public API.","wrong":"from cmakelang.format import Formatter","symbol":"cmake-format (command-line tool)","correct":"Run `cmake-format <file>` from your shell."}],"quickstart":{"code":"import os\n\ncmake_content_before = '''\ncmake_minimum_required(VERSION 3.0)\n\nproject(MyProject)\n\nset(SOURCES\n    main.cpp\n    anotherfile.cpp\n    thirdfile.cpp)\n\nadd_executable(MyProject ${SOURCES})\n'''\n\ncmake_file_path = \"CMakeLists.txt\"\n\nwith open(cmake_file_path, \"w\") as f:\n    f.write(cmake_content_before)\n\nprint(\"--- CMakeLists.txt (Before Formatting) ---\")\nprint(cmake_content_before)\n\n# Run cmake-format in-place\nprint(\"\\nRunning cmake-format...\")\n# For quickstart, using os.system for simplicity, in production consider subprocess.run\nexit_code = os.system(f\"cmake-format -i {cmake_file_path}\")\n\nif exit_code == 0:\n    with open(cmake_file_path, \"r\") as f:\n        cmake_content_after = f.read()\n    print(\"\\n--- CMakeLists.txt (After Formatting) ---\")\n    print(cmake_content_after)\n    print(\"\\nFormatting successful!\")\nelse:\n    print(f\"\\nError: cmake-format exited with code {exit_code}\")\n\n# Clean up\nos.remove(cmake_file_path)\n","lang":"python","description":"This quickstart demonstrates how to use `cmake-format` to automatically reformat a CMakeLists.txt file. It creates a sample file, formats it in-place, and then prints the before and after content. This highlights the primary command-line interface of the `cmakelang` tools."},"warnings":[{"fix":"Update your installation commands from `pip install cmake-format` to `pip install cmakelang`. Existing `cmake-format` installs will pull in `cmakelang` as a dependency, but direct usage of `cmakelang` is recommended.","message":"The project's Python package name officially changed from `cmake-format` to `cmakelang` around version 0.6.12/0.6.13. The old `cmake-format` PyPI package is now a transitional, empty package that depends on `cmakelang`.","severity":"breaking","affected_versions":"0.6.12+"},{"fix":"Review your configuration files and consider updating them to the new structure. You can generate a default configuration in your preferred format using `cmake-format --dump-config [yaml|json|python]` as a starting point.","message":"Configuration file datastructures were overhauled in v0.5.0. While legacy configuration files (without sections) are still supported, they may be deprecated in the future, and default formatting for some commands (e.g., `set()`) changed due to parser logic updates.","severity":"breaking","affected_versions":"0.5.0+"},{"fix":"Install with feature flags (e.g., `pip install cmakelang[YAML]` or `pip install cmakelang[html-gen]`) or manually install the required Python packages (`pip install pyyaml` / `pip install jinja2`).","message":"Optional features like YAML configuration file support (`pyyaml`) or HTML annotation (`jinja2`) require additional, non-default dependencies.","severity":"gotcha","affected_versions":"All"},{"fix":"Add detailed specifications for your custom commands to your `cmakelang` configuration file (e.g., in `additional_commands` section) to guide the formatter and linter.","message":"`cmake-format` relies on user-provided specifications in its configuration file to correctly understand and format custom CMake commands (macros/functions). Without these, formatting of custom commands may be suboptimal or incorrect.","severity":"gotcha","affected_versions":"All"},{"fix":"If `cmake-format --dump-config` fails, try executing it from a clean directory (e.g., `/` or `/tmp`) to ensure no corrupt local configuration files interfere.","message":"When running `cmake-format --dump-config`, the tool will attempt to load any automatically detected configuration files in the current or parent directories. If these files are corrupt or un-parsable, `dump-config` may fail.","severity":"gotcha","affected_versions":"All"},{"fix":"Be aware that external references (e.g., `git clone` URLs) might still use `cmake_format`, and these may change if the repository is officially renamed.","message":"The GitHub repository is still named `cmake_format`, even though the PyPI package and project name are `cmakelang`. The documentation indicates the repository may be moved in the future.","severity":"deprecated","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}