1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 if(CMAKE_HIP_COMPILER_FORCED)
6 # The compiler configuration was forced by the user.
7 # Assume the user has configured all compiler information.
8 set(CMAKE_HIP_COMPILER_WORKS TRUE)
12 set(__CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS}")
13 string(APPEND CMAKE_HIP_FLAGS " --cuda-host-only")
15 include(CMakeTestCompilerCommon)
17 # work around enforced code signing and / or missing executable target type
18 set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
19 if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
20 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
23 # Remove any cached result from an older CMake version.
24 # We now store this in CMakeHIPCompiler.cmake.
25 unset(CMAKE_HIP_COMPILER_WORKS CACHE)
27 # Try to identify the ABI and configure it into CMakeHIPCompiler.cmake
28 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
29 CMAKE_DETERMINE_COMPILER_ABI(HIP ${CMAKE_ROOT}/Modules/CMakeHIPCompilerABI.hip)
30 if(CMAKE_HIP_ABI_COMPILED)
31 # The compiler worked so skip dedicated test below.
32 set(CMAKE_HIP_COMPILER_WORKS TRUE)
33 message(STATUS "Check for working HIP compiler: ${CMAKE_HIP_COMPILER} - skipped")
36 # This file is used by EnableLanguage in cmGlobalGenerator to
37 # determine that the selected C++ compiler can actually compile
38 # and link the most basic of programs. If not, a fatal error
39 # is set and cmake stops processing commands and will not generate
40 # any makefiles or projects.
41 if(NOT CMAKE_HIP_COMPILER_WORKS)
42 PrintTestCompilerStatus("HIP")
43 __TestCompiler_setTryCompileTargetType()
44 file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testHIPCompiler.hip
46 "# error \"The CMAKE_HIP_COMPILER is set to a C/CXX compiler\"\n"
48 "int main(){return 0;}\n")
49 # Clear result from normal variable.
50 unset(CMAKE_HIP_COMPILER_WORKS)
51 # Puts test result in cache variable.
52 try_compile(CMAKE_HIP_COMPILER_WORKS ${CMAKE_BINARY_DIR}
53 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testHIPCompiler.hip
54 OUTPUT_VARIABLE __CMAKE_HIP_COMPILER_OUTPUT)
55 # Move result from cache to normal variable.
56 set(CMAKE_HIP_COMPILER_WORKS ${CMAKE_HIP_COMPILER_WORKS})
57 unset(CMAKE_HIP_COMPILER_WORKS CACHE)
58 __TestCompiler_restoreTryCompileTargetType()
59 if(NOT CMAKE_HIP_COMPILER_WORKS)
60 PrintTestCompilerResult(CHECK_FAIL "broken")
61 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
62 "Determining if the HIP compiler works failed with "
63 "the following output:\n${__CMAKE_HIP_COMPILER_OUTPUT}\n\n")
64 string(REPLACE "\n" "\n " _output "${__CMAKE_HIP_COMPILER_OUTPUT}")
65 message(FATAL_ERROR "The HIP compiler\n \"${CMAKE_HIP_COMPILER}\"\n"
66 "is not able to compile a simple test program.\nIt fails "
67 "with the following output:\n ${_output}\n\n"
68 "CMake will not be able to correctly generate this project.")
70 PrintTestCompilerResult(CHECK_PASS "works")
71 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
72 "Determining if the HIP compiler works passed with "
73 "the following output:\n${__CMAKE_HIP_COMPILER_OUTPUT}\n\n")
76 set(CMAKE_HIP_FLAGS "${__CMAKE_HIP_FLAGS}")
77 unset(__CMAKE_HIP_FLAGS)
80 # Try to identify the compiler features
81 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
82 CMAKE_DETERMINE_COMPILE_FEATURES(HIP)
84 # Re-configure to save learned information.
86 ${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in
87 ${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake
90 include(${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake)
92 if(CMAKE_HIP_SIZEOF_DATA_PTR)
93 foreach(f ${CMAKE_HIP_ABI_FILES})
96 unset(CMAKE_HIP_ABI_FILES)
99 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
100 unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
101 unset(__CMAKE_HIP_COMPILER_OUTPUT)