问题
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
回答1:
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_whitespaceandinsert_final_newline - And there are EditorConfig plug-ins for a lot of editors available (if not supported out-of-the-box)
- You can configure:
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/wonkycaseorsyntax
- It has filters for e.g.
- And there is Tools for upper/lower case consistency in CMake source
来源:https://stackoverflow.com/questions/32467743/how-to-ensure-consistent-coding-style-for-cmakelists-txt-and-findxxx-cmake