From 153c035a519750ca4c48eddbb0c8bc8cc543428a Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Mon, 13 Jun 2022 13:08:06 +0200 Subject: [PATCH] Adding a clang format configuration and target Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- .clang-format | 70 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 ++ config/Sources.cmake | 13 +++++++ config/ext/ClangFormat.cmake | 11 ++++++ 4 files changed, 96 insertions(+) create mode 100644 .clang-format create mode 100644 config/ext/ClangFormat.cmake diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..a7d1ab45 --- /dev/null +++ b/.clang-format @@ -0,0 +1,70 @@ +BasedOnStyle: WebKit +IndentWidth: 4 +ColumnLimit: 100 + +Language: Cpp +Standard: c++20 +DerivePointerAlignment: false + +PointerAlignment: Left +ReferenceAlignment: Right + +SortIncludes: CaseSensitive + +AccessModifierOffset: -4 + +AlignAfterOpenBracket: true +AlignArrayOfStructures: Left +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: Left +AlignOperands: AlignAfterOperator +AlignTrailingComments: true + +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterColon +BreakStringLiterals: true + +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: false + +AlwaysBreakTemplateDeclarations: Yes +EmptyLineBeforeAccessModifier: Always + +BinPackParameters: true +ReflowComments: true + +ShortNamespaceLines: 0 +NamespaceIndentation: All +FixNamespaceComments: true + +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Leave +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false + +TabWidth: 4 +UseTab: Never + +UseCRLF: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f70c78f..9166150f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(vkcv) # cmake options option(BUILD_MODULES "Enables building VkCV as shared libraries" ON) option(BUILD_PROJECTS "Enables building the VkCV projects" ON) +option(BUILD_CLANG_FORMAT "Enables formatting the source code" ON) option(BUILD_DOXYGEN_DOCS "Enables building the VkCV doxygen documentation" OFF) option(BUILD_SHARED "Enables building VkCV as shared libraries" OFF) option(BUILD_VMA_VULKAN_VERSION "Enforce a specific Vulkan version for VMA" OFF) @@ -15,6 +16,7 @@ endif() message(STATUS "Options:") message(" - BUILD_MODULES: ${BUILD_MODULES}") message(" - BUILD_PROJECTS: ${BUILD_PROJECTS}") +message(" - BUILD_CLANG_FORMAT: ${BUILD_CLANG_FORMAT}") message(" - BUILD_DOXYGEN_DOCS: ${BUILD_DOXYGEN_DOCS}") message(" - BUILD_SHARED: ${BUILD_SHARED}") diff --git a/config/Sources.cmake b/config/Sources.cmake index 2efd34c3..f0fd0ed7 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -112,4 +112,17 @@ set(vkcv_sources ${vkcv_include}/vkcv/BlitDownsampler.hpp ${vkcv_source}/vkcv/BlitDownsampler.cpp + + ${vkcv_include}/vkcv/Sampler.hpp + + ${vkcv_include}/vkcv/Result.hpp ) + +if (BUILD_CLANG_FORMAT) + message(STATUS "Clang-Format: ON") + + # add clang-format as target if installed + include(${vkcv_config}/ext/ClangFormat.cmake) +else() + message(STATUS "Clang-Format: OFF") +endif() diff --git a/config/ext/ClangFormat.cmake b/config/ext/ClangFormat.cmake new file mode 100644 index 00000000..723fd7a9 --- /dev/null +++ b/config/ext/ClangFormat.cmake @@ -0,0 +1,11 @@ + +if (EXISTS "/usr/bin/clang-format") + # note the option ALL which allows to format the source together with the application + add_custom_target( clang_format ALL + COMMAND /usr/bin/clang-format -style=file --sort-includes -i ${vkcv_sources} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Formatting code with Clang-Format" + VERBATIM ) +else () + message(WARNING "Doxygen need to be installed to generate the doxygen documentation") +endif () -- GitLab