Files
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

106 lines
3.9 KiB
CMake

# Copyright Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT
# Cross-platform ROCm Clang toolchain for the superbuild.
#
# Linux: defaults to /opt/rocm, uses clang/clang++
# Windows: ROCM_PATH must be provided, uses clang/clang++
#
# Usage:
# Linux: cmake --preset <preset>
# Linux: cmake --preset <preset> -DROCM_PATH="/opt/rocm"
# Windows: cmake --preset <preset> -DROCM_PATH="C:/AMD/ROCm/6.4"
#
# Note: ROCM_PATH should be passed via -D, not set in the environment,
# as environment variables can interfere with toolchain detection.
# Platform-specific configuration
if(WIN32)
set(_ROCM_COMPILER_EXTENSION ".exe")
else()
set(_ROCM_COMPILER_EXTENSION "")
endif()
# First-run validation (only runs once during initial configuration)
if(NOT _ROCM_CLANG_TOOLCHAIN_FIRST_RUN_COMPLETED)
# Warn if ROCM_PATH is set in environment (can interfere with toolchain discovery)
if(DEFINED ENV{ROCM_PATH})
message(WARNING
"\nROCM_PATH is set in the environment and may interfere with toolchain detection.\n"
"Remove ROCM_PATH from the environment and use the following instead:\n"
" cmake -DROCM_PATH=$ENV{ROCM_PATH}\n"
)
endif()
# Validate that a compatible generator is being used
if(CMAKE_GENERATOR)
string(TOLOWER "${CMAKE_GENERATOR}" _generator_lower)
if(NOT (_generator_lower MATCHES "ninja" OR _generator_lower MATCHES "makefile"))
message(FATAL_ERROR
"\nIncompatible generator detected: '${CMAKE_GENERATOR}'\n"
"The ROCm Clang toolchain requires Ninja or Makefile generators.\n"
"Use \"cmake -G <generator>\" to select a compatible generator.\n"
)
endif()
unset(_generator_lower)
endif()
endif()
# Set ROCM_PATH with platform-specific defaults
if(WIN32)
if(NOT DEFINED ROCM_PATH)
message(FATAL_ERROR
"ROCM_PATH must be set for Windows builds.\n"
" cmake --preset <preset> -DROCM_PATH=\"C:/AMD/ROCm/6.4\""
)
endif()
else()
if(NOT DEFINED ROCM_PATH)
set(ROCM_PATH "/opt/rocm")
endif()
endif()
# Set compiler paths
set(ROCM_LLVM_PATH "${ROCM_PATH}/lib/llvm")
file(TO_NATIVE_PATH "${ROCM_LLVM_PATH}/bin" ROCM_LLVM_BIN_DIR)
if(NOT EXISTS "${ROCM_LLVM_BIN_DIR}")
message(FATAL_ERROR "ROCm LLVM bin directory does not exist: ${ROCM_LLVM_BIN_DIR}")
endif()
set(CMAKE_C_COMPILER "${ROCM_LLVM_BIN_DIR}/clang${_ROCM_COMPILER_EXTENSION}" CACHE FILEPATH "C compiler")
set(CMAKE_CXX_COMPILER "${ROCM_LLVM_BIN_DIR}/clang++${_ROCM_COMPILER_EXTENSION}" CACHE FILEPATH "C++/HIP compiler")
# Some Windows components (e.g. hipDNN) embed a VERSIONINFO resource that needs a resource compiler.
# Prefer llvm-rc from the ROCm LLVM toolchain, then any rc on PATH. If none is found, mark RC as
# not-required so configuration still succeeds; components guard their .rc sources on a real compiler
# and warn when version metadata will be omitted.
if(WIN32 AND NOT CMAKE_RC_COMPILER)
find_program(_ROCM_RC_COMPILER NAMES llvm-rc rc HINTS "${ROCM_LLVM_BIN_DIR}")
if(_ROCM_RC_COMPILER)
set(CMAKE_RC_COMPILER "${_ROCM_RC_COMPILER}")
else()
set(CMAKE_RC_COMPILER "CMAKE_RC_COMPILER-NOTREQUIRED")
endif()
endif()
# Cache ROCM_PATH and add to CMAKE_PREFIX_PATH for find_package(hip)
set(ROCM_PATH "${ROCM_PATH}" CACHE PATH "Path to ROCm installation")
if(NOT "${ROCM_PATH}" IN_LIST CMAKE_PREFIX_PATH)
list(PREPEND CMAKE_PREFIX_PATH "${ROCM_PATH}")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Enable position independent code")
# Cleanup
unset(_ROCM_COMPILER_EXTENSION)
# Forward variables to try_compile() so the toolchain file works correctly during compiler checks
if(NOT _ROCM_CLANG_TOOLCHAIN_FIRST_RUN_COMPLETED)
set(_ROCM_CLANG_TOOLCHAIN_FIRST_RUN_COMPLETED TRUE)
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
ROCM_PATH
_ROCM_CLANG_TOOLCHAIN_FIRST_RUN_COMPLETED
)
endif()