oneapi-src / level-zero

oneAPI Level Zero Specification Headers and Loader
https://spec.oneapi.com/versions/latest/elements/l0/source/index.html
MIT License
222 stars 98 forks source link

Unescaped linker flags when building with the Intel C++ Compiler on Windows and CMake > 3.25 #205

Closed Maetveis closed 1 month ago

Maetveis commented 2 months ago

Description

From CMake 3.25 onwards when using the Intel C++ Compiler linking flags need to be wrapped with LINKER: or /Qoption,link because CMake uses the compiler driver for linking.

If the options are not wrapped they are ignore by icx with a warning.

Reproducer

To make the error more obvious I enabled warnings as errors for the linking stage:

# configure
cmake -DCMAKE_SHARED_LINKER_FLAGS_INIT="-Werror=unknown-argument" -S . -B build -G Ninja
# build
cmake --build build

Results in the following error:

[14/51] Linking CXX shared library bin\ze_null.dll
FAILED: bin/ze_null.dll lib/ze_null.lib
C:\WINDOWS\system32\cmd.exe /C "cd . && cmake.exe -E vs_link_dll --intdir=source\drivers\null\CMakeFiles\ze_null.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests  -- icx.exe /nologo source\drivers\null\CMakeFiles\ze_null.dir\ze_null.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\ze_nullddi.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\zet_nullddi.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\zes_nullddi.cpp.obj  -LD -Werror=unknown-argument /DYNAMICBASE /guard:cf /CETCOMPAT  /DEBUG /OPT:REF /OPT:ICF  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -link /out:bin\ze_null.dll /implib:lib\ze_null.lib /pdb:bin\ze_null.pdb /version:1.17 && cd ."
LINK: command "icx.exe /nologo source\drivers\null\CMakeFiles\ze_null.dir\ze_null.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\ze_nullddi.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\zet_nullddi.cpp.obj source\drivers\null\CMakeFiles\ze_null.dir\zes_nullddi.cpp.obj -LD -Werror=unknown-argument /DYNAMICBASE /guard:cf /CETCOMPAT /DEBUG /OPT:REF /OPT:ICF kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -link /out:bin\ze_null.dll /implib:lib\ze_null.lib /pdb:bin\ze_null.pdb /version:1.17 /MANIFEST:EMBED,ID=2" failed (exit code 1) with the following output:     
icx: error: unknown argument ignored in clang-cl: '-CETCOMPAT' [-Werror,-Wunknown-argument]