Incorrect link library flags in mixed C++/ASM project using MSVC with Clang

I am experiencing an issue in a mixed C++/ASM project on Windows using MSVC as the C++ compiler and Clang for the assembler.

When configuring a project for Ninja passing -DCMAKE_ASM_COMPILER=clang, bare link library names in C++ targets have a -l flag prefixed to them but the linker is link.exe which does not use -l for handling link libraries.

The same issue seems to occur whether clang is used with the GNU command-line frontend or clang-cl is used with the MSVC command-line frontend.

Here is a simple example to reproduce it.

# CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(cmake-issue LANGUAGES CXX ASM)

add_executable(cmake-issue main.cpp)
target_link_libraries(cmake-issue bcrypt)
// main.cpp
#include <windows.h>
#include <bcrypt.h>

int main() {
  BCryptCreateContext(CRYPT_LOCAL, L"", NULL);
}

Using Ninja as the generator and compiling it will yield linking errors.

PS > cmake -G Ninja -B build -DCMAKE_ASM_COMPILER=clang
-- The CXX compiler identification is MSVC 19.44.35225.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang.exe
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.6s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/User/Documents/cmake-issue/build
PS > cd .\build\
PS .\build> ninja
[2/2] Linking CXX executable cmake-issue.exe
FAILED: cmake-issue.exe 
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --msvc-ver=1944 --intdir=CMakeFiles\cmake-issue.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles/cmake-issue.dir/main.cpp.obj  /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  -lbcrypt  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles/cmake-issue.dir/main.cpp.obj /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -lbcrypt kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmake-issue.dir/intermediate.manifest CMakeFiles\cmake-issue.dir/manifest.res" failed (exit code 1120) with the following output:
LINK : warning LNK4044: unrecognized option '/lbcrypt'; ignored
main.cpp.obj : error LNK2019: unresolved external symbol BCryptCreateContext referenced in function main
cmake-issue.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
PS .\build>

The link command includes -lbcrypt when it should be bcrypt.lib. The same issue occurs if clang-cl is used for the assembler instead of the GNU command-line frontend version.

Removing ASM from the list of languages will pass the correct bcrypt.lib library in the link command so this only occurs if mixing assembly in a project on Windows.

I have tested this with CMake 3.31 and the latest 4.3.1 versions and they both experience the same behavior.

Figured I should ask here to see if others have experienced this or if there is some underlying issue with how the link command is generated.