Skip to content

Commit

Permalink
CMake: Fix picking of the binary_for_strip project location
Browse files Browse the repository at this point in the history
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 39f6570

Pick-to: 6.2 6.3
Fixes: QTBUG-102064
Task-number: QTBUG-88090
Task-number: QTBUG-101653
Change-Id: I0649f945e9ff0ab1f597c51bb5ab389fa665c021
Reviewed-by: Alexey Edelev <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Jörg Bornemann <[email protected]>
  • Loading branch information
alcroito committed Mar 29, 2022
1 parent 942de89 commit 939a828
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
3 changes: 3 additions & 0 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
61 changes: 41 additions & 20 deletions cmake/QtSeparateDebugInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down Expand Up @@ -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}")

Expand Down

0 comments on commit 939a828

Please sign in to comment.