REL_SYMLINK install on Windows

Hi,

The following example script creates a relative-path symlink via install and runs a few tests:

file(WRITE "src/hello.txt" "hello\n")

set(ENV{CMAKE_INSTALL_MODE} REL_SYMLINK)
file(INSTALL "src/hello.txt" DESTINATION "out")

set(REL_LINK "out/hello.txt")
if(NOT IS_SYMLINK "${REL_LINK}")
    message(FATAL_ERROR "REL_LINK is not a symlink: ${REL_LINK}")
endif()

file(READ_SYMLINK "${REL_LINK}" TARGET)
message(STATUS "link target : ${TARGET}")

if(EXISTS "${REL_LINK}")
    message(STATUS "link resolves: OK")
else()
    message(STATUS "link resolves: BROKEN")
endif()

On Windows this produces a broken symlink since it’s generated a relative path symlink using forward slashes which Windows doesn’t like.

D:\Projects\symlink-test>cmake -P symlink-test.cmake
-- Installing: D:/Projects/symlink-test/out/hello.txt
-- link target : ../src/hello.txt
-- link resolves: BROKEN

D:\Projects\symlink-test>dir out\hello.txt
09/10/2026  13:15    <SYMLINK>      hello.txt [../src/hello.txt]

D:\Projects\symlink-test>type out\hello.txt
The system cannot find the file specified.

On Linux it works as expected.

$ cmake -P symlink-test.cmake
-- Installing: /home/dave/symlink-test/out/hello.txt
-- link target : ../src/hello.txt
-- link resolves: OK

$ ls -l out/hello.txt
lrwxrwxrwx. 1 dave dave 16 Oct  9 13:22 out/hello.txt -> ../src/hello.txt

$ cat out/hello.txt
hello

If I change it to ABS_SYMLINK it works fine, Windows seems happy with forward slashes in an absolute path symlink:

D:\Projects\symlink-test>cmake -P symlinks-test.cmake
-- Installing: D:/Projects/symlink-test/out/hello.txt
-- link target : \??\D:\Projects\symlink-test\src\hello.txt
-- link resolves: OK

D:\Projects\symlink-test>dir out\hello.txt
09/10/2026  13:32    <SYMLINK>      hello.txt [D:/Projects/symlink-test/src/hello.txt]

D:\Projects\symlink-test>type out\hello.txt
hello

Is this a bug or is there another explanation? The version of CMake doesn’t seem to matter. I’ve tried 3.30.5 and 4.4.4 cos they’re what I had lying around.

Cheers,

Dave.