aboutsummaryrefslogtreecommitdiff
path: root/kde-modules
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-01-16 13:27:05 +0100
committerAlexander Lohnau <alexander.lohnau@gmx.de>2021-01-19 10:57:19 +0100
commita6be96a0c84b215de7f6fb397255af252adf7fc1 (patch)
tree0fdc4792f0275714b1c130059f4f456afa260627 /kde-modules
parentbe025ede6e0c42d7ac6c22d7a5d417beef9e9cd5 (diff)
downloadextra-cmake-modules-a6be96a0c84b215de7f6fb397255af252adf7fc1.tar.gz
extra-cmake-modules-a6be96a0c84b215de7f6fb397255af252adf7fc1.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.cmake9
2 files changed, 17 insertions, 0 deletions
diff --git a/kde-modules/KDEClangFormat.cmake b/kde-modules/KDEClangFormat.cmake
index 7f85508b..f1c98ae6 100644
--- a/kde-modules/KDEClangFormat.cmake
+++ b/kde-modules/KDEClangFormat.cmake
@@ -14,6 +14,8 @@
#
# Using this function will create a clang-format target that will format all
# ``<files>`` passed to the function with the predefined KDE clang-format style.
+# Since version 5.79 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:
#
@@ -27,6 +29,7 @@
#=============================================================================
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
+# SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
#
# SPDX-License-Identifier: BSD-3-Clause
@@ -40,6 +43,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 27298b8a..2a6a4f22 100644
--- a/kde-modules/KDEFrameworkCompilerSettings.cmake
+++ b/kde-modules/KDEFrameworkCompilerSettings.cmake
@@ -26,6 +26,7 @@
# SPDX-License-Identifier: BSD-3-Clause
include(KDECompilerSettings NO_POLICY_SCOPE)
+include(KDEClangFormat)
add_definitions(-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
@@ -64,3 +65,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
+
+# add clang-format target
+file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c)
+# The build folder should be skipped
+list(FILTER ALL_CLANG_FORMAT_SOURCE_FILES EXCLUDE REGEX "/build.*/")
+# The templates should also be skipped, clang-format would mess up the template macros
+list(FILTER ALL_CLANG_FORMAT_SOURCE_FILES EXCLUDE REGEX "templates/")
+kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})