Skip to content

Commit

Permalink
Use REALPATH based check for symbolic links on Windows
Browse files Browse the repository at this point in the history
Windows mount points are marked as symbolic links by CMake. So switch
back to the REALPATH based check for Windows hosts.

Amends dcc2704

Pick-to: 6.2 6.3
Task-number: QTBUG-99416
Change-Id: Ic996db1fac5c0b5edc18728535240e272dd435e0
Reviewed-by: Joerg Bornemann <[email protected]>
Reviewed-by: David Schulz <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
  • Loading branch information
semlanik committed Jan 7, 2022
1 parent 0edbf7f commit b13ee89
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,35 @@ include(.cmake.conf)
# Bail out if any part of the build directory's path is symlinked.
function(qt_internal_check_if_path_has_symlinks path)
get_filename_component(dir "${path}" ABSOLUTE)
while(TRUE)
if(IS_SYMLINK "${dir}")
message(FATAL_ERROR "The path \"${path}\" contains symlinks. \
This is not supported. Possible solutions:
- map directories using a transparent mechanism such as mount --bind
- pass the real path of the build directory to CMake, e.g. using \
cd $(realpath <path>) before invoking cmake <source_dir>.")
set(is_symlink FALSE)
if(CMAKE_HOST_WIN32)
# CMake marks Windows mount points as symbolic links, so use simplified REALPATH check
# on Windows platforms instead of IS_SYMLINK.
get_filename_component(dir_realpath "${dir}" REALPATH)
if(NOT dir STREQUAL dir_realpath)
set(is_symlink TRUE)
endif()

set(prev_dir "${dir}")
get_filename_component(dir "${dir}" DIRECTORY)
if("${dir}" STREQUAL "${prev_dir}")
return()
endif()
endwhile()
else()
while(TRUE)
if(IS_SYMLINK "${dir}")
set(is_symlink TRUE)
break()
endif()

set(prev_dir "${dir}")
get_filename_component(dir "${dir}" DIRECTORY)
if("${dir}" STREQUAL "${prev_dir}")
return()
endif()
endwhile()
endif()
if(is_symlink)
message(FATAL_ERROR "The path \"${path}\" contains symlinks. \
This is not supported. Possible solutions:
- map directories using a transparent mechanism such as mount --bind
- pass the real path of the build directory to CMake, e.g. using \
cd $(realpath <path>) before invoking cmake <source_dir>.")
endif()
endfunction()
qt_internal_check_if_path_has_symlinks("${CMAKE_BINARY_DIR}")

Expand Down

0 comments on commit b13ee89

Please sign in to comment.