Format with clang-format
cmake
cmake_minimum_required(VERSION 3.28)
project(my-project)
add_executable(my-app main.c)
file(GLOB_RECURSE ALL_SOURCE_FILES
*.c *.h *.cpp *.hpp *.cxx *.hxx *.cc *.hh *.cppm *.ipp *.ixx)
add_custom_target(format
COMMAND clang-format
-i
${ALL_SOURCE_FILES}
)
c
#include <stdio.h>
int main( ){
puts( "Hello world!"
);
return 0;
}
sh
cmake -B build
cmake --build build --target format
# ✨ Now the code is formatted!
c
#include <stdio.h>
int main() {
puts("Hello world!");
return 0;
}