@@ -223,6 +223,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
223223 -DUR_BUILD_ADAPTER_HIP:BOOL=${UR_BUILD_ADAPTER_HIP}
224224 -DUR_BUILD_ADAPTER_NATIVE_CPU:BOOL=${UR_BUILD_ADAPTER_NATIVE_CPU}
225225 -DUR_STATIC_LOADER:BOOL=${UR_STATIC_LOADER}
226+ -DUR_STATIC_ADAPTER_L0:BOOL=${UR_STATIC_ADAPTER_L0}
227+ -DUR_STATIC_ADAPTER_L0_V2:BOOL=${UR_STATIC_ADAPTER_L0_V2}
226228 -DUR_STATIC_ADAPTER_OPENCL:BOOL=${UR_STATIC_ADAPTER_OPENCL}
227229 -DUMF_BUILD_EXAMPLES:BOOL=${UMF_BUILD_EXAMPLES}
228230 -DUMF_BUILD_SHARED_LIBRARY:BOOL=${UMF_BUILD_SHARED_LIBRARY}
@@ -272,16 +274,50 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
272274 ${LLVM_BINARY_DIR } /lib/ur_loaderd.lib
273275 ${LLVM_BINARY_DIR } /lib/ur_commond.lib
274276 dbghelp )
277+ set (_urd_static_l0 FALSE )
275278 # Link static adapters into the loader
276279 foreach (adapter ${SYCL_ENABLE_BACKENDS} )
277280 ur_adapter_is_static (${adapter} adapter_is_static )
278- set (build_var "UR_BUILD_ADAPTER_${adapter} " )
279- string (TOUPPER "${build_var} " build_var)
281+ # The Level Zero adapters use the abbreviated build flags
282+ # UR_BUILD_ADAPTER_L0 / _L0_V2 rather than the backend name.
283+ string (TOUPPER "${adapter} " adapter_upper)
284+ if (adapter_upper STREQUAL "LEVEL_ZERO" )
285+ set (build_var "UR_BUILD_ADAPTER_L0" )
286+ elseif (adapter_upper STREQUAL "LEVEL_ZERO_V2" )
287+ set (build_var "UR_BUILD_ADAPTER_L0_V2" )
288+ else ()
289+ set (build_var "UR_BUILD_ADAPTER_${adapter_upper} " )
290+ endif ()
280291 if (adapter_is_static AND DEFINED ${build_var} AND ${build_var} )
281292 target_link_libraries (UnifiedRuntimeLoaderDebug INTERFACE
282293 ${LLVM_BINARY_DIR } /lib/ur_adapter_${adapter}d.lib )
294+ if (build_var STREQUAL "UR_BUILD_ADAPTER_L0" OR
295+ build_var STREQUAL "UR_BUILD_ADAPTER_L0_V2" )
296+ set (_urd_static_l0 TRUE )
297+ endif ()
283298 endif ()
284299 endforeach ()
300+ # A static umfd.lib does not absorb its private helper archives, so link
301+ # them too. umfd and the helpers are copied below.
302+ target_link_libraries (UnifiedRuntimeLoaderDebug INTERFACE
303+ ${LLVM_BINARY_DIR } /lib/umfd.lib
304+ ${LLVM_BINARY_DIR } /lib/umf_bad.lib
305+ ${LLVM_BINARY_DIR } /lib/umf_utilsd.lib
306+ ${LLVM_BINARY_DIR } /lib/umf_coarsed.lib )
307+ if (_urd_static_l0)
308+ # The static L0 adapters need ze_loader. Copy the debug-CRT ze_loader
309+ # from the debug sub-build under a 'd' name (it has no debug postfix, so
310+ # copying it as-is would collide with the release in-tree ze_loader.lib).
311+ list (APPEND URD_COPY_FILES ${LLVM_BINARY_DIR } /lib/ze_loaderd.lib)
312+ add_custom_command (
313+ OUTPUT ${LLVM_BINARY_DIR } /lib/ze_loaderd.lib
314+ COMMAND ${CMAKE_COMMAND } -E copy
315+ ${URD_INSTALL_DIR} /lib/ze_loader.lib
316+ ${LLVM_BINARY_DIR } /lib/ze_loaderd.lib
317+ )
318+ target_link_libraries (UnifiedRuntimeLoaderDebug INTERFACE
319+ ${LLVM_BINARY_DIR } /lib/ze_loaderd.lib )
320+ endif ()
285321 endif ()
286322 foreach (adapter ${SYCL_ENABLE_BACKENDS} )
287323 ur_adapter_is_static (${adapter} adapter_is_static )
@@ -294,6 +330,22 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
294330 endforeach ()
295331 # Also copy umfd.dll/umfd.lib
296332 urd_copy_library_to_build (umfd ${UMF_BUILD_SHARED_LIBRARY} )
333+ # A static umfd.lib doesn't absorb its private helper archives (umf_ba /
334+ # umf_utils / umf_coarse), so a consumer linking umfd.lib must link them too.
335+ # They aren't installed, but the debug sub-build produces them (debug CRT) at
336+ # ${URD_BINARY_DIR}/lib without a 'd' postfix, so copy them under a 'd' name.
337+ if (NOT UMF_BUILD_SHARED_LIBRARY)
338+ foreach (_umfd_helper umf_ba umf_utils umf_coarse)
339+ list (APPEND URD_COPY_FILES ${LLVM_BINARY_DIR } /lib/${_umfd_helper} d.lib)
340+ add_custom_command (
341+ OUTPUT ${LLVM_BINARY_DIR } /lib/${_umfd_helper}d.lib
342+ COMMAND ${CMAKE_COMMAND } -E copy
343+ ${URD_BINARY_DIR } /lib/${_umfd_helper}.lib
344+ ${LLVM_BINARY_DIR } /lib/${_umfd_helper}d.lib
345+ DEPENDS unified-runtimed
346+ )
347+ endforeach ()
348+ endif ()
297349
298350 add_custom_target (unified-runtimed-build ALL DEPENDS ${URD_COPY_FILES} )
299351 add_dependencies (unified-runtimed-build unified-runtimed )
0 commit comments