CMakeTestHIPCompiler.cmake 4.6 KB

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