summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-05-05 10:30:35 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2020-05-07 15:41:16 +0200
commitbf315c5526cb5cce6581de89f2747d7d2c3bad0a (patch)
tree0854ebfa49383f467ec10b6012c22bc598b56815 /bin
parentc70dcffbdb83fad1c829ea3c2aff7b74e66f0eec (diff)
CMake: Make build system of installed Qt more relocatable
Aka handle CMAKE_INSTALL_PREFIX in a more relocatable way. The following story inspired this change. If a user wants to build a Qt repo into a different install prefix than the usual Qt one, this will fail configuration because we look for various things like syncqt, qdoc, etc relative to CMAKE_INSTALL_PREFIX, which will now point to a different location where none of the above tools are located. The intent for such a use case is to support building Qt packages with Conan, which sets a random install prefix when configuring a repo. The idea is to derive the qt prefix dynamically from the QtBuildInternals package location. Essentially it's a reverse relative path from the QtBuildInternalsConfig.cmake file to the install prefix that was specified when initially configuring qtbase. Once the dynamic prefix is computed (so we know where the possibly relocated Qt is), we can find tools like syncqt and qdoc. This is an initial attempt to support a use case like that. More design work will probably needed in case if tools / libs need to be found in a location different than the Qt install prefix (so support for multiple install prefixes / search paths). An example of such a case would be when building qtdeclarative and qtquickcontrols2 as Conan packages in one go. Most likely the qmltyperegistrar tool will be located in the random install prefix set by Conan, so building qtquickcontrols2 might fail due to not finding the tool in the original Qt install prefix. As to the implementation details, the change does the following: - Dynamically computes and sets the QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX variable when find_package()'ing QtBuildInternals. It's an absolute path pointing to where the relocated Qt is. - When building qtbase this variable is not yet available (due to QtBuildInternalsExtra not existing), in that case we set the variable to the absolute path of CMAKE_INSTALL_PREFIX (but only for the initial qtbase configuration). - Remove QT_BUILD_INTERNALS_ORIGINAL_INSTALL_PREFIX which was used for standalone tests purposes. It's not needed now that we compute the location of the Qt prefix dynamically. - The Unixy qt-cmake and qt-cmake-private shell scripts now use a relative path to find the toolchain file we created. - The toolchain file also dynamically computes the location of the Qt packages, and adds them to CMAKE_PREFIX_PATH. - A lot of existing CMAKE_INSTALL_PREFIX uses are replaced with QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX. This includes finding tool locations, mkspecs dir, path environment setup for tools, etc. - Some places still use CMAKE_PREFIX_PATH in the following cases - When determining paths while configuring qtbase (valid cases) - When I wasn't sure what the behavior should be, so I left them as-is (an example is documentation generation, do we want to install it into the random Conan prefix, or into the main prefix? Currently it installs in the random prefix). Note that relocating a Qt installation does not work for non-prefix / non-installed builds, due to hardcoded paths to include directories and libraries in generated FooTargets.cmake files. Task-number: QTBUG-83999 Change-Id: I87d6558729db93121b1715771034b03ce3295923 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'bin')
-rw-r--r--bin/qt-cmake.bat.in11
-rwxr-xr-xbin/qt-cmake.in16
2 files changed, 25 insertions, 2 deletions
diff --git a/bin/qt-cmake.bat.in b/bin/qt-cmake.bat.in
index 6e5b27010b..2645c0320f 100644
--- a/bin/qt-cmake.bat.in
+++ b/bin/qt-cmake.bat.in
@@ -1 +1,10 @@
-"@CMAKE_COMMAND@" -DCMAKE_TOOLCHAIN_FILE="@__GlobalConfig_install_dir_absolute@/qt.toolchain.cmake" @__qt_cmake_extra@ %*
+@echo off
+:: The directory of this script is the expanded absolute path of the "$qt_prefix/bin" directory.
+set script_dir_path=%~dp0
+
+:: Try to use original cmake, otherwise to make it relocatable, use any cmake found in PATH.
+set cmake_path=@CMAKE_COMMAND@
+if not exist "%cmake_path%" set cmake_path=cmake
+
+set toolchain_path=%script_dir_path%/@__GlobalConfig_relative_path_from_bin_dir_to_cmake_config_dir@/qt.toolchain.cmake
+"%cmake_path%" -DCMAKE_TOOLCHAIN_FILE="%toolchain_path%" @__qt_cmake_extra@ %*
diff --git a/bin/qt-cmake.in b/bin/qt-cmake.in
index 2b42592267..f719257f60 100755
--- a/bin/qt-cmake.in
+++ b/bin/qt-cmake.in
@@ -1,3 +1,17 @@
#!/bin/sh
-exec @CMAKE_COMMAND@ -DCMAKE_TOOLCHAIN_FILE=@__GlobalConfig_install_dir_absolute@/qt.toolchain.cmake @__qt_cmake_extra@ "$@"
+# The directory of this script is the expanded absolute path of the "$qt_prefix/bin" directory.
+script_dir_path=`dirname $0`
+script_dir_path=`(cd "$script_dir_path"; /bin/pwd)`
+
+# Try to use original cmake, otherwise to make it relocatable, use any cmake found in PATH.
+original_cmake_path="@CMAKE_COMMAND@"
+cmake_path=$original_cmake_path
+if ! test -f "$cmake_path"; then
+ cmake_path="cmake"
+fi
+
+toolchain_path="$script_dir_path/@__GlobalConfig_relative_path_from_bin_dir_to_cmake_config_dir@/qt.toolchain.cmake"
+
+# Find the qt toolchain relative to the absolute bin dir path where the script is located.
+exec "$cmake_path" -DCMAKE_TOOLCHAIN_FILE="$toolchain_path" @__qt_cmake_extra@ "$@"