qt5base-lts/cmake/qt.toolchain.cmake.in
Alexandru Croitor dc26b30acd CMake: Protect against Qt toolchain file recursive inclusion
Three different people have encountered the issue that calling
calling qt-cmake on a project prints 1000 inclusion lines of the same
qt toolchain file, and then CMake bails out saying can't find the
CMAKE_MAKE_PROGRAM Ninja.

This happened because people accidentally called qt-cmake to configure
qtbase (instead of just cmake), which created a toolchain file that
chainloads itself recursively.

Error out when configuring qtbase, and when using the generated
toolchain file in the case when it would try to include itself.

The solution is to remove the qtbase CMakeCache.txt file, and
configure qtbase again, so it generates a proper qt.toolchain.cmake
file.

If somebody feels enthusiastic, they can move the check into the
qt-cmake and qt-cmake-private shell scripts, and error out before the
qtbase/CMakeCache.txt is polluted with the wrong toolchain file.
That is left for people that feel more comfortable with bash and batch
scripting.

Change-Id: If518c94791fe7c30731e6e462e347f26a5213c64
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-06-04 23:21:27 +02:00

37 lines
1.4 KiB
CMake

@init_platform@
@init_qt_host_path@
@init_original_toolchain_file@
@init_vcpkg@
if(__qt_chainload_toolchain_file)
get_filename_component(__qt_chainload_toolchain_file_real_path
"${__qt_chainload_toolchain_file}" REALPATH)
if(__qt_chainload_toolchain_file_real_path STREQUAL CMAKE_CURRENT_LIST_FILE)
message(FATAL_ERROR
"Woah, the Qt toolchain file tried to include itself recusively! '${__qt_chainload_toolchain_file}' "
"Make sure to remove qtbase/CMakeCache.txt and reconfigure qtbase with 'cmake' "
"rather than 'qt-cmake', and then you can reconfigure your own project."
)
else()
include("${__qt_chainload_toolchain_file}")
endif()
unset(__qt_chainload_toolchain_file)
endif()
# Compute dynamically the Qt installation prefix from the location of this file. This allows
# the usage of the toolchain file when the Qt installation is relocated.
get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX
${CMAKE_CURRENT_LIST_DIR}/../@qt_path_from_cmake_config_dir_to_prefix@
ABSOLUTE)
list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
if(QT_HOST_PATH)
list(APPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH}")
list(APPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
endif()