HIP: Propagate CMAKE_HIP_PLATFORM from/to the test project in check_language
Fixes: #25541
This commit is contained in:
parent
9ba3fc91e5
commit
ce9c6d0994
@ -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()
|
||||
|
||||
|
@ -25,6 +25,13 @@ add_CMakeOnly_test(CheckCXXSymbolExists)
|
||||
add_CMakeOnly_test(CheckCXXCompilerFlag)
|
||||
|
||||
add_CMakeOnly_test(CheckLanguage)
|
||||
if (CMake_TEST_HIP)
|
||||
set_property(TEST CMakeOnly.CheckLanguage APPEND PROPERTY LABELS "HIP")
|
||||
add_CMakeOnly_test(CheckLanguageHIPPlatform)
|
||||
set_property(TEST CMakeOnly.CheckLanguageHIPPlatform APPEND PROPERTY LABELS "HIP")
|
||||
add_CMakeOnly_test(CheckLanguageHIPPlatform2)
|
||||
set_property(TEST CMakeOnly.CheckLanguageHIPPlatform2 APPEND PROPERTY LABELS "HIP")
|
||||
endif()
|
||||
|
||||
add_CMakeOnly_test(CheckStructHasMember)
|
||||
|
||||
|
17
Tests/CMakeOnly/CheckLanguageHIPPlatform/CMakeLists.txt
Normal file
17
Tests/CMakeOnly/CheckLanguageHIPPlatform/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
cmake_minimum_required (VERSION 3.28)
|
||||
project(CheckLanguageHIPPlatform NONE)
|
||||
include(CheckLanguage)
|
||||
|
||||
check_language(HIP)
|
||||
|
||||
if(NOT DEFINED CMAKE_HIP_COMPILER)
|
||||
message(FATAL_ERROR "check_language did not set result")
|
||||
endif()
|
||||
|
||||
if (NOT CMAKE_HIP_COMPILER)
|
||||
message(FATAL_ERROR "check_language should not fail!")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED CMAKE_HIP_PLATFORM)
|
||||
message(FATAL_ERROR "check_language did not set CMAKE_HIP_PLATFORM!")
|
||||
endif()
|
14
Tests/CMakeOnly/CheckLanguageHIPPlatform2/CMakeLists.txt
Normal file
14
Tests/CMakeOnly/CheckLanguageHIPPlatform2/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
cmake_minimum_required (VERSION 3.28)
|
||||
project(CheckLanguageHIPPlatform2 NONE)
|
||||
include(CheckLanguage)
|
||||
|
||||
set(CMAKE_HIP_PLATFORM "not-a-hip-platform" CACHE STRING "")
|
||||
check_language(HIP)
|
||||
|
||||
if(NOT DEFINED CMAKE_HIP_COMPILER)
|
||||
message(FATAL_ERROR "check_language did not set result")
|
||||
endif()
|
||||
|
||||
if (CMAKE_HIP_COMPILER)
|
||||
message(FATAL_ERROR "check_language should have failed")
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user