clang-cl: Drive linking via compiler front-end
I would like to use clang-cl as CMAKE_LINKER
to not have to manually link the adresse/ubsan libs. After changing the default Windows-MSVC platform file to have
set(CMAKE_${lang}_LINK_EXECUTABLE
"${_CMAKE_VS_LINK_EXE}<CMAKE_${lang}_COMPILER> ${CMAKE_CL_NOLOGO} <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <OBJECTS> /link ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
I got it to pass the compiler detection (try_compile
) but the build itself fails even though I adjusted:
set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
"${_CMAKE_VS_LINK_DLL}<CMAKE_${lang}_COMPILER> ${CMAKE_CL_NOLOGO} <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <OBJECTS> /link ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
It fails due to missing linkage to the sanitizer libs. From the build log I have to assume that the placeholders <FLAGS> <CMAKE_${lang}_LINK_FLAGS>
are not getting expanded and added to the build (e.g. -- C:\PROGRA~1\LLVM\bin\clang-cl.exe /nologo <should_have_flags_here_but_here_is_empty_space> CMakeFiles\zlib.dir\adler32.c.obj
)
Since I basically copied the changes from the IntelLLVM Platform I am wondering how that is supposed to work there ;)
(could also be related to #23773)