From b2425fdffda98d9533aa6eb48cc4526c25d2af82 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 19 May 2025 15:28:51 -0400 Subject: [PATCH] HIP: Store CMAKE_HIP_HOST_COMPILER as an absolute path --- Modules/CMakeDetermineHIPCompiler.cmake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index a33171560e..13ec392f4b 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -113,6 +113,29 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN) if(NOT EXISTS "${CMAKE_HIP_HOST_COMPILER}") message(FATAL_ERROR "Could not find compiler set in environment variable HIPHOSTCXX:\n$ENV{HIPHOSTCXX}.\n${CMAKE_HIP_HOST_COMPILER}") endif() + elseif(CMAKE_HIP_HOST_COMPILER) + # We get here if CMAKE_HIP_HOST_COMPILER was specified by the user or toolchain file. + if(IS_ABSOLUTE "${CMAKE_HIP_HOST_COMPILER}") + # Convert to forward slashes. + cmake_path(CONVERT "${CMAKE_HIP_HOST_COMPILER}" TO_CMAKE_PATH_LIST CMAKE_HIP_HOST_COMPILER NORMALIZE) + else() + # Convert to absolute path so changes in `PATH` do not impact HIP compilation. + find_program(_CMAKE_HIP_HOST_COMPILER_PATH NO_CACHE NAMES "${CMAKE_HIP_HOST_COMPILER}") + if(_CMAKE_HIP_HOST_COMPILER_PATH) + set(CMAKE_HIP_HOST_COMPILER "${_CMAKE_HIP_HOST_COMPILER_PATH}") + endif() + unset(_CMAKE_HIP_HOST_COMPILER_PATH) + endif() + if(NOT EXISTS "${CMAKE_HIP_HOST_COMPILER}") + message(FATAL_ERROR "Could not find compiler set in variable CMAKE_HIP_HOST_COMPILER:\n ${CMAKE_HIP_HOST_COMPILER}") + endif() + # If the value was cached, update the cache entry with our modifications. + get_property(_CMAKE_HIP_HOST_COMPILER_CACHED CACHE CMAKE_HIP_HOST_COMPILER PROPERTY TYPE) + if(_CMAKE_HIP_HOST_COMPILER_CACHED) + set_property(CACHE CMAKE_HIP_HOST_COMPILER PROPERTY VALUE "${CMAKE_HIP_HOST_COMPILER}") + mark_as_advanced(CMAKE_HIP_HOST_COMPILER) + endif() + unset(_CMAKE_HIP_HOST_COMPILER_CACHED) endif() endif()