1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 set(CMAKE_HIP_OUTPUT_EXTENSION .o)
7 set(CMAKE_HIP_OUTPUT_EXTENSION .obj)
9 set(CMAKE_INCLUDE_FLAG_HIP "-I")
11 # Set implicit links early so compiler-specific modules can use them.
13 foreach(dir ${CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES})
14 string(APPEND __IMPLICIT_LINKS " -L\"${dir}\"")
16 foreach(lib ${CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES})
17 if(${lib} MATCHES "/")
18 string(APPEND __IMPLICIT_LINKS " \"${lib}\"")
20 string(APPEND __IMPLICIT_LINKS " -l${lib}")
24 # Load compiler-specific information.
25 if(CMAKE_HIP_COMPILER_ID)
26 include(Compiler/${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
29 # load the system- and compiler specific files
30 if(CMAKE_HIP_COMPILER_ID)
31 # load a hardware specific file, mostly useful for embedded compilers
32 if(CMAKE_SYSTEM_PROCESSOR)
33 include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
35 include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
39 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG)
40 set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
43 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP)
44 set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
47 if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG)
48 set(CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
51 if(NOT DEFINED CMAKE_EXE_EXPORTS_HIP_FLAG)
52 set(CMAKE_EXE_EXPORTS_HIP_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
55 if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG)
56 set(CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
59 if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG)
60 set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG})
63 if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP)
64 set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP})
67 if(NOT CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG)
68 set(CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG})
71 if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH)
72 set(CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
76 # for most systems a module is the same as a shared library
77 # so unless the variable CMAKE_MODULE_EXISTS is set just
78 # copy the values from the LIBRARY variables
79 if(NOT CMAKE_MODULE_EXISTS)
80 set(CMAKE_SHARED_MODULE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_HIP_FLAGS})
81 set(CMAKE_SHARED_MODULE_CREATE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS})
84 if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
85 if(NOT DEFINED CMAKE_HIP_LINK_WHAT_YOU_USE_FLAG)
86 set(CMAKE_HIP_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed")
88 if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK)
89 set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r)
93 # add the flags to the cache based
94 # on the initial values computed in the platform/*.cmake files
95 # use _INIT variables so that this only happens the first time
96 # and you can set these flags in the cmake cache
97 set(CMAKE_HIP_FLAGS_INIT "$ENV{HIPFLAGS} ${CMAKE_HIP_FLAGS_INIT}")
99 cmake_initialize_per_config_variable(CMAKE_HIP_FLAGS "Flags used by the HIP compiler")
101 if(CMAKE_HIP_STANDARD_LIBRARIES_INIT)
102 set(CMAKE_HIP_STANDARD_LIBRARIES "${CMAKE_HIP_STANDARD_LIBRARIES_INIT}"
103 CACHE STRING "Libraries linked by default with all HIP applications.")
104 mark_as_advanced(CMAKE_HIP_STANDARD_LIBRARIES)
107 if(NOT CMAKE_HIP_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_HIP_COMPILER_LAUNCHER})
108 set(CMAKE_HIP_COMPILER_LAUNCHER "$ENV{CMAKE_HIP_COMPILER_LAUNCHER}"
109 CACHE STRING "Compiler launcher for HIP.")
112 include(CMakeCommonLanguageInclude)
114 # now define the following rules:
115 # CMAKE_HIP_CREATE_SHARED_LIBRARY
116 # CMAKE_HIP_CREATE_SHARED_MODULE
117 # CMAKE_HIP_COMPILE_OBJECT
118 # CMAKE_HIP_LINK_EXECUTABLE
120 # create a shared library
121 if(NOT CMAKE_HIP_CREATE_SHARED_LIBRARY)
122 set(CMAKE_HIP_CREATE_SHARED_LIBRARY
123 "<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>")
126 # create a shared module copy the shared library rule by default
127 if(NOT CMAKE_HIP_CREATE_SHARED_MODULE)
128 set(CMAKE_HIP_CREATE_SHARED_MODULE ${CMAKE_HIP_CREATE_SHARED_LIBRARY})
131 # Create a static archive incrementally for large object file counts.
132 if(NOT DEFINED CMAKE_HIP_ARCHIVE_CREATE)
133 set(CMAKE_HIP_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
135 if(NOT DEFINED CMAKE_HIP_ARCHIVE_APPEND)
136 set(CMAKE_HIP_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
138 if(NOT DEFINED CMAKE_HIP_ARCHIVE_FINISH)
139 set(CMAKE_HIP_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
142 # compile a HIP file into an object file
143 if(NOT CMAKE_HIP_COMPILE_OBJECT)
144 set(CMAKE_HIP_COMPILE_OBJECT
145 "<CMAKE_HIP_COMPILER> ${_CMAKE_HIP_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> ${_CMAKE_COMPILE_AS_HIP_FLAG} -c <SOURCE>")
148 # compile a cu file into an executable
149 if(NOT CMAKE_HIP_LINK_EXECUTABLE)
150 set(CMAKE_HIP_LINK_EXECUTABLE
151 "<CMAKE_HIP_COMPILER> <FLAGS> <CMAKE_HIP_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
154 set(CMAKE_HIP_INFORMATION_LOADED 1)
156 # Load the file and find the relevant HIP runtime.
157 if(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET)
158 set(hip-lang_DIR "${CMAKE_HIP_COMPILER_ROCM_LIB}/cmake/hip-lang")
159 find_package(hip-lang CONFIG QUIET NO_DEFAULT_PATH REQUIRED)
161 if(DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET)
162 list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_STATIC ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET})
163 list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_SHARED ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET})