Files
TheRock/rocm-libraries/projects/hipdnn/cmake/ClangCheck.cmake
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

97 lines
3.7 KiB
CMake

# Copyright © Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT
# Helper function to verify a compiler is AMD/ROCm clang
function(verifyAmdRocmCompiler COMPILER_PATH COMPILER_NAME)
execute_process(
COMMAND ${COMPILER_PATH} --version OUTPUT_VARIABLE VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
if(VERSION_OUTPUT MATCHES "clang version"
AND (VERSION_OUTPUT MATCHES "ROCm" OR VERSION_OUTPUT MATCHES "AMD" OR COMPILER_PATH MATCHES
"rocm")
)
message(STATUS "✓ Confirmed AMD/ROCm type ${COMPILER_NAME} compiler")
else()
string(REGEX REPLACE "[\r\n]+" "\n " VERSION_OUTPUT "${VERSION_OUTPUT}")
message(
WARNING "\n"
"Unable to confirm AMD/ROCm type ${COMPILER_NAME} compiler: ${COMPILER_PATH}\n"
"Expected to find \"AMD\" or \"ROCm\" in the compiler version.\n"
"Actual compiler version reported:\n ${VERSION_OUTPUT}\n"
)
endif()
endfunction()
# Verify that we're using AMD/ROCm compiler.
verifyamdrocmcompiler(${CMAKE_CXX_COMPILER} "C++")
if(ENABLE_CLANG_FORMAT)
include(${CMAKE_CURRENT_LIST_DIR}/CheckToolVersion.cmake)
set(HIPDNN_CLANG_FORMAT_FILES_PER_INVOCATION
32
CACHE STRING "Maximum source files passed to each clang-format invocation"
)
if(HIPDNN_CLANG_FORMAT_FILES_PER_INVOCATION LESS 1)
message(FATAL_ERROR "HIPDNN_CLANG_FORMAT_FILES_PER_INVOCATION must be greater than 0")
endif()
set(HIPDNN_CLANG_FORMAT_JOBS
0
CACHE STRING "Maximum parallel clang-format invocations; 0 uses the host processor count"
)
if(HIPDNN_CLANG_FORMAT_JOBS LESS 0)
message(FATAL_ERROR "HIPDNN_CLANG_FORMAT_JOBS must be greater than or equal to 0")
endif()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
# Adds a format and check-format target
function(add_clang_format_target TARGET_NAME FORMAT_MODE)
if(NOT FORMAT_MODE STREQUAL "check" AND NOT FORMAT_MODE STREQUAL "format")
message(FATAL_ERROR "FORMAT_MODE must be 'check' or 'format'")
endif()
add_custom_target(
${TARGET_NAME}
COMMAND
"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/RunClangFormat.py"
--clang-format "${CLANG_FORMAT_BINARY}" --source-dir "${PROJECT_SOURCE_DIR}"
--mode "${FORMAT_MODE}" --files-per-invocation
"${HIPDNN_CLANG_FORMAT_FILES_PER_INVOCATION}" --jobs
"${HIPDNN_CLANG_FORMAT_JOBS}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM
COMMENT "Running clang-format ${FORMAT_MODE} (${PROJECT_NAME})"
)
endfunction()
# Find and check clang-format version using unified function
findandcheckclangformat()
# Use prefixed target names in superbuild to avoid collisions
if(ROCM_LIBS_SUPERBUILD)
set(_CHECK_FORMAT_TARGET ${PROJECT_NAME}_check_format)
set(_FORMAT_TARGET ${PROJECT_NAME}_format)
else()
set(_CHECK_FORMAT_TARGET check_format)
set(_FORMAT_TARGET format)
endif()
add_clang_format_target(${_CHECK_FORMAT_TARGET} check)
add_clang_format_target(${_FORMAT_TARGET} format)
# Alias targets with consistent hyphenated naming
add_custom_target(
${PROJECT_NAME}-check-format
DEPENDS ${_CHECK_FORMAT_TARGET}
COMMENT "Alias for ${_CHECK_FORMAT_TARGET}"
)
add_custom_target(
${PROJECT_NAME}-format
DEPENDS ${_FORMAT_TARGET}
COMMENT "Alias for ${_FORMAT_TARGET}"
)
endif() # ENABLE_CLANG_FORMAT