summaryrefslogtreecommitdiffstats
path: root/config/sanitizer/formatting.cmake
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2024-03-04 14:53:22 (GMT)
committerGitHub <noreply@github.com>2024-03-04 14:53:22 (GMT)
commit38c39381ece73afdcd881de2aaa76f8e9a057bd5 (patch)
tree9cd44430dc1bd93ed3b0a58bd9ffa16e758657e6 /config/sanitizer/formatting.cmake
parent8276bdbe09504336d5a94458ec9ad1ce3b531fc9 (diff)
downloadhdf5-38c39381ece73afdcd881de2aaa76f8e9a057bd5.zip
hdf5-38c39381ece73afdcd881de2aaa76f8e9a057bd5.tar.gz
hdf5-38c39381ece73afdcd881de2aaa76f8e9a057bd5.tar.bz2
Add upddated cmake tools from source location (#4040)
Diffstat (limited to 'config/sanitizer/formatting.cmake')
-rw-r--r--config/sanitizer/formatting.cmake68
1 files changed, 56 insertions, 12 deletions
diff --git a/config/sanitizer/formatting.cmake b/config/sanitizer/formatting.cmake
index 5aaa2a6..181351d 100644
--- a/config/sanitizer/formatting.cmake
+++ b/config/sanitizer/formatting.cmake
@@ -47,10 +47,7 @@ function(clang_format TARGET_NAME)
# If the item is a target, then we'll attempt to grab the associated
# source files from it.
get_target_property(_TARGET_TYPE ${item} TYPE)
- if(NOT
- _TARGET_TYPE
- STREQUAL
- "INTERFACE_LIBRARY")
+ if(NOT _TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
get_property(
_TEMP
TARGET ${item}
@@ -72,21 +69,68 @@ function(clang_format TARGET_NAME)
# Make the target
if(FORMAT_FILES)
+ add_custom_target(${TARGET_NAME} COMMAND ${CLANG_FORMAT_EXE} -i
+ -style=file ${FORMAT_FILES})
+
+ if(NOT TARGET format)
+ add_custom_target(format)
+ endif()
+
+ add_dependencies(format ${TARGET_NAME})
+ endif()
+
+ endif()
+endfunction()
+
+#
+# cmake-format
+#
+find_program(CMAKE_FORMAT_EXE "cmake-format")
+mark_as_advanced(FORCE CMAKE_FORMAT_EXE)
+if(CMAKE_FORMAT_EXE)
+ message(STATUS "cmake-format found: ${CMAKE_FORMAT_EXE}")
+else()
+ message(STATUS "cmake-format not found!")
+endif()
+
+# When called, this function will call 'cmake-format' program on all listed
+# files (if both the program and the files exist and are found)
+# ~~~
+# Required:
+# TARGET_NAME - The name of the target to create.
+#
+# Optional:
+# ARGN - Any arguments passed in will be considered as 'files' to perform the
+# formatting on. Any items that are not files will be ignored. Both relative and
+# absolute paths are accepted.
+# ~~~
+function(cmake_format TARGET_NAME)
+ if(CMAKE_FORMAT_EXE)
+ set(FORMAT_FILES)
+ # Determine files that exist
+ foreach(iter IN LISTS ARGN)
+ if(EXISTS ${iter})
+ set(FORMAT_FILES ${FORMAT_FILES} ${iter})
+ elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${iter})
+ set(FORMAT_FILES ${FORMAT_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${iter})
+ endif()
+ endforeach()
+
+ # Generate target
+ if(FORMAT_FILES)
if(TARGET ${TARGET_NAME})
message(
ERROR
- "Cannot create clang-format target '${TARGET_NAME}', already exists.")
+ "Cannot create cmake-format target '${TARGET_NAME}', already exists.")
else()
- add_custom_target(${TARGET_NAME} COMMAND ${CLANG_FORMAT_EXE} -i -style=file ${FORMAT_FILES})
+ add_custom_target(${TARGET_NAME} COMMAND ${CMAKE_FORMAT_EXE} -i
+ ${FORMAT_FILES})
- if(NOT TARGET format)
- add_custom_target(format)
+ if(NOT TARGET cmake-format)
+ add_custom_target(cmake-format)
endif()
-
- add_dependencies(format ${TARGET_NAME})
+ add_dependencies(cmake-format ${TARGET_NAME})
endif()
endif()
-
endif()
endfunction()
-