From dcc2704d17bda08e6dc7783559ccbfd864dd4339 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 23 Dec 2021 13:20:21 +0100 Subject: Use IS_SYMLINK condition instead of REALPATH when checking BINARY_DIR For case-insensitive file systems, the REALPATH file component may return file paths in a different case than ABSOULEPATH. We use REALPATH to detect symlinks. In case-sensitive file systems there still might be the situation when /path/to/Build is a symlink to the /path/to/build, so we cannot make the comparison case-insensitive. Use the IS_SYMLINK check instead. Pick-to: 6.2 6.3 Fixes: QTBUG-99416 Change-Id: Idf998b9e09837a834139553fb822e05b2a0a1949 Reviewed-by: Joerg Bornemann --- CMakeLists.txt | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 963ed295bf..56fa1adb22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,21 +12,25 @@ cmake_minimum_required(VERSION 3.16) include(.cmake.conf) # Bail out if any part of the build directory's path is symlinked. -# The OS-level current working directory is always the real path and some -# parts of the build system only deal with that path, which causes confusion -# when compared to the logical working directory maintained by the shell and -# passed on the command line. -get_filename_component(build_dir_absolute "${CMAKE_BINARY_DIR}" ABSOLUTE) -get_filename_component(build_dir_realpath "${CMAKE_BINARY_DIR}" REALPATH) -if(NOT build_dir_absolute STREQUAL build_dir_realpath) - message(FATAL_ERROR "The build path \"${CMAKE_BINARY_DIR}\" contains symlinks. \ +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 ) before invoking cmake .") -endif() -unset(build_dir_absolute) -unset(build_dir_realpath) +cd $(realpath ) before invoking cmake .") + endif() + + set(prev_dir "${dir}") + get_filename_component(dir "${dir}" DIRECTORY) + if("${dir}" STREQUAL "${prev_dir}") + return() + endif() + endwhile() +endfunction() +qt_internal_check_if_path_has_symlinks("${CMAKE_BINARY_DIR}") # Run auto detection routines, but not when doing standalone tests. In that case, the detection # results are taken from either QtBuildInternals or the qt.toolchain.cmake file. Also, inhibit -- cgit v1.2.3