Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3188 from kunaltyagi/qoc
Adding support for compilation target 'format'
- Loading branch information
Showing
5 changed files
with
142 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,23 @@ | ||
--- | ||
AlwaysBreakAfterReturnType: All | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
BraceWrapping: | ||
AfterFunction: true | ||
AfterClass: false | ||
AfterStruct: false | ||
BeforeElse: true | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
BreakBeforeBraces: Custom | ||
BreakConstructorInitializers: BeforeComma | ||
ColumnLimit: 88 | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 0 | ||
Language: Cpp | ||
PointerAlignment: Left | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#! /usr/bin/env sh | ||
|
||
# sample command line usage: $0 clang-format(version >= 6.0) $PCL_SOURCE_DIR | ||
# $ sh ./.dev/format.sh `which clang-format` ./ | ||
# $ sh format.sh `which clang-format` ../ | ||
# $ sh ~/pcl/format.sh `which clang-format` ~/pcl | ||
# $ sh /pcl/format.sh `which clang-format` /pcl | ||
|
||
format() { | ||
# don't use a directory with whitespace | ||
local whitelist="2d cuda gpu ml simulation stereo tracking" | ||
|
||
local PCL_DIR="${2}" | ||
local formatter="${1}" | ||
|
||
if [ ! -f "${formatter}" ]; then | ||
echo "Could not find a clang-format. Please specify one as the first argument" | ||
exit 166 | ||
fi | ||
|
||
# check for self | ||
if [ ! -f "${PCL_DIR}/.dev/format.sh" ]; then | ||
echo "Please ensure that PCL_SOURCE_DIR is passed as the second argument" | ||
exit 166 | ||
fi | ||
|
||
for dir in ${whitelist}; do | ||
path=${PCL_DIR}/${dir} | ||
find ${path} -type f -iname *.[ch] -o -iname *.[ch]pp -o -iname *.[ch]xx \ | ||
-iname *.cu | xargs -n1 ${formatter} -i -style=file | ||
done | ||
} | ||
|
||
format $@ |
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,72 @@ | ||
# | ||
# .rst: FindClangFormat | ||
# --------------- | ||
# | ||
# The module defines the following variables | ||
# | ||
# ``ClangFormat_EXECUTABLE`` Path to clang-format executable | ||
# ``ClangFormat_FOUND`` True if the clang-format executable was found. | ||
# ``ClangFormat_VERSION`` The version of clang-format found | ||
# | ||
# Example usage: | ||
# | ||
# .. code-block:: cmake | ||
# | ||
# find_package(ClangFormat) | ||
# if(ClangFormat_FOUND) | ||
# message("clang-format executable found: ${ClangFormat_EXECUTABLE}\n" | ||
# "version: ${ClangFormat_VERSION}") | ||
# endif() | ||
|
||
find_program(ClangFormat_EXECUTABLE | ||
NAMES | ||
clang-format-9 | ||
clang-format-9.0 | ||
clang-format-8 | ||
clang-format-8.0 | ||
clang-format-7 | ||
clang-format-7.0 | ||
clang-format-6.0 | ||
clang-format-5.0 | ||
clang-format-4.0 | ||
clang-format-3.9 | ||
clang-format-3.8 | ||
clang-format-3.7 | ||
clang-format-3.6 | ||
clang-format-3.5 | ||
clang-format-3.4 | ||
clang-format-3.3 | ||
clang-format # least priority | ||
DOC "clang-format executable") | ||
mark_as_advanced(ClangFormat_EXECUTABLE) | ||
|
||
# Extract version from command "clang-format -version" | ||
if(ClangFormat_EXECUTABLE) | ||
execute_process(COMMAND ${ClangFormat_EXECUTABLE} -version | ||
OUTPUT_VARIABLE clang_format_version | ||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
endif() | ||
set(version_regex "^.*clang-format version ([.0-9]+).*") | ||
if(clang_format_version MATCHES ${version_regex}) | ||
# clang_format_version samples: | ||
# * clang-format version 3.9.1-4ubuntu3~16.04.1 (tags/RELEASE_391/rc2) | ||
# * Alpine clang-format version 8.0.0 (tags/RELEASE_800/final) (based on LLVM 8.0.0) | ||
string(REGEX | ||
REPLACE ${version_regex} | ||
"\\1" | ||
ClangFormat_VERSION | ||
"${clang_format_version}") | ||
# ClangFormat_VERSION sample: "3.9.1", "8.0.0" | ||
endif() | ||
unset(clang_format_version) | ||
unset(version_regex) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args( | ||
ClangFormat | ||
REQUIRED_VARS | ||
ClangFormat_EXECUTABLE | ||
ClangFormat_VERSION | ||
VERSION_VAR | ||
ClangFormat_VERSION | ||
) |
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,12 @@ | ||
find_package(ClangFormat 6) | ||
# search for version number in clang-format without version number | ||
if(ClangFormat_FOUND) | ||
message(STATUS "Adding target 'format'") | ||
add_custom_target( | ||
format | ||
COMMAND sh | ||
${PCL_SOURCE_DIR}/.dev/format.sh | ||
${ClangFormat_EXECUTABLE} | ||
${PCL_SOURCE_DIR} | ||
) | ||
endif() |