2023-08-08 18:39:01 -05:00
|
|
|
# ------------------------------------------------------------------------------#
|
|
|
|
|
#
|
|
|
|
|
# creates following targets to format code:
|
|
|
|
|
# - format
|
|
|
|
|
# - format-source
|
|
|
|
|
# - format-cmake
|
|
|
|
|
# - format-python
|
|
|
|
|
# - format-rocprofiler-source
|
|
|
|
|
# - format-rocprofiler-cmake
|
|
|
|
|
# - format-rocprofiler-python
|
|
|
|
|
#
|
|
|
|
|
# ------------------------------------------------------------------------------#
|
|
|
|
|
|
|
|
|
|
include_guard(DIRECTORY)
|
|
|
|
|
|
|
|
|
|
find_program(ROCPROFILER_CLANG_FORMAT_EXE NAMES clang-format-11 clang-format-mp-11)
|
|
|
|
|
find_program(ROCPROFILER_CMAKE_FORMAT_EXE NAMES cmake-format)
|
|
|
|
|
find_program(ROCPROFILER_BLACK_FORMAT_EXE NAMES black)
|
|
|
|
|
|
|
|
|
|
add_custom_target(format-rocprofiler)
|
|
|
|
|
if(NOT TARGET format)
|
|
|
|
|
add_custom_target(format)
|
|
|
|
|
endif()
|
|
|
|
|
foreach(_TYPE source python cmake)
|
|
|
|
|
if(NOT TARGET format-${_TYPE})
|
|
|
|
|
add_custom_target(format-${_TYPE})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
if(ROCPROFILER_CLANG_FORMAT_EXE
|
|
|
|
|
OR ROCPROFILER_BLACK_FORMAT_EXE
|
|
|
|
|
OR ROCPROFILER_CMAKE_FORMAT_EXE)
|
|
|
|
|
|
|
|
|
|
set(rocp_source_files)
|
|
|
|
|
set(rocp_header_files)
|
|
|
|
|
set(rocp_python_files)
|
|
|
|
|
set(rocp_cmake_files ${PROJECT_SOURCE_DIR}/CMakeLists.txt
|
|
|
|
|
${PROJECT_SOURCE_DIR}/external/CMakeLists.txt)
|
|
|
|
|
|
|
|
|
|
foreach(_DIR cmake samples source tests)
|
|
|
|
|
foreach(_TYPE header_files source_files cmake_files python_files)
|
|
|
|
|
set(${_TYPE})
|
|
|
|
|
endforeach()
|
|
|
|
|
file(GLOB_RECURSE header_files ${PROJECT_SOURCE_DIR}/${_DIR}/*.h
|
2023-08-22 13:29:11 -05:00
|
|
|
${PROJECT_SOURCE_DIR}/${_DIR}/*.hpp ${PROJECT_SOURCE_DIR}/${_DIR}/*.h.in
|
|
|
|
|
${PROJECT_SOURCE_DIR}/${_DIR}/*.hpp.in)
|
2023-08-08 18:39:01 -05:00
|
|
|
file(GLOB_RECURSE source_files ${PROJECT_SOURCE_DIR}/${_DIR}/*.c
|
|
|
|
|
${PROJECT_SOURCE_DIR}/${_DIR}/*.cpp)
|
|
|
|
|
file(GLOB_RECURSE cmake_files ${PROJECT_SOURCE_DIR}/${_DIR}/*CMakeLists.txt
|
|
|
|
|
${PROJECT_SOURCE_DIR}/${_DIR}/*.cmake)
|
2023-08-22 13:29:11 -05:00
|
|
|
file(GLOB_RECURSE python_files ${PROJECT_SOURCE_DIR}/${_DIR}/*.py
|
|
|
|
|
${PROJECT_SOURCE_DIR}/${_DIR}/*.py.in)
|
2023-08-08 18:39:01 -05:00
|
|
|
foreach(_TYPE header_files source_files cmake_files python_files)
|
|
|
|
|
list(APPEND rocp_${_TYPE} ${${_TYPE}})
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
foreach(_TYPE header_files source_files cmake_files python_files)
|
|
|
|
|
if(rocp_${_TYPE})
|
|
|
|
|
list(REMOVE_DUPLICATES rocp_${_TYPE})
|
|
|
|
|
list(SORT rocp_${_TYPE})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
if(ROCPROFILER_CLANG_FORMAT_EXE)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
format-rocprofiler-source
|
|
|
|
|
${ROCPROFILER_CLANG_FORMAT_EXE} -i ${rocp_header_files} ${rocp_source_files}
|
|
|
|
|
COMMENT
|
|
|
|
|
"[rocprofiler] Running source formatter ${ROCPROFILER_CLANG_FORMAT_EXE}..."
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-22 13:29:11 -05:00
|
|
|
if(ROCPROFILER_BLACK_FORMAT_EXE AND rocp_python_files)
|
2023-08-08 18:39:01 -05:00
|
|
|
add_custom_target(
|
|
|
|
|
format-rocprofiler-python
|
|
|
|
|
${ROCPROFILER_BLACK_FORMAT_EXE} -q ${rocp_python_files}
|
|
|
|
|
COMMENT
|
2023-08-22 13:29:11 -05:00
|
|
|
"[rocprofiler] Running python formatter ${ROCPROFILER_BLACK_FORMAT_EXE}..."
|
2023-08-08 18:39:01 -05:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(ROCPROFILER_CMAKE_FORMAT_EXE)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
format-rocprofiler-cmake
|
|
|
|
|
${ROCPROFILER_CMAKE_FORMAT_EXE} -i ${rocp_cmake_files}
|
|
|
|
|
COMMENT
|
2023-08-22 13:29:11 -05:00
|
|
|
"[rocprofiler] Running cmake formatter ${ROCPROFILER_CMAKE_FORMAT_EXE}..."
|
2023-08-08 18:39:01 -05:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
foreach(_TYPE source python cmake)
|
|
|
|
|
if(TARGET format-rocprofiler-${_TYPE})
|
|
|
|
|
add_dependencies(format-rocprofiler format-rocprofiler-${_TYPE})
|
|
|
|
|
add_dependencies(format-${_TYPE} format-rocprofiler-${_TYPE})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2023-08-22 13:29:11 -05:00
|
|
|
foreach(_TYPE source python cmake)
|
2023-08-08 18:39:01 -05:00
|
|
|
if(TARGET format-rocprofiler-${_TYPE})
|
|
|
|
|
add_dependencies(format format-rocprofiler-${_TYPE})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|