diff options
author | Brad King <brad.king@kitware.com> | 2021-09-14 17:14:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-09-16 19:33:53 (GMT) |
commit | cb93f7262469d0f7e1b7da01ad3586d001234af2 (patch) | |
tree | ee450b9b1157f07ff1c3b250781749cb848fc9be /Modules/CMakeDetermineHIPCompiler.cmake | |
parent | a71f0fc9c7762a06d0bfdd64d0d490919e12357a (diff) | |
download | CMake-cb93f7262469d0f7e1b7da01ad3586d001234af2.zip CMake-cb93f7262469d0f7e1b7da01ad3586d001234af2.tar.gz CMake-cb93f7262469d0f7e1b7da01ad3586d001234af2.tar.bz2 |
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.cmake | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index 5c8849e..7b7d7a3 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) |