2

There are clang-format etc to ensure a consistent coding style for .cpp and .h files among different developers.

But how can I ensure consistent coding style in CMake for CMakeLists.txt and FindXXX.cmake written from different developers?

The main rules I want to enforce is consistent indention/space, upper/lower case consistency, 80 character per line constraint

user3667089
  • 2,996
  • 5
  • 30
  • 56
  • 3
    Off topic question here, sorry! – πάντα ῥεῖ Sep 08 '15 at 21:56
  • why is this question off topic? – user3667089 Sep 08 '15 at 23:17
  • I don't see how this is off-topic either, but anyway - I can't say I've ever heard of such a script/tool for CMake code. – Fraser Sep 09 '15 at 01:42
  • 1
    Some of the very basic things I ensure with [`.editorconfig`](http://editorconfig.org/). Can you give an example of the rules you want to enforce? There are some specific solutions like [Tools for upper/lower case consistency in CMake source](http://stackoverflow.com/questions/22839458/tools-for-upper-lower-case-consistency-in-cmake-source) or [`cmake-lint`](https://github.com/richq/cmake-lint). – Florian Sep 09 '15 at 07:47
  • 2
    Because looking for external resources (like books, tools) is off-topic. – usr1234567 Sep 09 '15 at 08:06
  • @Florian Excellent answer! I would accept your answer if it's not a comment. The main rules I want to enforce is consistent indention/space, upper/lower case consistency (as you mentioned), 80 character per line constraint. – user3667089 Sep 09 '15 at 09:02

1 Answers1

4

Turning my comments into an answer

I don't know of a way to enforce CMakeLists.txt or other CMake script file's coding style in CMake itself. But there are editor extensions and format checkers available you can use:

  • Some of the very basic things I ensure with .editorconfig

    • You can configure: indent_style, indent_size, tab_width, end_of_line, charset, trim_trailing_whitespace and insert_final_newline
    • And there are EditorConfig plug-ins for a lot of editors available (if not supported out-of-the-box)
  • With cmake-lint you can check/filter for a few more rules

    • It has filters for e.g. convention/filename, linelength, package/consistency, readability/logic, readability/mixedcase, readability/wonkycase or syntax
  • And there is Tools for upper/lower case consistency in CMake source
Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149