diff options
| -rw-r--r-- | build_scripts/main.py | 10 | ||||
| -rw-r--r-- | build_scripts/platforms/macos.py | 8 | ||||
| -rw-r--r-- | build_scripts/platforms/unix.py | 2 | ||||
| -rw-r--r-- | build_scripts/wheel_override.py | 2 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/QtGui/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | sources/pyside6/cmake/Macros/PySideModules.cmake | 29 | ||||
| -rw-r--r-- | sources/pyside6/cmake/PySideHelpers.cmake | 19 | ||||
| -rw-r--r-- | sources/shiboken6/cmake/ShibokenHelpers.cmake | 17 | ||||
| -rw-r--r-- | tools/cross_compile_android/main.py | 1 |
9 files changed, 79 insertions, 18 deletions
diff --git a/build_scripts/main.py b/build_scripts/main.py index 9a8d4fb3f..dac476cdb 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -508,7 +508,11 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): log.info("-" * 3) if sys.platform == 'win32': log.info(f"OpenSSL dll directory: {OPTION['OPENSSL']}") - if sys.platform == 'darwin': + # for cross-compilation it is possible to use a macOS host, but + # pyside_macos_deployment_target is not relevant for the target. + # The only exception here is when we are trying to cross-compile from intel mac to m1 mac. + # This case is not supported yet. + if sys.platform == 'darwin' and not self.is_cross_compile: pyside_macos_deployment_target = (macos_pyside_min_deployment_target()) log.info(f"MACOSX_DEPLOYMENT_TARGET set to: {pyside_macos_deployment_target}") log.info("=" * 30) @@ -745,7 +749,9 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): cmake_cmd += platform_cmake_options() - if sys.platform == 'darwin': + # for a macOS host, cross-compilation is possible, but for the host system as such + # we only build shiboken. Hence the following code can be skipped. + if sys.platform == 'darwin' and not self.is_cross_compile: if OPTION["MACOS_ARCH"]: # also tell cmake which architecture to use cmake_cmd.append(f"-DCMAKE_OSX_ARCHITECTURES:STRING={OPTION['MACOS_ARCH']}") diff --git a/build_scripts/platforms/macos.py b/build_scripts/platforms/macos.py index dbe60d343..505573e0b 100644 --- a/build_scripts/platforms/macos.py +++ b/build_scripts/platforms/macos.py @@ -21,7 +21,7 @@ def _macos_patch_executable(name, _vars=None): macos_add_rpath(rpath, binary) -def prepare_standalone_package_macos(pyside_build, _vars): +def prepare_standalone_package_macos(pyside_build, _vars, is_android=False): built_modules = _vars['built_modules'] constrain_modules = None @@ -119,7 +119,11 @@ def prepare_standalone_package_macos(pyside_build, _vars): ignored_modules = [] if not pyside_build.is_webengine_built(built_modules): ignored_modules.extend(['libQt6WebEngine*.dylib']) + accepted_modules = ['libQt6*.6.dylib'] + if is_android: + accepted_modules = ['libQt6*.so', '*-android-dependencies.xml'] + if constrain_modules: accepted_modules = [f"libQt6{module}*.6.dylib" for module in constrain_modules] @@ -156,6 +160,8 @@ def prepare_standalone_package_macos(pyside_build, _vars): # <qt>/plugins/* -> <setup>/{st_package_name}/Qt/plugins plugins_target = destination_qt_dir / "plugins" filters = ["*.dylib"] + if is_android: + filters = ["*.so"] copydir("{qt_plugins_dir}", plugins_target, _filter=filters, recursive=True, diff --git a/build_scripts/platforms/unix.py b/build_scripts/platforms/unix.py index 3333f5f96..8378d42be 100644 --- a/build_scripts/platforms/unix.py +++ b/build_scripts/platforms/unix.py @@ -237,7 +237,7 @@ def prepare_packages_posix(pyside_build, _vars, cross_build=False): if config.is_internal_pyside_build() or config.is_internal_shiboken_generator_build(): _vars['built_modules'] = generated_config['built_modules'] if sys.platform == 'darwin': - prepare_standalone_package_macos(pyside_build, _vars) + prepare_standalone_package_macos(pyside_build, _vars, is_android=is_android) else: prepare_standalone_package_linux(pyside_build, _vars, cross_build, is_android=is_android) diff --git a/build_scripts/wheel_override.py b/build_scripts/wheel_override.py index f3f9f17a9..790282cd4 100644 --- a/build_scripts/wheel_override.py +++ b/build_scripts/wheel_override.py @@ -47,7 +47,7 @@ class PysideBuildWheel(_bdist_wheel, CommandMixin): def finalize_options(self): CommandMixin.mixin_finalize_options(self) - if sys.platform == 'darwin': + if sys.platform == 'darwin' and not self.is_cross_compile: # Override the platform name to contain the correct # minimum deployment target. # This is used in the final wheel name. diff --git a/sources/pyside6/PySide6/QtGui/CMakeLists.txt b/sources/pyside6/PySide6/QtGui/CMakeLists.txt index 99e0789d1..c868b6c88 100644 --- a/sources/pyside6/PySide6/QtGui/CMakeLists.txt +++ b/sources/pyside6/PySide6/QtGui/CMakeLists.txt @@ -313,6 +313,15 @@ set(QtGui_private_include_dirs ${Qt${QT_MAJOR_VERSION}Core_PRIVATE_INCLUDE_DIRS} ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS}) +if (${CMAKE_SYSTEM_NAME} STREQUAL "Android") + if (QT_FEATURE_opengles2) + # add openGL ES 2.0 + find_package(GLESv2 REQUIRED) + else() + message(FATAL_ERROR "QtGui requires OpenGL ES 2.0 on Android") + endif() +endif() + configure_file("${QtGui_SOURCE_DIR}/QtGui_global.post.h.in" "${QtGui_BINARY_DIR}/QtGui_global.post.h" @ONLY) diff --git a/sources/pyside6/cmake/Macros/PySideModules.cmake b/sources/pyside6/cmake/Macros/PySideModules.cmake index 1e434f9f6..33b844f95 100644 --- a/sources/pyside6/cmake/Macros/PySideModules.cmake +++ b/sources/pyside6/cmake/Macros/PySideModules.cmake @@ -194,6 +194,35 @@ macro(create_pyside_module) --lean-headers --api-version=${SUPPORTED_QT_VERSION}) + # check if building for Android with a macOS host + # This is not needed for Linux because OpenGLES2 development binaries in + # linux can be installed by installing 'libgles2-mesa-dev' package which + # comes as a default requirement for building PySide6. As such for + # cross-compiling in linux, we use the clang compiler from the installed + # libclang itself. + if(CMAKE_ANDROID_ARCH_LLVM_TRIPLE AND CMAKE_HOST_APPLE) + message(STATUS "Building for Android with arch ${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}") + list(APPEND shiboken_command "--clang-option=--target=${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}") + + # CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX does not contain the ANDROID_PLATFORM i.e. it ends with + # the form 'aarch64-linux-android-'. Remove the last '-' and add the corresponding clang + # based on ANDROID_PLATFORM making it 'aarch64-linux-android26-clang++' + + # Get the length of the string + string(LENGTH "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}" _length) + + # Subtract 1 from the length to get the characters till '-' + math(EXPR _last_index "${_length} - 1") + + # Get the substring from the start to the character before the last one + string(SUBSTRING "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}" 0 "${_last_index}" + SHIBOKEN_ANDROID_COMPILER_PREFIX) + + # use the compiler from the Android NDK + list(APPEND shiboken_command + "--compiler-path=${SHIBOKEN_ANDROID_COMPILER_PREFIX}${CMAKE_ANDROID_API}-clang++") + endif() + if(CMAKE_HOST_APPLE) set(shiboken_framework_include_dir_list ${QT_FRAMEWORK_INCLUDE_DIR}) make_path(shiboken_framework_include_dirs ${shiboken_framework_include_dir_list}) diff --git a/sources/pyside6/cmake/PySideHelpers.cmake b/sources/pyside6/cmake/PySideHelpers.cmake index 23ceda6bd..01c438107 100644 --- a/sources/pyside6/cmake/PySideHelpers.cmake +++ b/sources/pyside6/cmake/PySideHelpers.cmake @@ -138,13 +138,18 @@ macro(check_os) set(ENABLE_MAC "0") set(ENABLE_WIN "0") - if(CMAKE_HOST_APPLE) - set(ENABLE_MAC "1") - elseif(CMAKE_HOST_WIN32) - set(ENABLE_WIN "1") - set(ENABLE_UNIX "0") - elseif(NOT CMAKE_HOST_UNIX) - message(FATAL_ERROR "OS not supported") + # check if Android, if so, set ENABLE_UNIX=1 + # this is needed to avoid including the wrapper specific to macOS when building for Android + # from a macOS host + if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CMAKE_HOST_APPLE) + set(ENABLE_MAC "1") + elseif(CMAKE_HOST_WIN32) + set(ENABLE_WIN "1") + set(ENABLE_UNIX "0") + elseif(NOT CMAKE_HOST_UNIX) + message(FATAL_ERROR "OS not supported") + endif() endif() endmacro() diff --git a/sources/shiboken6/cmake/ShibokenHelpers.cmake b/sources/shiboken6/cmake/ShibokenHelpers.cmake index 8bc066102..cff6df95e 100644 --- a/sources/shiboken6/cmake/ShibokenHelpers.cmake +++ b/sources/shiboken6/cmake/ShibokenHelpers.cmake @@ -202,12 +202,6 @@ macro(get_python_extension_suffix) # Python_SOABI is only set by CMake 3.17+ # TODO: Lower this to CMake 3.16 if possible. if(SHIBOKEN_IS_CROSS_BUILD) - # For android platform armv7a FindPython module return Python_SOABI as empty because - # it is unable to set Python_CONFIG i.e. find `python3-config` script - # This workaround sets the Python_SOABI manually for this platform. - if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") - set(Python_SOABI "cpython-311}") - endif() if(NOT Python_SOABI) message(FATAL_ERROR "Python_SOABI variable is empty.") endif() @@ -320,6 +314,17 @@ macro(shiboken_find_required_python) "${_shiboken_backup_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}") set(CMAKE_FIND_ROOT_PATH "${_shiboken_backup_CMAKE_FIND_ROOT_PATH}") + + # For Android platform sometimes the FindPython module returns Python_SOABI as empty in + # certain scenarios eg: armv7a target, macOS host etc. This is because + # it is unable to set Python_CONFIG i.e. `python3-config` script + # This workaround sets the Python_SOABI manually for this Android platform. + # This needs to be updated manually if the Python version for Android cross compilation + # changes. + # TODO: Find a better way to set Python_SOABI for Android platform + if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT Python_SOABI) + set(Python_SOABI "cpython-311") + endif() else() find_package( Python diff --git a/tools/cross_compile_android/main.py b/tools/cross_compile_android/main.py index b68fd5031..200f494cf 100644 --- a/tools/cross_compile_android/main.py +++ b/tools/cross_compile_android/main.py @@ -18,6 +18,7 @@ from android_utilities import (run_command, download_android_commandlinetools, download_android_ndk, install_android_packages) # Note: Does not work with PyEnv. Your Host Python should contain openssl. +# also update the version in ShibokenHelpers.cmake if Python version changes. PYTHON_VERSION = "3.11" SKIP_UPDATE_HELP = ("skip the updation of SDK packages build-tools, platform-tools to" |
