Add format-tests target

This commit is contained in:
Richard Berger 2020-06-15 11:21:43 -04:00
parent d5d28bcbd2
commit e840fa23f1
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# Find clang-format
find_program(ClangFormat_EXECUTABLE NAMES clang-format
clang-format-10.0
clang-format-9.0
clang-format-8.0
clang-format-7.0
clang-format-6.0
DOC "clang-format executable")
mark_as_advanced(ClangFormat_EXECUTABLE)
if(ClangFormat_EXECUTABLE)
# find version
execute_process(COMMAND ${ClangFormat_EXECUTABLE} --version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(clang_format_version MATCHES "^clang-format version .*")
# Arch Linux
# clang-format version 10.0.0
# Ubuntu 18.04 LTS Output
# clang-format version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
string(REGEX REPLACE "clang-format version ([0-9.]+).*"
"\\1"
ClangFormat_VERSION
"${clang_format_version}")
elseif(clang_format_version MATCHES ".*LLVM version .*")
# CentOS 7 Output
# LLVM (http://llvm.org/):
# LLVM version 3.4.2
# Optimized build.
# Built Nov 1 2018 (15:06:24).
# Default target: x86_64-redhat-linux-gnu
# Host CPU: x86-64
string(REGEX REPLACE ".*LLVM version ([0-9.]+).*"
"\\1"
ClangFormat_VERSION
"${clang_format_version}")
else()
set(ClangFormat_VERSION "0.0")
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ClangFormat REQUIRED_VARS ClangFormat_EXECUTABLE VERSION_VAR ClangFormat_VERSION)

View File

@ -5,3 +5,13 @@ add_subdirectory(force-styles)
add_subdirectory(utils)
add_subdirectory(formats)
find_package(ClangFormat)
if(ClangFormat_FOUND)
set(UNITTEST_SOURCES)
file(GLOB_RECURSE UNITTEST_SOURCES *.cpp *.h)
add_custom_target(format-tests
COMMAND ${ClangFormat_EXECUTABLE} --verbose -i -style=file ${UNITTEST_SOURCES}
DEPENDS ${UNITTEST_SOURCES})
endif()