Skip to content

Commit

Permalink
CMake: prepend build dir for examples build
Browse files Browse the repository at this point in the history
In cross-compilation, the CMAKE_FIND_ROOT_PATH will have path to the
host Qt and examples build will pick up wrong Qt6Config.cmake unless
the build dir path is prepended.

Pick-to: 6.4 6.3 6.2
Fixes: QTBUG-104270
Change-Id: I7fc7499369a2e5446e1c5257155f81c72716fef7
Reviewed-by: Michal Klocek <[email protected]>
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
sapiippo authored and Michal Klocek committed Jul 21, 2022
1 parent 65d9593 commit 18ed6a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ endfunction()
# Mean to be called when configuring examples as part of the main build tree, as well as for CMake
# tests (tests that call CMake to try and build CMake applications).
macro(qt_internal_set_up_build_dir_package_paths)
list(APPEND CMAKE_PREFIX_PATH "${QT_BUILD_DIR}")
list(PREPEND CMAKE_PREFIX_PATH "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/cmake")
# Make sure the CMake config files do not recreate the already-existing targets
set(QT_NO_CREATE_TARGETS TRUE)
endmacro()
Expand Down Expand Up @@ -833,15 +833,15 @@ macro(qt_examples_build_begin)

# Examples that are built as part of the Qt build need to use the CMake config files from the
# build dir, because they are not installed yet in a prefix build.
# Appending to CMAKE_PREFIX_PATH helps find the initial Qt6Config.cmake.
# Appending to QT_EXAMPLES_CMAKE_PREFIX_PATH helps find components of Qt6, because those
# Prepending to CMAKE_PREFIX_PATH helps find the initial Qt6Config.cmake.
# Prepending to QT_EXAMPLES_CMAKE_PREFIX_PATH helps find components of Qt6, because those
# find_package calls use NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH is ignored.
# Appending to CMAKE_FIND_ROOT_PATH ensures the components are found while cross-compiling
# Prepending to CMAKE_FIND_ROOT_PATH ensures the components are found while cross-compiling
# without setting CMAKE_FIND_ROOT_PATH_MODE_PACKAGE to BOTH.
if(NOT QT_IS_EXTERNAL_EXAMPLES_BUILD OR NOT __qt_all_examples_ported_to_external_projects)
qt_internal_set_up_build_dir_package_paths()
list(APPEND CMAKE_FIND_ROOT_PATH "${QT_BUILD_DIR}")
list(APPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/cmake")
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_BUILD_DIR}")
list(PREPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/cmake")
endif()

# Because CMAKE_INSTALL_RPATH is empty by default in the repo project, examples need to have
Expand Down

0 comments on commit 18ed6a8

Please sign in to comment.