Skip to content

Commit bd3d995

Browse files
committed
[CMake]: Use check_linker_flag for /DEPENDENTLOADFLAG
PR oneapi-src#2100 changed the WIN32 check to check from `if(WIN32)` to checking if link.exe is used via `CMAKE_CXX_COMPILER_LINKER_ID`. This has two problems: - CMAKE_CXX_COMPILER_LINKER_ID is only supported starting with CMake 3.29, but UR still claims to CMake versions from 3.20 (`cmake_minimum_required` is called with this version). This results in the flag being silently dropped in earlier versions of CMake. - There are other linkers that also support this flag for example LLD. Using check_linker_flag resolves these issues without hard-coding a list of known linkers.
1 parent 2aaa261 commit bd3d995

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

source/adapters/level_zero/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
include(CheckLinkerFlag)
7+
68
if(UR_BUILD_ADAPTER_L0)
79
set(ADAPTER_LIB_TYPE SHARED)
810
if(UR_STATIC_ADAPTER_L0)
@@ -99,7 +101,8 @@ if(UR_BUILD_ADAPTER_L0)
99101
SOVERSION "${PROJECT_VERSION_MAJOR}"
100102
)
101103

102-
if(CMAKE_CXX_COMPILER_LINKER_ID MATCHES MSVC)
104+
check_linker_flag(CXX "LINKER:/DEPENDENTLOADFLAG:0x800" CXX_LINKER_SUPPORTS_DEPENDENTLOADFLAG)
105+
if(CXX_LINKER_SUPPORTS_DEPENDENTLOADFLAG)
103106
# 0x800: Search for the DLL only in the System32 folder
104107
target_link_options(ur_adapter_level_zero PRIVATE LINKER:/DEPENDENTLOADFLAG:0x800)
105108
endif()
@@ -194,7 +197,8 @@ if(UR_BUILD_ADAPTER_L0_V2)
194197
SOVERSION "${PROJECT_VERSION_MAJOR}"
195198
)
196199

197-
if(CMAKE_CXX_COMPILER_LINKER_ID MATCHES MSVC)
200+
check_linker_flag(CXX "LINKER:/DEPENDENTLOADFLAG:0x800" CXX_LINKER_SUPPORTS_DEPENDENTLOADFLAG)
201+
if(CXX_LINKER_SUPPORTS_DEPENDENTLOADFLAG)
198202
# 0x800: Search for the DLL only in the System32 folder
199203
target_link_options(ur_adapter_level_zero_v2 PUBLIC LINKER:/DEPENDENTLOADFLAG:0x800)
200204
endif()

0 commit comments

Comments
 (0)