diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-03-25 13:43:33 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2020-03-26 12:46:16 +0100 |
commit | 9968a211f92c2b4d5bd1fe004f16ec1c5f968dcd (patch) | |
tree | 87842032554d8d80e2fe0c7c004b5ca4a9ad4243 | |
parent | f2208c59e70333cecf613390917a104f7c1f110b (diff) |
CMake: Fix pkgconfig calls when cross-compiling
When cross-compiling with CMake, before this patch pkgconfig calls would
find libraries which are part of the host system and not the target
system.
The current approach used is based of the discussion present in
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4478, and should
be considered a temporary solution until the issue is properly addressed
in upstream CMake.
Change-Id: I535d4d48c2a5d34689082b80501b3b6ae30d7845
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmake/QtConfig.cmake.in | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b11c4bd93b..7cf6e7cac3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,16 @@ cmake_minimum_required(VERSION 3.15.0) # Run auto detection routines include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtAutoDetect.cmake) +if (CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT) + # When cross compiling with CMake any calls to pkg_check_modules() will + # search into the host system instead of the target sysroot. + # The current work around is based on the discussion found at + # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4478 + set(ENV{PKG_CONFIG_DIR} "") + set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") + set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT}) +endif() + project(QtBase VERSION 6.0.0 DESCRIPTION "Qt Base Libraries" diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index b63dca8732..8e828e8f33 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -1,5 +1,15 @@ @PACKAGE_INIT@ +if (CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT) + # When cross compiling with CMake any calls to pkg_check_modules() will + # search into the host system instead of the target sysroot. + # The current work around is based on the discussion found at + # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4478 + set(ENV{PKG_CONFIG_DIR} "") + set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") + set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT}) +endif() + # Slightly amended version of ./src/corelib/Qt6Config.cmake.in if (CMAKE_VERSION VERSION_LESS 3.1.0) message(FATAL_ERROR "Qt requires at least CMake version 3.1.0") |