Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clang format #220

Merged
merged 8 commits into from
Feb 27, 2024
Merged
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
46 changes: 46 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
Language: Cpp
BasedOnStyle: LLVM
AllowShortFunctionsOnASingleLine: None
AlwaysBreakAfterReturnType: All
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
ColumnLimit: 100
PackConstructorInitializers: Never
ConstructorInitializerIndentWidth: 2
Cpp11BracedListStyle: false
IndentCaseLabels: true
NamespaceIndentation: All
PointerAlignment: Left
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpacesBeforeTrailingComments: 2
SpaceAfterTemplateKeyword: true
AlignEscapedNewlines: Left
FixNamespaceComments: false
ContinuationIndentWidth: 2
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
SpaceInEmptyBlock: true
UseTab: Never
...
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,37 @@ endif(TESTS)
# CDash #
##########################################################################
include(Dart)

##########################################################################
# CLANG-FORMAT #
##########################################################################
find_program(
CLANG_FORMAT_EXECUTABLE
NAMES "clang-format"
DOC "Path to clang-format executable"
)
if(NOT CLANG_FORMAT_EXECUTABLE)
message(STATUS "clang-format not found.")
else()
message(STATUS "clang-format found: ${CLANG_FORMAT_EXECUTABLE}")
set(DO_CLANG_FORMAT "${CLANG_FORMAT_EXECUTABLE}" -i -style=file)
endif()

if(CLANG_FORMAT_EXECUTABLE)
add_custom_target(
clang-format-core-sources
COMMAND "${CLANG_FORMAT_EXECUTABLE}" -i -style=file ${DUNE_CORE_HEADERS} ${DUNE_CORE_SOURCES}
)
add_custom_target(
clang-format-programs
COMMAND "${CLANG_FORMAT_EXECUTABLE}" -i -style=file ${programs}
)
add_custom_target(
clang-format-tests
COMMAND "${CLANG_FORMAT_EXECUTABLE}" -i -style=file ${DUNE_TESTS_SOURCES}
)
add_custom_target(
clang-format-tasks
COMMAND "${CLANG_FORMAT_EXECUTABLE}" -i -style=file ${ALL_TASK_SOURCES} ${ALL_TASK_HEADERS}
)
endif()
7 changes: 7 additions & 0 deletions cmake/Tasks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
# Author: Ricardo Martins #
############################################################################

set(ALL_TASK_SOURCES)
set(ALL_TASK_HEADERS)


macro(dune_add_task root_folder task)
string(REPLACE "/Task.cmake" "" path ${task})

Expand Down Expand Up @@ -105,6 +109,9 @@ macro(dune_add_task root_folder task)
file(GLOB TASK_HEADERS ${root_folder}/${path}/*.hpp)
endif(NOT TASK_HEADERS)

set(ALL_TASK_SOURCES ${ALL_TASK_SOURCES} ${TASK_SOURCES})
set(ALL_TASK_HEADERS ${ALL_TASK_HEADERS} ${TASK_HEADERS})

if(TASK_PROGRAM)
foreach(task_main_source ${TASK_PROGRAM})
set(program)
Expand Down
52 changes: 52 additions & 0 deletions programs/scripts/dune-clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
############################################################################
# Copyright 2007-2019 Universidade do Porto - Faculdade de Engenharia #
# Laboratório de Sistemas e Tecnologia Subaquática (LSTS) #
############################################################################
# This file is part of DUNE: Unified Navigation Environment. #
# #
# Commercial Licence Usage #
# Licencees holding valid commercial DUNE licences may use this file in #
# accordance with the commercial licence agreement provided with the #
# Software or, alternatively, in accordance with the terms contained in a #
# written agreement between you and Faculdade de Engenharia da #
# Universidade do Porto. For licensing terms, conditions, and further #
# information contact lsts@fe.up.pt. #
# #
# Modified European Union Public Licence - EUPL v.1.1 Usage #
# Alternatively, this file may be used under the terms of the Modified #
# EUPL, Version 1.1 only (the "Licence"), appearing in the file LICENCE.md #
# included in the packaging of this file. You may not use this work #
# except in compliance with the Licence. Unless required by applicable #
# law or agreed to in writing, software distributed under the Licence is #
# distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF #
# ANY KIND, either express or implied. See the Licence for the specific #
# language governing permissions and limitations at #
# https://github.com/LSTS/dune/blob/master/LICENCE.md and #
# http://ec.europa.eu/idabc/eupl.html. #
############################################################################
# Author: Jose Pinto #
############################################################################

# This script can be used to format all committed source files using
# clang-format. It can also be added used as .git/hooks/pre-commit script

format_file() {
file="${1}"
if [ -f $file ]; then
clang-format -i ${1}
git add ${1}
fi
}

case "${1}" in
--help )
echo "Runs clang-format on locally committed source files"
;;
* )
for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(c|cpp|h|hpp)$' ` ; do
echo "Applying clang-format to ${file}..."
format_file "${file}"
done
;;
esac