Files
cmake/Tests/RunCMake/Make/InstallNameDir-check.cmake
Florent Castelli 726e6454b5 Ninja,Makefile: Do not convert separators in the install-name directory
The Ninja and Makefile generators passed the install-name directory of a
shared library (`@rpath/` by default, or `INSTALL_NAME_DIR`) through
`ConvertToOutputFormat(SHELL)`.  That converts directory separators for
the host shell, so a Windows host cross-compiling for macOS wrote
`-install_name @rpath\libfoo.dylib`.  The install name is not a host
path: it is embedded in the Mach-O load command and read by dyld on the
target, where a backslash never matches anything.

Escape the value for the shell without converting separators, in both
generators.  Add a test to each that fakes an install-name platform and
checks the generated build files keep the forward slashes.

Fixes: #28104
2026-09-22 14:29:50 -04:00

18 lines
755 B
CMake

# The install-name directory is target data embedded in the binary, so it
# must keep its forward slashes on every host.
foreach(case "rpath_dir;@rpath/" "custom_dir;/custom/dir/")
list(GET case 0 target)
list(GET case 1 dir)
# Generators without link scripts inline the link command in build.make.
set(link_txt "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${target}.dir/link.txt")
if(NOT EXISTS "${link_txt}")
set(link_txt "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${target}.dir/build.make")
endif()
file(READ "${link_txt}" content)
string(FIND "${content}" "-install_name ${dir}" pos)
if(pos EQUAL -1)
string(APPEND RunCMake_TEST_FAILED
"${link_txt} does not contain '-install_name ${dir}':\n${content}")
endif()
endforeach()