CMake: Bail out if the build dir is symlinked

Building Qt in a symlinked build directory leads to all kind of issues,
like unnecessary rebuilds, strange compilation errors or already errors
at configure time.

Detect this situation and bail out early with an informative error
message.

Task-number: QTBUG-88418
Task-number: QTBUG-89559
Change-Id: I70c16e11a7eede7a183f6f56b73ea93f985312f3
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Joerg Bornemann 2020-12-17 13:41:38 +01:00
parent c6379e3499
commit 41aff1cd93

View File

@ -8,6 +8,16 @@ cmake_minimum_required(VERSION 3.16)
# Get the repo version and CMake policy details
include(.cmake.conf)
# Bail out if parts of the build directory's components are symlinks.
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. \
This is not supported. Please use some other - transparent - mechanism to map directories.")
endif()
unset(build_dir_absolute)
unset(build_dir_realpath)
# Early check to reduce chance of warning being lost in the output
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake")
qt_internal_check_for_suitable_cmake_version()