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:
CMakeLists.txt
as a different language than Cpp?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:
cmake_minimum_required(VERSION 3.2) project(HELLO)
add_executable(helloDemo demo.cxx demo_b.cxx)
add_executable(goodByeDemo goodbye.cxx goodbye_b.cxx)
Command:
pip install --user cmake_format # Or sudo to install system-wide
cmake-format -i CMakeLists.txt
Resulting 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With