file(REAL_PATH) does not expand symbolink links under Windows
file(REAL_PATH) does not expand symbolic links under Windows.
I created a simple cmake project that tries to expand a symlink, under Cmake for Windows, TEST_ROOT_PATH_2 would not point to the real symlink but rather to the position where the file as, in contrast to what the documentation and behavour under Linux is.
If you try to test the exact same project under WSL2, you will get the expected result.
Steps to reproduce:
- Create two folders, one called d1 where the REAL file is going to be placed and one called d2 where the symlink is going to be placed
- Run the command under Windows
mklink d2\test.txt "absolute path to d1\test.txt
- Try to configure the project under Windows <- this will not work
- Try to configure the project under WSL1 Linux <- this will work
Example cmake file:
cmake_minimum_required(VERSION 3.20)
project(test)
set(E_PATH "d2/test.txt")
set(R_PATH "${CMAKE_CURRENT_LIST_DIR}/d1/test.txt")
file(REAL_PATH ${E_PATH} TEST_ROOT_PATH_2)
message(STATUS "symlink \"${TEST_ROOT_PATH_2}\"")
if (NOT "${TEST_ROOT_PATH_2}" STREQUAL "${R_PATH}")
message(FATAL_ERROR "Wrong!!")
endif()
message(FATAL_ERROR "ok")
Tested environments:
- Windows 11 22H2 with CMake 3.27.4, 3.28.1 and latest nightly at the time of writing 3.28.20231216-g98.5538. Neither of this versions produces the expected results. (reference file system: NTFS)
- Ubuntu 22.04.3 LTS under WSL2 with CMake 3.22.1. This produces the expected result.
Edited by Christian Rendina