Skip to content

Commit 5013cf6

Browse files
authored
[cmake] Add symbolic links for MSVC libraries (#106710)
When cross-compiling a Windows clang with `-DLLVM_BUILD_INSTRUMENTED`, the profiling compiler-rt is linked to binaries, as one would expect, but the profiling compiler-rt contains objects with `/DEFAULTLIB:LIBCMT` and `/DEFAULTLIB:OLDNAMES` directives, which makes the build expect `LIBCMT.lib` and `OLDNAMES.lib`, but they are nowhere to be found because they are in lowercase. While the WinMsvc.cmake helper recreates symbolic links to work around such case sensitivity issues for the Windows SDK libs, it doesn't do so for the MSVC libs, which we add here.
1 parent 332e6f8 commit 5013cf6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/cmake/platforms/WinMsvc.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
9595
LLVM_WINSYSROOT
9696
MSVC_VER
9797
WINSDK_VER
98+
msvc_lib_symlinks_dir
9899
winsdk_lib_symlinks_dir
99100
winsdk_vfs_overlay_path
100101
)
@@ -156,6 +157,24 @@ function(generate_winsdk_lib_symlinks winsdk_um_lib_dir output_dir)
156157
endforeach()
157158
endfunction()
158159

160+
function(generate_msvc_lib_symlinks msvc_lib_dir output_dir)
161+
execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${output_dir}")
162+
file(GLOB libraries RELATIVE "${msvc_lib_dir}" "${msvc_lib_dir}/*.lib")
163+
foreach(library ${libraries})
164+
get_filename_component(name_wle "${library}" NAME_WLE)
165+
get_filename_component(ext "${library}" LAST_EXT)
166+
string(TOLOWER "${ext}" lowercase_ext)
167+
string(TOUPPER "${name_wle}" all_uppercase_symlink_name_wle)
168+
set(uppercase_symlink_name "${all_uppercase_symlink_name_wle}${lowercase_ext}")
169+
if(NOT library STREQUAL uppercase_symlink_name)
170+
execute_process(COMMAND "${CMAKE_COMMAND}"
171+
-E create_symlink
172+
"${msvc_lib_dir}/${library}"
173+
"${output_dir}/${uppercase_symlink_name}")
174+
endif()
175+
endforeach()
176+
endfunction()
177+
159178
function(get_highest_version the_dir the_ver)
160179
file(GLOB entries LIST_DIRECTORIES true RELATIVE "${the_dir}" "${the_dir}/[0-9.]*")
161180
foreach(entry ${entries})
@@ -297,6 +316,12 @@ if(case_sensitive_filesystem)
297316
endif()
298317
list(APPEND LINK_FLAGS
299318
-libpath:"${winsdk_lib_symlinks_dir}")
319+
if(NOT msvc_lib_symlinks_dir)
320+
set(msvc_lib_symlinks_dir "${CMAKE_BINARY_DIR}/msvc_lib_symlinks")
321+
generate_msvc_lib_symlinks("${MSVC_LIB}/${WINSDK_ARCH}" "${msvc_lib_symlinks_dir}")
322+
endif()
323+
list(APPEND LINK_FLAGS
324+
-libpath:"${msvc_lib_symlinks_dir}")
300325
endif()
301326

302327
string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")

0 commit comments

Comments
 (0)