Fix some linking rules to allow path with whitespaces (#42718)
Summary:
Essentially, replace `-Wl,--whole-archive,$<TARGET_FILE:FOO>` with `-Wl,--whole-archive,\"$<TARGET_FILE:FOO>\"` as TARGET_FILE might return path containing whitespaces
Fixes https://github.com/pytorch/pytorch/issues/42657
Pull Request resolved: https://github.com/pytorch/pytorch/pull/42718
Reviewed By: ezyang
Differential Revision: D22993568
Pulled By: malfet
fbshipit-source-id: de878b17d20e35b51dd350f20d079c8b879f70b5
diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake
index c46803e..264aa97 100644
--- a/cmake/public/utils.cmake
+++ b/cmake/public/utils.cmake
@@ -48,15 +48,15 @@
# In the case of static library, we will need to add whole-static flags.
if(APPLE)
target_link_libraries(
- ${DST} INTERFACE -Wl,-force_load,$<TARGET_FILE:${SRC}>)
+ ${DST} INTERFACE -Wl,-force_load,\"$<TARGET_FILE:${SRC}>\")
elseif(MSVC)
# In MSVC, we will add whole archive in default.
target_link_libraries(
- ${DST} INTERFACE -WHOLEARCHIVE:$<TARGET_FILE:${SRC}>)
+ ${DST} INTERFACE -WHOLEARCHIVE:\"$<TARGET_FILE:${SRC}>\")
else()
# Assume everything else is like gcc
target_link_libraries(${DST} INTERFACE
- "-Wl,--whole-archive,$<TARGET_FILE:${SRC}> -Wl,--no-whole-archive")
+ "-Wl,--whole-archive,\"$<TARGET_FILE:${SRC}>\" -Wl,--no-whole-archive")
endif()
# Link all interface link libraries of the src target as well.
# For static library, we need to explicitly depend on all the libraries
@@ -80,7 +80,7 @@
elseif(${__src_target_type} STREQUAL "SHARED_LIBRARY")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
target_link_libraries(${DST} INTERFACE
- "-Wl,--no-as-needed,$<TARGET_FILE:${SRC}> -Wl,--as-needed")
+ "-Wl,--no-as-needed,\"$<TARGET_FILE:${SRC}>\" -Wl,--as-needed")
else()
target_link_libraries(${DST} INTERFACE ${SRC})
endif()