aboutsummaryrefslogtreecommitdiff
path: root/kde-modules
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-01-16 13:27:05 +0100
committerChristoph Cullmann <cullmann@kde.org>2021-02-10 23:23:40 +0000
commitda06fa05d8a20edab7c684a516d4a676889cc83b (patch)
tree5deac853fcc5dec9767b7cf045b287faaa2db623 /kde-modules
parent9d23e2943754afab9741c47ae135037498ad9d34 (diff)
downloadextra-cmake-modules-da06fa05d8a20edab7c684a516d4a676889cc83b.tar.gz
extra-cmake-modules-da06fa05d8a20edab7c684a516d4a676889cc83b.tar.bz2
Add clang-format target by default in KDEFrameworkCompilerSettings
To prevent cmake errors with exiting usages it is checked if the target already exists.
Diffstat (limited to 'kde-modules')
-rw-r--r--kde-modules/KDEClangFormat.cmake8
-rw-r--r--kde-modules/KDEFrameworkCompilerSettings.cmake7
2 files changed, 15 insertions, 0 deletions
diff --git a/kde-modules/KDEClangFormat.cmake b/kde-modules/KDEClangFormat.cmake
index b662b275..7889fde0 100644
--- a/kde-modules/KDEClangFormat.cmake
+++ b/kde-modules/KDEClangFormat.cmake
@@ -22,6 +22,8 @@
# added to version control. It is recommended to add it to the ``.gitignore`` file: ``/.clang-format``.
#
# Since 5.79: If the source folder already contains a .clang-format file it is not overwritten.
+# Since version 5.80 this function is called by default in KDEFrameworkCompilerSettings. If directories should be excluded from
+# the formatting a .clang-format file with "DisableFormat: true" and "SortIncludes: false" should be created.
#
# Example usage:
#
@@ -43,6 +45,7 @@
#=============================================================================
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
+# SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
#
# SPDX-License-Identifier: BSD-3-Clause
@@ -67,6 +70,11 @@ endif()
# formatting target
function(KDE_CLANG_FORMAT)
+ if (TARGET clang-format)
+ message(WARNING "the kde_clang_format function was already called")
+ return()
+ endif()
+
# add target without specific commands first, we add the real calls file-per-file to avoid command line length issues
add_custom_target(clang-format COMMENT "Formatting sources in ${CMAKE_CURRENT_SOURCE_DIR} with ${KDE_CLANG_FORMAT_EXECUTABLE}...")
diff --git a/kde-modules/KDEFrameworkCompilerSettings.cmake b/kde-modules/KDEFrameworkCompilerSettings.cmake
index 329be097..478039da 100644
--- a/kde-modules/KDEFrameworkCompilerSettings.cmake
+++ b/kde-modules/KDEFrameworkCompilerSettings.cmake
@@ -74,3 +74,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
+
+if (NOT ("${ECM_GLOBAL_FIND_VERSION}" VERSION_LESS "5.80.0"))
+ include(KDEClangFormat)
+ # add clang-format target
+ file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c)
+ kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
+endif ()