CMakeHIPInformation.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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(UNIX)
  4. set(CMAKE_HIP_OUTPUT_EXTENSION .o)
  5. else()
  6. set(CMAKE_HIP_OUTPUT_EXTENSION .obj)
  7. endif()
  8. set(CMAKE_INCLUDE_FLAG_HIP "-I")
  9. # Set implicit links early so compiler-specific modules can use them.
  10. set(__IMPLICIT_LINKS)
  11. foreach(dir ${CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES})
  12. string(APPEND __IMPLICIT_LINKS " -L\"${dir}\"")
  13. endforeach()
  14. foreach(lib ${CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES})
  15. if(${lib} MATCHES "/")
  16. string(APPEND __IMPLICIT_LINKS " \"${lib}\"")
  17. else()
  18. string(APPEND __IMPLICIT_LINKS " -l${lib}")
  19. endif()
  20. endforeach()
  21. # Load compiler-specific information.
  22. if(CMAKE_HIP_COMPILER_ID)
  23. include(Compiler/${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
  24. endif()
  25. # load the system- and compiler specific files
  26. if(CMAKE_HIP_COMPILER_ID)
  27. # load a hardware specific file, mostly useful for embedded compilers
  28. if(CMAKE_SYSTEM_PROCESSOR)
  29. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
  30. endif()
  31. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
  32. endif()
  33. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG)
  34. set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  35. endif()
  36. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP)
  37. set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  38. endif()
  39. if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG)
  40. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  41. endif()
  42. if(NOT DEFINED CMAKE_EXE_EXPORTS_HIP_FLAG)
  43. set(CMAKE_EXE_EXPORTS_HIP_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
  44. endif()
  45. if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG)
  46. set(CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
  47. endif()
  48. if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG)
  49. set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG})
  50. endif()
  51. if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP)
  52. set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP})
  53. endif()
  54. if(NOT CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG)
  55. set(CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG})
  56. endif()
  57. if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH)
  58. set(CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  59. endif()
  60. # for most systems a module is the same as a shared library
  61. # so unless the variable CMAKE_MODULE_EXISTS is set just
  62. # copy the values from the LIBRARY variables
  63. if(NOT CMAKE_MODULE_EXISTS)
  64. set(CMAKE_SHARED_MODULE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_HIP_FLAGS})
  65. set(CMAKE_SHARED_MODULE_CREATE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS})
  66. endif()
  67. if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
  68. if(NOT DEFINED CMAKE_HIP_LINK_WHAT_YOU_USE_FLAG)
  69. set(CMAKE_HIP_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed")
  70. endif()
  71. if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK)
  72. set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r)
  73. endif()
  74. endif()
  75. # add the flags to the cache based
  76. # on the initial values computed in the platform/*.cmake files
  77. # use _INIT variables so that this only happens the first time
  78. # and you can set these flags in the cmake cache
  79. set(CMAKE_HIP_FLAGS_INIT "$ENV{HIPFLAGS} ${CMAKE_HIP_FLAGS_INIT}")
  80. cmake_initialize_per_config_variable(CMAKE_HIP_FLAGS "Flags used by the HIP compiler")
  81. if(CMAKE_HIP_STANDARD_LIBRARIES_INIT)
  82. set(CMAKE_HIP_STANDARD_LIBRARIES "${CMAKE_HIP_STANDARD_LIBRARIES_INIT}"
  83. CACHE STRING "Libraries linked by default with all HIP applications.")
  84. mark_as_advanced(CMAKE_HIP_STANDARD_LIBRARIES)
  85. endif()
  86. if(NOT CMAKE_HIP_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_HIP_COMPILER_LAUNCHER})
  87. set(CMAKE_HIP_COMPILER_LAUNCHER "$ENV{CMAKE_HIP_COMPILER_LAUNCHER}"
  88. CACHE STRING "Compiler launcher for HIP.")
  89. endif()
  90. include(CMakeCommonLanguageInclude)
  91. # now define the following rules:
  92. # CMAKE_HIP_CREATE_SHARED_LIBRARY
  93. # CMAKE_HIP_CREATE_SHARED_MODULE
  94. # CMAKE_HIP_COMPILE_OBJECT
  95. # CMAKE_HIP_LINK_EXECUTABLE
  96. # create a shared library
  97. if(NOT CMAKE_HIP_CREATE_SHARED_LIBRARY)
  98. set(CMAKE_HIP_CREATE_SHARED_LIBRARY
  99. "<CMAKE_HIP_COMPILER> <CMAKE_SHARED_LIBRARY_HIP_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  100. endif()
  101. # create a shared module copy the shared library rule by default
  102. if(NOT CMAKE_HIP_CREATE_SHARED_MODULE)
  103. set(CMAKE_HIP_CREATE_SHARED_MODULE ${CMAKE_HIP_CREATE_SHARED_LIBRARY})
  104. endif()
  105. # Create a static archive incrementally for large object file counts.
  106. if(NOT DEFINED CMAKE_HIP_ARCHIVE_CREATE)
  107. set(CMAKE_HIP_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  108. endif()
  109. if(NOT DEFINED CMAKE_HIP_ARCHIVE_APPEND)
  110. set(CMAKE_HIP_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  111. endif()
  112. if(NOT DEFINED CMAKE_HIP_ARCHIVE_FINISH)
  113. set(CMAKE_HIP_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  114. endif()
  115. # compile a HIP file into an object file
  116. if(NOT CMAKE_HIP_COMPILE_OBJECT)
  117. set(CMAKE_HIP_COMPILE_OBJECT
  118. "<CMAKE_HIP_COMPILER> ${_CMAKE_HIP_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> ${_CMAKE_COMPILE_AS_HIP_FLAG} -c <SOURCE>")
  119. endif()
  120. # compile a cu file into an executable
  121. if(NOT CMAKE_HIP_LINK_EXECUTABLE)
  122. set(CMAKE_HIP_LINK_EXECUTABLE
  123. "<CMAKE_HIP_COMPILER> <FLAGS> <CMAKE_HIP_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  124. endif()
  125. set(CMAKE_HIP_INFORMATION_LOADED 1)
  126. # Load the file and find the relevant HIP runtime.
  127. if(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET)
  128. set(hip-lang_DIR "${CMAKE_HIP_COMPILER_ROCM_LIB}/cmake/hip-lang")
  129. find_package(hip-lang CONFIG QUIET NO_DEFAULT_PATH REQUIRED)
  130. endif()
  131. if(DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET)
  132. list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_STATIC ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET})
  133. list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_SHARED ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET})
  134. endif()