Is there a way to get clang-format to correctly format a CMake file?
I have a .clang-format
file with Language: Cpp
and BasedOnStyle: Google
. No other language is specified.
Ideally, I would like to customize the style, however the biggest problem right now is, that clang-format indents many lines. The longer the file, the more levels of indentation I get.
Questions:
- Is there a way to get clang-format to recognize a
CMakeLists.txt
as a different language than Cpp? - Does clang-format have the capabilities for me to add rules for the CMake language?
- Does an alternative to clang-format exist in this context?
Example
Input
cmake_minimum_required (VERSION 3.2)
project(HELLO)
add_executable (helloDemo demo.cxx demo_b.cxx)
add_executable (goodByeDemo goodbye.cxx goodbye_b.cxx)
Actual Output
cmake_minimum_required(VERSION 3.2) project(HELLO)
add_executable(helloDemo demo.cxx demo_b.cxx)
add_executable(goodByeDemo goodbye.cxx goodbye_b.cxx)
Expected output: Same as input. Or maybe no space between command and parenthesis.
A related question: Is there any utility that can reformat a cmake file
Clang-format cannot do this, but an alternative exists now: https://github.com/cheshirekow/cmake_format
Example -- Bad input:
Command:
Resulting output: