diff options
author | Gergely Meszaros <gergely@streamhpc.com> | 2024-01-02 15:23:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-01-04 16:25:15 (GMT) |
commit | ce9c6d0994799a64d1cea4eac0492d27ded74b75 (patch) | |
tree | b9acd37b50e6a46c76fa8fa929fce42933705f72 /Modules | |
parent | 9ba3fc91e5ce567b0f50b28573af9508242446d6 (diff) | |
download | CMake-ce9c6d0994799a64d1cea4eac0492d27ded74b75.zip CMake-ce9c6d0994799a64d1cea4eac0492d27ded74b75.tar.gz CMake-ce9c6d0994799a64d1cea4eac0492d27ded74b75.tar.bz2 |
HIP: Propagate CMAKE_HIP_PLATFORM from/to the test project in check_language
Fixes: #25541
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CheckLanguage.cmake | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index 358c435..bad3590 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -41,6 +41,12 @@ or :command:`project` commands: not be set without also setting :variable:`CMAKE_<LANG>_COMPILER` to a NVCC compiler. + :variable:`CMAKE_<LANG>_PLATFORM <CMAKE_HIP_PLATFORM>` + This variable is set to the detected GPU platform when ``<lang>`` is ``HIP``. + + If the variable is already set its value is always preserved. Only compatible values + will be considered for :variable:`CMAKE_<LANG>_COMPILER`. + For example: .. code-block:: cmake @@ -69,12 +75,20 @@ macro(check_language lang) set(extra_compiler_variables "set(CMAKE_${lang}_HOST_COMPILER \\\"\${CMAKE_${lang}_HOST_COMPILER}\\\")") endif() + if("${lang}" STREQUAL "HIP") + list(APPEND extra_compiler_variables "set(CMAKE_${lang}_PLATFORM \\\"\${CMAKE_${lang}_PLATFORM}\\\")") + endif() + + list(TRANSFORM extra_compiler_variables PREPEND "\"") + list(TRANSFORM extra_compiler_variables APPEND "\\n\"") + list(JOIN extra_compiler_variables "\n " extra_compiler_variables) + set(_cl_content "cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(Check${lang} ${lang}) file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" \"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\" - \"${extra_compiler_variables}\\n\" + ${extra_compiler_variables} )" ) @@ -95,6 +109,11 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" else() set(_D_CMAKE_TOOLCHAIN_FILE "") endif() + if(CMAKE_${lang}_PLATFORM) + set(_D_CMAKE_LANG_PLATFORM "-DCMAKE_${lang}_PLATFORM:STRING=${CMAKE_${lang}_PLATFORM}") + else() + set(_D_CMAKE_LANG_PLATFORM "") + endif() execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang} COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR} @@ -103,6 +122,7 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" ${_D_CMAKE_GENERATOR_INSTANCE} ${_D_CMAKE_MAKE_PROGRAM} ${_D_CMAKE_TOOLCHAIN_FILE} + ${_D_CMAKE_LANG_PLATFORM} OUTPUT_VARIABLE _cl_output ERROR_VARIABLE _cl_output RESULT_VARIABLE _cl_result @@ -130,6 +150,10 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" mark_as_advanced(CMAKE_${lang}_HOST_COMPILER) endif() + if(CMAKE_${lang}_PLATFORM) + set(CMAKE_${lang}_PLATFORM "${CMAKE_${lang}_PLATFORM}" CACHE STRING "${lang} platform") + mark_as_advanced(CMAKE_${lang}_PLATFORM) + endif() endif() endmacro() |