Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

48 changes: 48 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
Checks: '-*,clang-diagnostic-*,google*,-google-runtime-references,-google-readability-braces-around-statements,misc*,-misc-unused-parameters'
WarningsAsErrors: ''
HeaderFilterRegex: 'shad/.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
User: minu455
CheckOptions:
- key: google-build-namespaces.HeaderFileExtensions
value: h,hh,hpp,hxx
- key: google-global-names-in-headers.HeaderFileExtensions
value: h
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.BranchThreshold
value: '4294967295'
- key: google-readability-function-size.LineThreshold
value: '4294967295'
- key: google-readability-function-size.NestingThreshold
value: '4294967295'
- key: google-readability-function-size.ParameterThreshold
value: '4294967295'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: google-runtime-int.SignedTypePrefix
value: int
- key: google-runtime-int.TypeSuffix
value: ''
- key: google-runtime-int.UnsignedTypePrefix
value: uint
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ if (POLICY CMP0048)
set(cmake_3_0_LANGUAGES LANGUAGES)
endif()

# Add path for custom CMake modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)

if (NOT PACKAGE_VERSION)
set(PACKAGE_VERSION
"${GMT_VERSION_MAJOR}.${GMT_VERSION_MINOR}.${GMT_VERSION_PATCH}")
Expand Down Expand Up @@ -51,6 +57,9 @@ if (CMAKE_BUILD_TYPE AND
endif()


include(config)

set(GMT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(GMT_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(GMT_MAIN_INCLUDE_DIR ${GMT_MAIN_SRC_DIR}/include)
set(GMT_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
Expand Down Expand Up @@ -84,3 +93,20 @@ install(DIRECTORY ${GMT_MAIN_INCLUDE_DIR}/gmt
PATTERN "*~" EXCLUDE
PATTERN "CMakeLists.txt"
)

# Adding clang-format target if executable is found
if(CLANG_FORMAT_EXE)
# Additional targets to perform clang-format/clang-tidy
# Get all project files
file(GLOB_RECURSE
ALL_CXX_SOURCE_FILES
*.[chi]pp *.[chi]xx *.cc *.hh *.ii *.[CHI] *.[ch]
)

add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT_EXE}
-i
${ALL_CXX_SOURCE_FILES}
)
endif()
29 changes: 29 additions & 0 deletions cmake/CheckClangTools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable")

if(CLANG_TIDY_EXE)
set(
DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-p=${GMT_BINARY_DIR} -format-style=file")
message(STATUS "ClangTidy found: ${CLANG_TIDY_EXE}")
if (NOT CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
else()
message(STATUS "ClangTidy not found.")
endif()

find_program(
CLANG_FORMAT_EXE
NAMES "clang-format"
DOC "Path to clang-format executable")

if (CLANG_FORMAT_EXE)
message(STATUS "ClangFormat found: ${CLANG_FORMAT_EXE}")
if (NOT CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
else()
message(STATUS "ClangFormat not found.")
endif()
1 change: 1 addition & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(CheckClangTools)
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ include_directories(${THREADS_PTHREADS_INCLUDE_DIR})

add_library(gmt ${sources})
set_target_properties(gmt PROPERTIES LINKER_LANGUAGE CXX)
if (CLANG_TIDY_EXE)
set_target_properties(gmt PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
endif()
target_link_libraries(gmt ${MPI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS gmt DESTINATION lib)
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ set_source_files_properties(main.c PROPERTIES LANGUAGE CXX )

add_executable(gmttest main.c)
set_target_properties(gmttest PROPERTIES LINKER_LANGUAGE CXX)
if (CLANG_TIDY_EXE)
set_target_properties(gmttest PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
endif()
target_link_libraries(gmttest gmttestlib gmt ${MPI_LIBRARIES})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh ${CMAKE_CURRENT_BINARY_DIR}/run_test.sh COPYONLY)