Is there any utility that can reformat a cmake fil

2019-04-29 02:01发布

问题:

I have relatively complex cmake files and I am wondering if there is any utility that can reformat a cmakeList.txt and beautify it for easier reading?

Some simple tricks would do the jobs, such as indenting if else endif sections and so on.

Is there any such tools?

I am using notepad++ for editing, but if there is any other tools, I can switch.

回答1:

Take a look at Atom and its plugin language-cmake (you can install easily with Atom package manager).

Once both are installed, open your CMakeLists.txt and go to Edit > Lines > Auto Indent.



回答2:

Someone recently wrote a CMake autoformatter called cmake_format. Still under development but should be good enough for basic CMake files.



回答3:

I searched for a code beautifier supporting CMake, and I did not find any.

  • There is this thread on CMake mailing lists, which does not provide a good solution
  • This mailing list thread provides no answer too (some use emacs mode)
  • I checked most of the major code beautifiers using UniversalIndentGUI on Ubuntu. None of the provided beautifiers from the long list are working with CMake out of the box.

Looks like implementing CMake support in an existing beautifier, or writing a custom one is a great idea for a nice code project.