basic_108
@Gitter :gitter.im/cnruby
- Requirements
- How to Install A Tool
'clang-format'
of FormattingC/C++
Code - Get the Project
- Use the Tool
'clang-format'
- Compare the Different Formatting Styles
- How to Format All
C/C++
Files - Final Summary
- References
- C/C++ Basic Concepts
- How to install the Tool
'clang-format'
on Ubuntu 20.04
- VS Code OR Eclipse Theia
- CMake
- Tool 'clang-format'
- Python 3.7+, optional
- Tool 'cmake_format', optional
# MacOS 12.10 above
brew install clang-format
git clone https://github.com/cnruby/w3h1_cmake.git basic_108
cd basic_108
git checkout basic_108
code .
cmake -GNinja -Bbuild/
cmake --build build/
# Clang format predefined styles
# styles = ( LLVM Google Chromium Mozilla WebKit Microsoft )
clang-format -style=Google src/main.cxx
clang-format -style=Google -i src/main.cxx
# the style file name must be ".clang-format"
clang-format -style=Google -dump-config
clang-format -style=Google -dump-config > .clang-format
clang-format -style=Mozilla -dump-config > .clang-format
# clang-format default style 'LLVM'
clang-format -style=file src/main.cxx
#<!-- markdown-exec(cmd:cat compare.cmake) -->#
# The File compare.cmake
set(STYLES LLVM Google Chromium Mozilla WebKit Microsoft)
foreach(style ${STYLES})
message("C/C++ style = <<${style}>>")
set(MAIN ${CMAKE_CURRENT_SOURCE_DIR}/src/main)
set(CMD
"clang-format -style=${style} ${MAIN}.cxx > \
${MAIN}.${style}.cpp")
message(${CMD})
execute_process(COMMAND clang-format -style=${style} ${MAIN}.cxx
OUTPUT_FILE ${MAIN}.${style}.cpp)
endforeach()
#<!-- /markdown-exec -->
# delete all files "src/main.*.c*"
# rm src/main.*.c*
# run the file 'compare.cmake'
cmake -P compare.cmake
#<!-- markdown-exec(cmd:cat format-clang.rb) -->#
# The File format-clang.rb
# format-clang.rb
# ls src/main.*.c*
# rm src/main.*.c*
# cmake -P compare.cmake
# ruby format-clang.rb
#EXTENSIONS = %w[cxx cpp hpp cu c h]
EXTENSIONS = %w[cxx cpp]
EXTENSIONS.each do |ext|
puts "ext = #{ext}"
`clang-format -style=file -i $(find . -name "*.#{ext}")`
end
#<!-- /markdown-exec -->
# run the file 'format-clang.rb'
ruby format-clang.rb
@Github: github.com/cnruby
@Twitter: twitter.com/cnruby
@Blogspot: cnruby.blogspot.com
- https://github.com/KratosMultiphysics/Kratos/wiki/How-to-configure-clang%E2%80%90format
- https://leimao.github.io/blog/Clang-Format-Quick-Tutorial/
- http://clang.llvm.org/docs/ClangFormat.html
- https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
- https://linuxhint.com/install-llvm-ubuntu/
- https://llvm.org/docs/GettingStarted.html
- https://clang.llvm.org/docs/ClangFormatStyleOptions.html
- command script cmake execute process shell
- https://gist.github.com/andrewseidl/8066c18e97c40086c183
- https://github.com/KratosMultiphysics/Kratos/wiki/How-to-configure-clang%E2%80%90format
- http://derekmolloy.ie/hello-world-introductions-to-cmake/
- https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
- The GNU Compiler Collection (GCC) is a collection of compilers and libraries for C, C++, Objective-C, Fortran, Ada, Go, and D programming languages.
- LLVM is a C/C++ compiler toolset just like GCC
- LLVM can compile C, C++ and Objective-C.
- Clang provided by the LLVM toolset is able to compile C and C++ codes faster than GCC.
- The LLVM debugger LLDB is much more memory efficient and very fast at loading symbols compared to GCC.
- LLVM supports C++11, C++14 and C++17 through libc++ and libc++ ABI projects.
- LLVM is available on Linux, Windows and Mac OS X. So it’s cross platform.
- The default GCC compiler in Ubuntu
- The default Clang compiler in MacOS
# https://cnruby.blogspot.com/2020/04/howto-install-clang-10include-clang-and.html
sudo apt-get install clang-tools-10