Compare commits

...

7 Commits

Author SHA1 Message Date
Martchus f8934f979d Add tidy test 2017-04-04 21:00:48 +02:00
Martchus 888ea56765 Call clang-format with all src files 2017-04-04 21:00:24 +02:00
Martchus 6f46a18dc1 Move creation of check target to BasicConfig.cmake
* So other tests like tidy check can be added
* Even if there are no tests after all, the
  check target shoudn't cause any problems
2017-04-04 20:56:50 +02:00
Martchus 2439ad6d38 Document tidying/clang-format 2017-04-04 19:58:49 +02:00
Martchus 790660c711 Adapt global.h.in to new coding style 2017-04-04 19:58:49 +02:00
Martchus 6c0f4d587d Ignore .clang-format
This symlink will be automatically created when
invoking `make tidy`. It is required because I
don't know how to specify the path for the
.clang-format file direclty.
2017-04-04 19:58:49 +02:00
Martchus d2f0f2e511 Add tidy target using clang-format 2017-04-04 19:58:49 +02:00
7 changed files with 172 additions and 24 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ Makefile*
# tests # tests
testfiles/output.* testfiles/output.*
# clang-format
/.clang-format

View File

@ -31,6 +31,7 @@ The library utilizes:
* cppunit for unit tests (optional) * cppunit for unit tests (optional)
* Doxygen for API documentation (optional) * Doxygen for API documentation (optional)
* Graphviz for diagrams in the API documentation (optional) * Graphviz for diagrams in the API documentation (optional)
* clang-format for tidying (optional)
#### Runtime dependencies #### Runtime dependencies
* The c++utilities library itself only needs * The c++utilities library itself only needs
@ -43,6 +44,7 @@ Just run:
``` ```
cd "path/to/build/directory" cd "path/to/build/directory"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="/final/install/location" "path/to/projectdirectory" cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="/final/install/location" "path/to/projectdirectory"
make tidy # format source files (optional)
make make
make check # build and run unit tests (optional) make check # build and run unit tests (optional)
make apidoc # build API documentation (optional) make apidoc # build API documentation (optional)

View File

@ -141,4 +141,68 @@ else()
set(QUICK_GUI OFF) set(QUICK_GUI OFF)
endif() endif()
# find coding style (use style from c++utilities if none included in own project dir)
set(CLANG_FORMAT_RULES "${CMAKE_CURRENT_SOURCE_DIR}/coding-style.clang-format")
if(CPP_UTILITIES_SOURCE_DIR AND NOT EXISTS "${CLANG_FORMAT_RULES}")
set(CLANG_FORMAT_RULES "${CPP_UTILITIES_SOURCE_DIR}/coding-style.clang-format")
endif()
if(NOT EXISTS "${CLANG_FORMAT_RULES}")
set(CLANG_FORMAT_RULES "${CPP_UTILITIES_CONFIG_DIRS}/codingstyle.clang-format")
endif()
# add autotools-style check target
if(NOT TARGET check)
set(CMAKE_CTEST_COMMAND ${CMAKE_CTEST_COMMAND} -V)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
# enable testing
enable_testing()
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
message(STATUS "For the check target to work, it is required to call enable_testing() on the source directory root.")
endif()
# add target for tidying with clang-format
if(EXISTS "${CLANG_FORMAT_RULES}")
find_program(CLANG_FORMAT_BIN clang-format)
if(CLANG_FORMAT_BIN)
set(FORMATABLE_FILES ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${QML_HEADER_FILES} ${QML_SRC_FILES})
if(FORMATABLE_FILES)
list(REMOVE_ITEM FORMATABLE_FILES "")
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tidy"
COMMAND "${CLANG_FORMAT_BIN}" -style=file -i ${FORMATABLE_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Tidying ${META_PROJECT_NAME} sources using clang-format"
)
if(NOT TARGET tidy)
add_custom_target(tidy)
endif()
add_dependencies(tidy "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tidy")
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_link_codingstyle"
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CLANG_FORMAT_RULES}" "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format"
COMMENT "Linking coding style from ${CLANG_FORMAT_RULES}"
)
add_dependencies("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tidy" "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_link_codingstyle")
# also add a test to verify whether sources are tidy
add_test(NAME "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tidy_test"
COMMAND "${CLANG_FORMAT_BIN}" -output-replacements-xml -style=file ${FORMATABLE_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
set_tests_properties("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tidy_test" PROPERTIES
FAIL_REGULAR_EXPRESSION "<replacement.*>.*</replacement>"
)
endif()
else()
message(WARNING "clang-format not found; unable to add tidy target")
endif()
else()
message(WARNING "No rules to invoke clang-format for ${META_PROJECT_NAME} present")
endif()
set(BASIC_PROJECT_CONFIG_DONE YES) set(BASIC_PROJECT_CONFIG_DONE YES)

View File

@ -22,22 +22,6 @@ if(CPP_UNIT_LIB)
set(META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PRIVATE_SHARED_COMPILE_DEFINITIONS}) set(META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PRIVATE_SHARED_COMPILE_DEFINITIONS})
endif() endif()
# add autotools-style check target and enable testing
if(NOT TARGET check)
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
# enable testing
enable_testing()
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
message(STATUS "For the check target to work, it is required to call enable_testing() on the source directory root.")
endif()
# add target for test executable, but exclude it from the "all target" when EXCLUDE_TESTS_FROM_ALL is set # add target for test executable, but exclude it from the "all target" when EXCLUDE_TESTS_FROM_ALL is set
if(EXCLUDE_TESTS_FROM_ALL) if(EXCLUDE_TESTS_FROM_ALL)
set(TESTS_EXCLUSION EXCLUDE_FROM_ALL) set(TESTS_EXCLUSION EXCLUDE_FROM_ALL)

View File

@ -7,11 +7,11 @@
#include @GENERAL_GLOBAL_H_INCLUDE_PATH@ #include @GENERAL_GLOBAL_H_INCLUDE_PATH@
#ifdef @META_PROJECT_VARNAME_UPPER@_STATIC #ifdef @META_PROJECT_VARNAME_UPPER@_STATIC
# define @META_PROJECT_VARNAME_UPPER@_EXPORT #define @META_PROJECT_VARNAME_UPPER@_EXPORT
# define @META_PROJECT_VARNAME_UPPER@_IMPORT #define @META_PROJECT_VARNAME_UPPER@_IMPORT
#else #else
# define @META_PROJECT_VARNAME_UPPER@_EXPORT LIB_EXPORT #define @META_PROJECT_VARNAME_UPPER@_EXPORT LIB_EXPORT
# define @META_PROJECT_VARNAME_UPPER@_IMPORT LIB_IMPORT #define @META_PROJECT_VARNAME_UPPER@_IMPORT LIB_IMPORT
#endif #endif
/*! /*!

95
coding-style.clang-format Normal file
View File

@ -0,0 +1,95 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 150
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 8
UseTab: Never
...

View File

@ -7,11 +7,11 @@
#include "./application/global.h" #include "./application/global.h"
#ifdef CPP_UTILITIES_STATIC #ifdef CPP_UTILITIES_STATIC
# define CPP_UTILITIES_EXPORT #define CPP_UTILITIES_EXPORT
# define CPP_UTILITIES_IMPORT #define CPP_UTILITIES_IMPORT
#else #else
# define CPP_UTILITIES_EXPORT LIB_EXPORT #define CPP_UTILITIES_EXPORT LIB_EXPORT
# define CPP_UTILITIES_IMPORT LIB_IMPORT #define CPP_UTILITIES_IMPORT LIB_IMPORT
#endif #endif
/*! /*!