diff --git a/.clang-format b/.clang-format index 53dbe32..7bf7ac8 100644 --- a/.clang-format +++ b/.clang-format @@ -3,27 +3,29 @@ Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveBitFields: false -AlignConsecutiveDeclarations: false +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None AlignEscapedNewlines: Left AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: true +AllowShortEnumsOnASingleLine: false AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability BinPackArguments: true BinPackParameters: true BraceWrapping: @@ -46,6 +48,7 @@ BraceWrapping: SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon @@ -57,46 +60,49 @@ BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE IncludeBlocks: Regroup IncludeCategories: - - Regex: '^' - Priority: 2 - SortPriority: 0 - - Regex: '^<.*\.h>' + - Regex: '^$' Priority: 1 - SortPriority: 0 - - Regex: '^<.*' + - Regex: '^<.*\.h>$' Priority: 2 - SortPriority: 0 - Regex: '.*' Priority: 3 - SortPriority: 0 IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false IndentCaseLabels: true IndentCaseBlocks: false IndentGotoLabels: true IndentPPDirectives: None IndentExternBlock: AfterExternBlock +IndentRequires: false IndentWidth: 2 IndentWrappedFunctionNames: false InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -114,7 +120,9 @@ PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 PointerAlignment: Left +PPIndentWidth: -1 RawStringFormats: - Language: Cpp Delimiters: @@ -143,31 +151,42 @@ RawStringFormats: - ParseTextProtoOrDie - ParseTestProto - ParsePartialTestProto - CanonicalDelimiter: '' + CanonicalDelimiter: pb BasedOnStyle: google +ReferenceAlignment: Pointer ReflowComments: true -SortIncludes: true +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: Never SpacesInConditionalStatement: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 SpacesInParentheses: false SpacesInSquareBrackets: false SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION @@ -178,5 +197,7 @@ WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME ... diff --git a/CMakeLists.txt b/CMakeLists.txt index 164ebca..b6f55ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.20) project(basiccmake LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(GlobalOptions) -include(GNUInstallDirs) -include(Format) - # keep PUBLIC dependencies in sync with cmake/config.cmake.in #find_package(foo REQUIRED) +include(AddAutoformatTarget) +include(GlobalOptions) +include(GNUInstallDirs) + add_subdirectory(src) install(DIRECTORY include TYPE INCLUDE FILES_MATCHING PATTERN *.h) diff --git a/cmake/AddAutoformatTarget.cmake b/cmake/AddAutoformatTarget.cmake new file mode 100644 index 0000000..548c2ac --- /dev/null +++ b/cmake/AddAutoformatTarget.cmake @@ -0,0 +1,28 @@ +find_program(clang-format_EXECUTABLE clang-format) +mark_as_advanced(clang-format_EXECUTABLE) + +if(clang-format_EXECUTABLE) + add_executable(clang-format IMPORTED) + set_target_properties(clang-format PROPERTIES + IMPORTED_LOCATION ${clang-format_EXECUTABLE}) +endif() + +function(add_autoformat_target target) + get_target_property(source_dir ${target} SOURCE_DIR) + get_target_property(sources ${target} SOURCES) + foreach(source ${sources}) + get_property(generated SOURCE ${source} PROPERTY GENERATED) + if(NOT ${generated}) + list(APPEND non_generated_sources ${source}) + endif() + endforeach() + add_custom_target(autoformat_${target} + COMMAND clang-format -i -- ${non_generated_sources} + WORKING_DIRECTORY ${source_dir} + COMMENT "Autoformating sources of target ${target}" + VERBATIM) + if(NOT TARGET autoformat) + add_custom_target(autoformat) + endif() + add_dependencies(autoformat autoformat_${target}) +endfunction() diff --git a/cmake/Format.cmake b/cmake/Format.cmake deleted file mode 100644 index 5feaebf..0000000 --- a/cmake/Format.cmake +++ /dev/null @@ -1,13 +0,0 @@ -file(GLOB_RECURSE all_sources - RELATIVE "${PROJECT_SOURCE_DIR}" - include/*.h src/*.cc src/*.h) -add_custom_target(${PROJECT_NAME}_format - COMMENT "Formating ${PROJECT_NAME} with clang-format" - COMMAND clang-format -style=file -i -- ${all_sources} VERBATIM - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") -unset(all_sources) - -if(NOT TARGET format) - add_custom_target(format) -endif() -add_dependencies(format ${PROJECT_NAME}_format) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 3232784..0c555d3 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -1,3 +1,3 @@ include(CMakeFindDependencyMacro) -#find_dependency(foo) +#find_dependency(foo @foo_VERSION@ REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd5c956..c705a3f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,13 @@ -add_executable(${PROJECT_NAME} main.cc) +add_executable(${PROJECT_NAME} + main.cc +) target_link_libraries(${PROJECT_NAME} PRIVATE ) target_include_directories(${PROJECT_NAME} PUBLIC $ - $) + $ +) + +add_autoformat_target(${PROJECT_NAME})