From 939a8281e66226cfdd175e03cd92818639d31765 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 28 Mar 2022 16:59:20 +0200 Subject: [PATCH] CMake: Fix picking of the binary_for_strip project location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix binary_for_strip project not being found when the following conditions were met: - building a repo other than qtbase - qtbase sources are not available on the machine (usually happens in CI where only the current repo sources are available). The issue was that QT_CMAKE_DIR would always be defined, regardless of which repo was being built and the system would incorrectly assume the location of the project files. The fix is to always pick up the sources from qtbase's source dir if they are available (this time done with an appropriate check), otherwise use the installed files. Note that the behavior of always using the qtbase sources if available is not exactly the best, but it is a more general issue that affects other code too. In the name of consistency, make it so for the binary_for_strip project as well, but add TODOs in code to address the situation in a separate change. Amends 39f657032b5e65bfcb93472201f6607c0388ba37 Pick-to: 6.2 6.3 Fixes: QTBUG-102064 Task-number: QTBUG-88090 Task-number: QTBUG-101653 Change-Id: I0649f945e9ff0ab1f597c51bb5ab389fa665c021 Reviewed-by: Alexey Edelev Reviewed-by: Qt CI Bot Reviewed-by: Jörg Bornemann --- .../QtBuildInternalsConfig.cmake | 3 + cmake/QtSeparateDebugInfo.cmake | 61 +++++++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index a6891241e76..e05d922b160 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -74,6 +74,9 @@ macro(qt_set_up_build_internals_paths) # building qtdeclarative, rather than having to build qtbase first (which will copy # QtBuild.cmake to the build dir). This is similar to qmake non-prefix builds, where the # source qtbase/mkspecs directory is used. + # TODO: Clean this up, together with qt_internal_try_compile_binary_for_strip to only use the + # the qtbase sources when building qtbase. And perhaps also when doing a non-prefix + # developer-build. if(EXISTS "${QT_SOURCE_TREE}/cmake") list(PREPEND CMAKE_MODULE_PATH "${QT_SOURCE_TREE}/cmake") endif() diff --git a/cmake/QtSeparateDebugInfo.cmake b/cmake/QtSeparateDebugInfo.cmake index a5f57d4d13a..e983a3b6c29 100644 --- a/cmake/QtSeparateDebugInfo.cmake +++ b/cmake/QtSeparateDebugInfo.cmake @@ -6,21 +6,31 @@ endif() # Builds a shared library which will have strip run on it. function(qt_internal_try_compile_binary_for_strip binary_out_var) - # Need to find the config.tests files depending on which repo we are building. - if(EXISTS "${QT_CMAKE_DIR}") - # building qtbase - set(basedir "${QT_CMAKE_DIR}/..") - else() - # building other repo - set(basedir "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}") - endif() + # Need to find the config.tests files depending whether the qtbase sources are available. + # This mirrors the logic in qt_set_up_build_internals_paths. + # TODO: Clean this up, together with qt_set_up_build_internals_paths to only use the + # the qtbase sources when building qtbase. And perhaps also when doing a non-prefix + # developer-build. set(config_test_dir "config.tests/binary_for_strip") - set(src_dir "${basedir}/${config_test_dir}") + set(qtbase_config_test_dir "${QT_SOURCE_TREE}/${config_test_dir}") + set(installed_config_test_dir + "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}/${config_test_dir}") + + # qtbase sources available, always use them, regardless of prefix or non-prefix builds. + if(EXISTS "${qtbase_config_test_dir}") + set(src_dir "${qtbase_config_test_dir}") + + # qtbase sources unavailable, use installed files. + elseif(EXISTS "${installed_config_test_dir}") + set(src_dir "${installed_config_test_dir}") + else() + message(FATAL_ERROR "Can't find binary_for_strip config test project.") + endif() # Make sure the built project files are not installed when doing an in-source build (like it # happens in Qt's CI) by choosing a build dir that does not coincide with the installed - # source dir. + # source dir. Otherwise the config test binaries will be packaged up, which we don't want. set(binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${config_test_dir}_built") set(flags "") @@ -137,18 +147,29 @@ function(qt_internal_generate_binary_strip_wrapper) set(script_name "qt-internal-strip") - if(EXISTS "${QT_CMAKE_DIR}") - # qtbase build-tree case - set(wrapper_in_basedir "${QT_CMAKE_DIR}/..") - else() - # other repo case - set(wrapper_in_basedir "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}") - endif() - # the libexec literal is used on purpose for the source, so the file is found # on Windows hosts. - set(wrapper_in - "${wrapper_in_basedir}/libexec/${script_name}${wrapper_extension}.in") + set(wrapper_rel_path "libexec/${script_name}${wrapper_extension}.in") + + # Need to find the libexec input file depending whether the qtbase sources are available. + # This mirrors the logic in qt_set_up_build_internals_paths. + # TODO: Clean this up, together with qt_set_up_build_internals_paths to only use the + # the qtbase sources when building qtbase. And perhaps also when doing a non-prefix + # developer-build. + set(qtbase_wrapper_in_path "${QT_SOURCE_TREE}/${wrapper_rel_path}") + set(installed_wrapper_in_path + "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}/${wrapper_rel_path}") + + # qtbase sources available, always use them, regardless of prefix or non-prefix builds. + if(EXISTS "${qtbase_wrapper_in_path}") + set(wrapper_in "${qtbase_wrapper_in_path}") + + # qtbase sources unavailable, use installed files. + elseif(EXISTS "${installed_wrapper_in_path}") + set(wrapper_in "${installed_wrapper_in_path}") + else() + message(FATAL_ERROR "Can't find ${script_name}${wrapper_extension}.in file.") + endif() set(wrapper_out "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}${wrapper_extension}")