Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
Turcksin, Bruno R authored and jeanlucf22 committed Aug 20, 2019
1 parent 4715204 commit 5c31b64
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ test:
script:
- mkdir build
- cd build
- cmake -DBUILD_FOR_GPU=ON -DCMAKE_PREFIX_PATH=/opt/magma ..
- cmake -DBUILD_FOR_GPU=ON -DPLA_WITH_CLANG_FORMAT=ON -DCMAKE_PREFIX_PATH=/opt/magma ..
- make
- ctest
- make format
- git diff --exit-code
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ set(Boost_COMPONENTS
)
find_package(Boost 1.65 REQUIRED COMPONENTS ${Boost_COMPONENTS})

# clang-format (optional)
set(PLA_WITH_CLANG_FORMAT FALSE CACHE BOOL "Indent code with clang-format")
if(${PLA_WITH_CLANG_FORMAT})
find_package(CLANG_FORMAT)
if(${CLANG_FORMAT_FOUND})
message(STATUS "Indent with clang-format")
file(GLOB_RECURSE FORMAT_SOURCES src/*.cc src/*.h src/*.cpp src/*.hpp
tests/*.cc tests/*.h tests/*.cpp tests/*.hpp)
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES}
DEPENDS ${FORMAT_SOURCES})
endif()
endif()

enable_testing()

add_subdirectory(src)
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
gcc \
gfortran \
build-essential \
clang-format \
wget \
curl \
bison \
Expand Down
31 changes: 31 additions & 0 deletions cmake/FindCLANG_FORMAT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Find clang-format
#
# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable
# CLANG_FORMAT_FOUND - True if clang-format executable was found
# CLANG_FORMAT_VERSION - The version of clang-format found

find_program(CLANG_FORMAT_EXECUTABLE
NAMES clang-format clang-format-6.0
DOC "clang-format executable")
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)

# Extract version
if (CLANG_FORMAT_EXECUTABLE)
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (clang_format_version MATCHES "^clang-format version .*")
# clang_format_version sample: "clang-format version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)"
string(REGEX REPLACE "clang-format version ([.0-9]+).*" "\\1"
CLANG_FORMAT_VERSION "${clang_format_version}")
endif()
if (NOT CLANG_FORMAT_VERSION STREQUAL "6.0.0" AND
NOT CLANG_FORMAT_VERSION STREQUAL "6.0.1")
message(SEND_ERROR "Wrong clang-format version. Please use clang-format 6.0.")
endif()
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION)

0 comments on commit 5c31b64

Please sign in to comment.