Skip to content

Commit

Permalink
Allow optional clang format of source files (off by default).
Browse files Browse the repository at this point in the history
  • Loading branch information
bashimao authored and rhdong committed Nov 17, 2022
1 parent bda2d58 commit b871c51
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CUDA_STANDARD 14)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

option(CLANGFORMAT "Clangformat code files before compiling" OFF)
if(CLANGFORMAT)
include(ClangFormat)
file(GLOB_RECURSE clangformat_includes
${PROJECT_SOURCE_DIR}/include/*.h
${PROJECT_SOURCE_DIR}/include/*.hpp
${PROJECT_SOURCE_DIR}/include/*.cuh
)
file(GLOB clangformat_tests
${PROJECT_SOURCE_DIR}/tests/*.c
${PROJECT_SOURCE_DIR}/tests/*.h
${PROJECT_SOURCE_DIR}/tests/*.cpp
${PROJECT_SOURCE_DIR}/tests/*.hpp
${PROJECT_SOURCE_DIR}/tests/*.cu
${PROJECT_SOURCE_DIR}/tests/*.cuh
)
set(clangformat_files ${clangformat_includes} ${clangformat_tests})
clangformat_setup("${clangformat_files}")
endif()

# Default to release build.
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/ClangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function(clangformat_setup clangformat_srcs)

add_custom_target(${PROJECT_NAME}_clangformat ALL
COMMAND ${CLANGFORMAT_EXECUTABLE}
-style=google
-style=file
-i
${clangformat_srcs}
COMMENT "Formating with ${CLANGFORMAT_EXECUTABLE} ...")
Expand Down

0 comments on commit b871c51

Please sign in to comment.