SWDEV-509518 - Allow LLVM_ROOT and Clang_ROOT to be used with find_program

Fixes #123. find_program doesn't follow CMP0074 and thus ignores LLVM_ROOT and Clang_ROOT. This change adds LLVM_ROOT and Clang_ROOT to the search path of find_program for llvm-mc and clang in hiprtc to mimics previous add_package behaviour.
Caveat: cmake-specific variables like CMAKE_PREFIX_PATH will take precedence over paths specified with HINTS for find_program, there's no way to change the ordering unless we skip cmake-specific variables all together using NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH.

Change-Id: I1fedb60cda09744416e19b3c6e3e0c5c9045f8e7
Этот коммит содержится в:
zichguan-amd
2025-01-20 16:43:13 -05:00
коммит произвёл Zichuan Guan
родитель 799e54aa0d
Коммит 272ef9a7bf
+18 -2
Просмотреть файл
@@ -132,9 +132,25 @@ add_to_config(_versionInfo HIP_VERSION_GITHASH)
# Enable preprocessed hiprtc-builtins library
include(HIPRTC RESULT_VARIABLE HIPRTC_CMAKE)
# Set binary roots to <PackageName>_ROOT cmake and environment variables similar to CMP0074
# to allow find_program to use LLVM_ROOT and Clang_ROOT
if(DEFINED ENV{LLVM_ROOT})
set(ENV_LLVM_BIN $ENV{LLVM_ROOT}/bin)
endif()
if(DEFINED LLVM_ROOT)
set(LLVM_BIN ${LLVM_ROOT}/bin)
endif()
if(DEFINED ENV{Clang_ROOT})
set(ENV_Clang_BIN $ENV{Clang_ROOT}/bin)
endif()
if(DEFINED Clang_ROOT)
set(Clang_BIN ${Clang_ROOT}/bin)
endif()
# Requires clang and llvm-mc to create this library.
find_program(clang clang HINTS ${ROCM_PATH}/llvm/bin ${ROCM_PATH})
find_program(llvm-mc llvm-mc HINTS ${ROCM_PATH}/llvm/bin ${ROCM_PATH})
find_program(clang clang HINTS ${Clang_BIN} ${ENV_Clang_BIN} ${ROCM_PATH}/llvm/bin ${ROCM_PATH})
find_program(llvm-mc llvm-mc HINTS ${LLVM_BIN} ${ENV_LLVM_BIN} ${ROCM_PATH}/llvm/bin ${ROCM_PATH})
set(HIPRTC_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/hip_rtc_gen")
set(HIPRTC_GEN_HEADER "${HIPRTC_GEN_DIR}/hipRTC_header.h")
set(HIPRTC_GEN_MCIN "${HIPRTC_GEN_DIR}/hipRTC_header.mcin")