diff options
| author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-09-28 16:46:54 +0200 |
|---|---|---|
| committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-02-04 15:51:01 +0100 |
| commit | 14e4527cc427ce8c5e7c1758a95a1bbce0498471 (patch) | |
| tree | 9e78de69604f492661d856014c74ad8faa1ce696 /sources/pyside6/cmake/PySideHelpers.cmake | |
| parent | 5d0fd24f0ff9289dba2d41a38a7054770c3a3eee (diff) | |
CMake: pyside: Add support for cross-building
The pyside project will be cross-compiled either if
CMAKE_CROSSCOMPILING is set to TRUE (which is usually set
by a CMake toolchain file or computed by CMake itself)
or if QFP_SHIBOKEN_HOST_PATH is provided on the command line.
Various code is added to ensure the correct target Qt, Python and
Shiboken libraries are found, as well as host Qt and shiboken tools.
These are specified to the project by setting one of the following
vars:
- QFP_QT_TARGET_PATH (for device Qt libs and includes)
- QFP_PYTHON_TARGET_PATH (for device python libs and includes)
- QFP_SHIBOKEN_TARGET_PATH (for device libs)
- QFP_SHIBOKEN_HOST_PATH (for host shiboken generator)
- QT_HOST_PATH (for host moc and friends)
When cross-compiling, pyi file generation is disabled because it's not
possible to run a target python interpeter on a host machine. It might
be possible to do that by using qemu userland emulation in the future.
Task-number: PYSIDE-802
Task-number: PYSIDE-1033
Change-Id: Ifa101e90d83397fa19132f9f0ce21e03b3523a74
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/cmake/PySideHelpers.cmake')
| -rw-r--r-- | sources/pyside6/cmake/PySideHelpers.cmake | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/sources/pyside6/cmake/PySideHelpers.cmake b/sources/pyside6/cmake/PySideHelpers.cmake index b7d8b5578..0a43fedfe 100644 --- a/sources/pyside6/cmake/PySideHelpers.cmake +++ b/sources/pyside6/cmake/PySideHelpers.cmake @@ -1,3 +1,70 @@ +function(pyside_internal_detect_if_cross_building) + if(CMAKE_CROSSCOMPILING OR QFP_SHIBOKEN_HOST_PATH) + set(is_cross_build TRUE) + else() + set(is_cross_build FALSE) + endif() + set(PYSIDE_IS_CROSS_BUILD "${is_cross_build}" PARENT_SCOPE) + message(STATUS "PYSIDE_IS_CROSS_BUILD: ${PYSIDE_IS_CROSS_BUILD}") +endfunction() + +function(pyside_internal_set_up_extra_dependency_paths) + set(extra_root_path_vars + QFP_QT_TARGET_PATH + QFP_PYTHON_TARGET_PATH + QFP_SHIBOKEN_TARGET_PATH + ) + foreach(root_path IN LISTS extra_root_path_vars) + set(new_root_path_value "${${root_path}}") + if(new_root_path_value) + set(new_prefix_path "${CMAKE_PREFIX_PATH}") + list(PREPEND new_prefix_path "${new_root_path_value}/lib/cmake") + set(CMAKE_PREFIX_PATH "${new_prefix_path}") + set(CMAKE_PREFIX_PATH "${new_prefix_path}" PARENT_SCOPE) + + # Need to adjust the prefix and root paths so that find_package(Qt) and other 3rd + # party packages are found successfully when they are located outside of the + # default sysroot (whatever that maybe for the target platform). + if(PYSIDE_IS_CROSS_BUILD) + set(new_root_path "${CMAKE_FIND_ROOT_PATH}") + list(PREPEND new_root_path "${new_root_path_value}") + set(CMAKE_FIND_ROOT_PATH "${new_root_path}") + set(CMAKE_FIND_ROOT_PATH "${new_root_path}" PARENT_SCOPE) + endif() + endif() + endforeach() +endfunction() + +function(pyside_internal_find_host_shiboken_tools) + set(find_package_extra_args) + if(QFP_SHIBOKEN_HOST_PATH) + list(APPEND find_package_extra_args PATHS "${QFP_SHIBOKEN_HOST_PATH}/lib/cmake") + list(PREPEND CMAKE_FIND_ROOT_PATH "${QFP_SHIBOKEN_HOST_PATH}") + endif() + + # When doing a regular build, immediately mark the package as required. + if(NOT PYSIDE_IS_CROSS_BUILD) + list(APPEND "REQUIRED") + endif() + + find_package( + Shiboken6Tools 6 CONFIG + ${find_package_extra_args} + ) + + # When cross building, we show a more helpful error message that + # QFP_SHIBOKEN_HOST_PATH should be provided instead of CMAKE_PREFIX_PATH (specifically + # for the host tools package). + if(PYSIDE_IS_CROSS_BUILD) + if(NOT Shiboken6Tools_DIR) + message(FATAL_ERROR + "Shiboken6Tools package was not found. " + "Please set QFP_SHIBOKEN_HOST_PATH to the location where the Shiboken6Tools " + "CMake package is installed.") + endif() + endif() +endfunction() + macro(collect_essential_modules) # Collect all essential modules. # note: the order of this list is relevant for dependencies. |
