-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for compilation target 'format'
* clang-format 6.0 or above * skip files in doc/ * search all possible clang-format names * might work in cmake 3.5 * added support for windows style paths
- Loading branch information
1 parent
0d78358
commit 72c0000
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
AccessModifierOffset: '0' | ||
AlwaysBreakAfterReturnType : All | ||
AlwaysBreakTemplateDeclarations: 'true' | ||
BreakBeforeBraces: Linux | ||
Language: Cpp | ||
NamespaceIndentation: All | ||
SpaceBeforeParens: Always | ||
Standard: Cpp11 | ||
TabWidth: 2 | ||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# select all files with correct c++ extensions | ||
file(GLOB_RECURSE | ||
ALL_CXX_SOURCE_FILES | ||
*.[ch] *.[chi]pp *.[chi]xx *.cppm *.cc *.hh *.ii *.[CHI] | ||
) | ||
|
||
# exclude the docs **for now** | ||
set(EXCLUDE_REGEX ".*doc[\\|/].*") | ||
if(${CMAKE_VERSION} VERSION_LESS "3.6.0") | ||
foreach(PROPOSED_FILE ${ALL_CXX_SOURCE_FILES}) | ||
string(REGEX MATCH ${EXCLUDE_REGEX} regex_found ${PROPOSED_FILE}) | ||
if(regex_found) | ||
list(REMOVE_ITEM ${ALL_CXX_SOURCE_FILES} ${PROPOSED_FILE}) | ||
endif() | ||
endforeach() | ||
else() | ||
list(FILTER ALL_CXX_SOURCE_FILES EXCLUDE REGEX ${EXCLUDE_REGEX}) | ||
endif() | ||
|
||
find_program(CLANG_FORMAT | ||
NAMES clang-format | ||
# backup names | ||
clang-format-9.0 clang-format-8.0 clang-format-7.0 clang-format-6.0 | ||
clang-format-9 clang-format-8 clang-format-7 clang-format-6 | ||
) | ||
|
||
# search for version number in clang-format without version number | ||
if(CLANG_FORMAT) | ||
execute_process( | ||
COMMAND sh "-c" | ||
"${CLANG_FORMAT} --version | grep -oE '[0-9]' | head -n 1" | ||
OUTPUT_VARIABLE CLANG_FORMAT_VERSION | ||
) | ||
if(${CLANG_FORMAT_VERSION} GREATER_EQUAL 6) | ||
set(CLANG_FORMAT_CORRECT ${CLANG_FORMAT}) | ||
endif() | ||
endif() | ||
|
||
if(CLANG_FORMAT_CORRECT) | ||
message(STATUS "Using ${CLANG_FORMAT_CORRECT} for target 'format'") | ||
add_custom_target( | ||
format | ||
COMMAND ${CLANG_FORMAT_CORRECT} | ||
-i | ||
-style=file | ||
${ALL_CXX_SOURCE_FILES} | ||
) | ||
else() | ||
message(WARNING "No suitable clang-format (version >= 6.0) found") | ||
endif() |