{"id":20406311,"url":"https://github.com/anybotics/cmake_clang_tools","last_synced_at":"2026-02-14T04:02:51.278Z","repository":{"id":79035265,"uuid":"373400636","full_name":"ANYbotics/cmake_clang_tools","owner":"ANYbotics","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-13T04:08:09.000Z","size":134,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":20,"default_branch":"master","last_synced_at":"2026-01-13T07:47:05.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ANYbotics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-06-03T06:13:45.000Z","updated_at":"2026-01-13T04:08:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"d513040f-540a-47cf-8f90-ae17a1589b46","html_url":"https://github.com/ANYbotics/cmake_clang_tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ANYbotics/cmake_clang_tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ANYbotics%2Fcmake_clang_tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ANYbotics%2Fcmake_clang_tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ANYbotics%2Fcmake_clang_tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ANYbotics%2Fcmake_clang_tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ANYbotics","download_url":"https://codeload.github.com/ANYbotics/cmake_clang_tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ANYbotics%2Fcmake_clang_tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29435410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T03:34:37.767Z","status":"ssl_error","status_checked_at":"2026-02-14T03:34:09.092Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T05:16:28.051Z","updated_at":"2026-02-14T04:02:51.263Z","avatar_url":"https://github.com/ANYbotics.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cmake_clang_tools\n\n# Overview\n\nThis package provides cmake helper macros in order to run clang-tidy and clang-format on your code.\n\nIt also contains python scripts that wrap around those tools to adapt their behavior.\n\nThe source code is released under a [BSD 3-Clause license](LICENSE).\n\n**Author(s):** Gabriel Hottiger\n\n# Installation\n\n## Dependencies\n* clang\n* clang-tidy\n* clang-format\n\n## Build\nBoth catkin and plain CMake builds are supported.\n\n### Catkin\n\nTo build `cmake_clang_tools` with catkin run the following command.\n\n```\n  catkin build cmake_clang_tools\n```\n\n### CMake\n\nTo install `cmake_clang_tools` run the following commands in the root folder of the repository.\n\n```\n  mkdir -p build\n  cd build\n  cmake ..\n  make                              # local build\n  sudo make install                 # install in /usr/local\n```\n\n## Uninstall\n\nTo uninstall `cmake_clang_tools` run the following commands in the root folder of the repository.\n\n```\n  cd build\n  sudo make uninstall               # uninstall from /usr/local\n```\n\n# Usage\n\n## Enabling cmake_clang_tools in your project.\n\nIn order to use `cmake_clang_tools` in your CMake/catkin project you will have to add the following steps.\n\n#### Package.xml (for catkin only)\n\n```\n\u003cbuild_depend\u003ecmake_clang_tools\u003c/build_depend\u003e\n```\n\n#### CMakeLists.txt\n\n**Default usage**\n\nThe default macro `add_default_clang_tooling` sets reasonable default values for the arguments of `add_clang_tooling`.\nIt assumes that the source code of the package is located in folders named `src`, `include` and `test`.\nThis macro will fix formatting issues during compilation.\nIf all targets are present in the list (`${PROJECT_NAME}`, `${PROJECT_NAME}_core`,\n`${PROJECT_NAME}_node`, `test_${PROJECT_NAME}`, `test_${PROJECT_NAME}_core`, `test_${PROJECT_NAME}_node`) the `TARGETS` option can be omitted.\n\n```\n# Generate compile_commands.json (needed if clang-tidy is run)\nset(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n# Add your project lib and/or executable (e.g. myLib, myExec)\n\n# Add clang tooling to your target\nfind_package(cmake_clang_tools QUIET)\nif(cmake_clang_tools_FOUND)\n  add_default_clang_tooling(\n    TARGETS myLib myExec\n  )\nendif(cmake_clang_tools_FOUND)\n```\n**Advanced usage**\n```\n# Generate compile_commands.json (needed if clang-tidy is run)\nset(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n# Add your project lib and/or executable (e.g. myLib, myExec)\n\n# Add clang tooling to your target\nfind_package(cmake_clang_tools QUIET)\nif(cmake_clang_tools_FOUND)\n  add_clang_tooling(\n    TARGETS myLib myExec\n    SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include\n    CT_HEADER_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include\n    CF_FIX\n  )\nendif(cmake_clang_tools_FOUND)\n```\n\nSome example flags were used for the add_clang_tooling cmake macro, see below for a complete list.\n\n## Running cmake_clang_tools\n\nThe format checking/fixing (using clang-format) happens before the source code is built and is triggered automatically on every build.\n\nThe static analysis (using clang-tidy) has two run behaviors.\nPer default, the static analysis is executed when the `run_static_analysis` CMake target is built.\nTo run static analysis for `my_package` run the following command:\n\n```\ncatkin build --catkin-make-args run_static_analysis -- my_package --no-deps\n```\nYou can configure clang-tidy to run on every build, by setting the `ATTACH_TO_ALL` option for clang tidy.\nThis is only recommended in combination with toggling of the `cmake_clang_tools` configuration (described in the next section).\nOtherwise, it can lead to significant compile time overhead during the development phase.\n\n## Configure cmake_clang_tools\n\nYou can configure `cmake_clang_tools` with a config file located at ```/home/$USER/.config/cmake_clang_tools/config.yaml```. \nThe file will be generated with the following default configuration on it's first run.\n\n```\n# Toggle execution of clang-format (true/false).\nrun_clang_format: true\n# Toggle execution of clang-tidy (true/false).\nrun_clang_tidy: true\n# Only run cmake_clang_tools for the packages contained in this whitelist.\n# Empty list -\u003e run on all packages.\nwhitelist: { }\n# Don't run cmake_clang_tools for the packages contained in this blacklist.\n# Empty list -\u003e run on all packages.\nblacklist: { }\n```\n\nWith the first two arguments you can toggle execution of `clang_tidy` and `clang_format`.\nThis is meant as a temporary solution while developing, since `clang_tidy` can increase compile time quite a bit.\n\nIf you only want to run `cmake_clang_tools` on some packages, you can configure a whitelist. \nYou can also exclude packages by blacklisting them.\nThis is useful if you are the maintainer of only a subset of packages that you compile from source.\n\n# Tools\n\n## clang-format\n\n### Disable formatting\n\nTo disable formatting temporarily use:\n```\nEigen::Matrix2d m;  // clang-format off\nm \u003c\u003c 2.0, 3.0\n     4.0, 5.0;      // clang-format on\n```\n\n### .clang-format\n\nThe formatting options can be configured with a `.clang-format` file. \n\nSee the [List of Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html).\n\nCurrent Settings: Check out the `.clang-format` file in the `config` folder.\n\n## clang-tidy\n\n### Disable checks\n\nTo disable checks temporarily use:\n```\n// Silent all the diagnostics for the line\nFoo(int param); // NOLINT\n\n// Silent only the specified checks for the line\nFoo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)\n\n// Silent only the specified diagnostics for the next line\n// NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)\nFoo(bool param);\n```\n\n### .clang-tidy\n\nThe code check options can be configured with a `.clang-tidy` file.\n\nSee the [List of Checks](http://clang.llvm.org/extra/clang-tidy/checks/list.html).\n\nCurrent Settings: Check out the `.clang-tidy` file in the `config` folder.\n\n# CMake macros\n\n## add_default_clang_tooling\n```\nADD_DEFAULT_CLANG_TOOLING(TARGETS target1 .. targetN\n                          [SOURCE_DIRS sourceDir1 .. sourceDirN]\n                          [DISABLE_CLANG_TIDY]\n                          [CT_WERROR]\n                          [CT_FIX]\n                          [CT_QUIET]\n                          [CT_ATTACH_TO_ALL]\n                          [CT_CONFIG_FILE ct_config_path]\n                          [CT_HEADER_DIRS dir1 .. dirN]\n                          [CT_HEADER_EXCLUDE_DIRS excludeDir1 .. excludeDirN]\n                          [CT_HEADER_FILTER header_filter]\n                          [CT_BUILD_DIR build_dir]\n                          [CT_CHECKS check1 .. checkN]\n                          [DISABLE_CLANG_FORMAT]\n                          [CF_WERROR]\n                          [CF_NO_FIX]\n                          [CF_QUIET]\n                          [CF_CONFIG_FILE cf_config_path])\n```\n**CF_NO_FIX** Don't fix formatting issues\n\nFor the remaining options check the `add_clang_tooling` macro.\n\n## add_clang_tooling\n```\nADD_CLANG_TOOLING(TARGETS target1 .. targetN\n                  [SOURCE_DIRS sourceDir1 .. sourceDirN]\n                  [DISABLE_CLANG_TIDY]\n                  [CT_WERROR]\n                  [CT_FIX]\n                  [CT_QUIET]\n                  [CT_ATTACH_TO_ALL]\n                  [CT_CONFIG_FILE ct_config_path]\n                  [CT_HEADER_DIRS dir1 .. dirN]\n                  [CT_HEADER_EXCLUDE_DIRS excludeDir1 .. excludeDirN]\n                  [CT_HEADER_FILTER header_filter]\n                  [CT_BUILD_DIR build_dir]\n                  [CT_CHECKS check1 .. checkN]\n                  [DISABLE_CLANG_FORMAT]\n                  [CF_WERROR]\n                  [CF_FIX]\n                  [CF_QUIET]\n                  [CF_CONFIG_FILE cf_config_path])\n```\n**SOURCE_DIRS** Directories for which clang tools are ran\n\n**DISABLE_CLANG_TIDY** Don't run clang-tidy\n\n**DISABLE_CLANG_FORMAT** Don't run clang-format\n\n\nFor the remaining options check the following macros, where CT stands form clang-tidy and CF for clang-format.\n\n## add_clang_format\n```\nADD_CLANG_FORMAT(TARGETS target1 .. targetN\n                 [SOURCES source1 .. sourceN]\n                 [WERROR]\n                 [FIX]\n                 [QUIET]\n                 [CONFIG_FILE config_path])\n```\n**TARGETS** Targets for which clang-format is ran on POST_BUILD\n\n**SOURCES** Source files to run clang-format on\n\n**WERROR** Treat formatting issues as errors\n\n**FIX** Fix formatting issues inline\n\n**QUIET** Output to stdout instead of stderr\n\n**CONFIG_FILE** Clang-format config file to be used (default: .clang-format in this repo)\n\n\n## add_clang_tidy\n```\nADD_CLANG_TIDY(TARGETS target1 .. targetN\n               [SOURCES source1 .. sourceN]\n               [WERROR]\n               [FIX]\n               [QUIET]\n               [ATTACH_TO_ALL]\n               [CONFIG_FILE config_path]\n               [HEADER_DIRS dir1 .. dirN]\n               [HEADER_EXCLUDE_DIRS excludeDir1 .. excludeDirN]\n               [HEADER_FILTER header_filter]\n               [BUILD_DIR build_dir]\n               [CHECKS check1 .. checkN])\n```\n**TARGETS** Targets for which clang-tidy is run on POST_BUILD\n\n**SOURCES** Source files to run clang-tidy on\n\n**WERROR** Treat all clang-tidy warnings as errors\n\n**FIX** Fix clang-tidy issues inline (**Not Recommended!**)\n\n**QUIET** Output to stdout instead of stderr\n\n**ATTACH_TO_ALL** Attach the clang-tidy target to the ALL target. Runs clang-tidy on every build.\n\n**CONFIG_FILE** Clang-tidy config file to be used (default: .clang-tidy in this repo)\n\n**HEADER_DIRS** Header directories, all include directories of your project\n\n**HEADER_EXCLUDE_DIRS** Header directories to exclude from HEADER_DIRS (*Thus HEADER_DIRS must be set!*)\n\n**HEADER_FILTER** Header filter, regular expression (*,|) to filter headers. Only active if HEADER_DIRS are not set. (default: .\\*)\n\n**BUILD_DIR** Build directory of the target, compile_commands.json should be located in here. (default: ${CMAKE_CURRENT_BINARY_DIR})\n\n**CHECKS** Add/remove checks to/from the configuration file (default: [])\n           Use the check name to add a new check or prefix the check name with `-` to remove it.\n           See [list of clang-tidy checks](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html).\n\n\n# Editors\n\n## CLion\n\nClang format and clang tidy are built-in tools in CLion. Add the `.clang-tidy` and `.clang-format` files to the root of your project path.\nJetbrains provides setup instructions for [clang format](https://blog.jetbrains.com/clion/2019/01/clion-opens-2019-1-eap-clangformat-disasm-lldb-injected-languages/#clangformat_support)\nand [clang tidy](https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html#conffiles).\n\n## Eclipse\n\nThere exist plugins to support clang tooling for eclipse.\n\n### Add clang format as a plugin\n[See here](https://marketplace.eclipse.org/content/cppstyle)\n\n### Add clang tidy as a plugin\n[See here](https://github.com/Ericsson/CodeCheckerEclipsePlugin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanybotics%2Fcmake_clang_tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanybotics%2Fcmake_clang_tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanybotics%2Fcmake_clang_tools/lists"}