summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineHIPCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-09-14 17:14:22 +0000
committerBrad King <brad.king@kitware.com>2021-09-16 15:33:53 -0400
commitcb93f7262469d0f7e1b7da01ad3586d001234af2 (patch)
treeee450b9b1157f07ff1c3b250781749cb848fc9be /Modules/CMakeDetermineHIPCompiler.cmake
parenta71f0fc9c7762a06d0bfdd64d0d490919e12357a (diff)
downloadcmake-cb93f7262469d0f7e1b7da01ad3586d001234af2.tar.gz
HIP: Simplify detection of HIP runtime CMake package
It only makes sense to use the CMake package from the same ROCm installation that the compiler uses. Ask the HIP compiler to report the location of the ROCm installation. Verify up front that it contains the expected CMake package file.
Diffstat (limited to 'Modules/CMakeDetermineHIPCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineHIPCompiler.cmake20
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake
index 5c8849e6ae..7b7d7a3b4a 100644
--- a/Modules/CMakeDetermineHIPCompiler.cmake
+++ b/Modules/CMakeDetermineHIPCompiler.cmake
@@ -76,6 +76,18 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN)
_cmake_find_compiler_sysroot(HIP)
endif()
+if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT AND CMAKE_HIP_COMPILER_ID STREQUAL "Clang")
+ execute_process(COMMAND "${CMAKE_HIP_COMPILER}" -v -print-targets
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE _CMAKE_HIP_COMPILER_RESULT
+ OUTPUT_VARIABLE _CMAKE_HIP_COMPILER_STDOUT
+ ERROR_VARIABLE _CMAKE_HIP_COMPILER_STDERR
+ )
+
+ if(_CMAKE_HIP_COMPILER_RESULT EQUAL 0 AND _CMAKE_HIP_COMPILER_STDERR MATCHES "Found HIP installation: *([^,]*)[,\n]")
+ set(CMAKE_HIP_COMPILER_ROCM_ROOT "${CMAKE_MATCH_1}")
+ endif()
+endif()
if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
execute_process(
COMMAND hipconfig --rocmpath
@@ -89,6 +101,14 @@ endif()
if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
message(FATAL_ERROR "Failed to find ROCm root directory.")
endif()
+if(NOT EXISTS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/cmake/hip-lang/hip-lang-config.cmake")
+ message(FATAL_ERROR
+ "The ROCm root directory:\n"
+ " ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n"
+ "does not contain the HIP runtime CMake package, expected at:\n"
+ " ${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/cmake/hip-lang/hip-lang-config.cmake\n"
+ )
+endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_HIP_COMPILER}" PATH)