From ba74eaba11b2df9d6c2b23f7595e7bb1a03e911e Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Wed, 20 Apr 2022 08:48:02 +0200 Subject: Support cross-compilation on macOS So far we only supported a cross-compiling with universal builds, however qmake also supports 'regular' cross compilation (by setting '-device-option'). This is semi-supported with qt-cmake as we need to provide additional configure defines like: * CMAKE_OSX_ARCHITECTURES=arm64 * CMAKE_SYSTEM_NAME=Darwin * CMAKE_OSX_DEPLOYMENT_TARGET=10.14 It might seem to be a far fetched issue, however in case of webengine doing the cross compilation for only one architecture allows to save compile times when testing only arm64 builds. Note we do not need to create gn toolchains for that case, however unlike universal builds it requires host qt build for tools. Pick-to: 6.3 6.2 Change-Id: Ica8470fdd4cad4866c1470e0403ffd019eaf39a6 Reviewed-by: Alexandru Croitor --- cmake/Functions.cmake | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'cmake') diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake index cc6f609f6..44313d8cf 100644 --- a/cmake/Functions.cmake +++ b/cmake/Functions.cmake @@ -1033,18 +1033,26 @@ endfunction() function(get_configs result) if(QT_GENERATOR_IS_MULTI_CONFIG) - set(${result} ${CMAKE_CONFIGURATION_TYPES} PARENT_SCOPE) + set(${result} ${CMAKE_CONFIGURATION_TYPES}) else() - set(${result} ${CMAKE_BUILD_TYPE} PARENT_SCOPE) + set(${result} ${CMAKE_BUILD_TYPE}) + endif() + if(NOT ${result}) + message(FATAL_ERROR "No valid configurations found !") endif() + set(${result} ${${result}} PARENT_SCOPE) endfunction() function(get_architectures result) - if(QT_IS_MACOS_UNIVERSAL OR IOS) - set(${result} ${CMAKE_OSX_ARCHITECTURES} PARENT_SCOPE) + if(CMAKE_OSX_ARCHITECTURES) + set(${result} ${CMAKE_OSX_ARCHITECTURES}) else() - set(${result} ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE) + set(${result} ${CMAKE_SYSTEM_PROCESSOR}) endif() + if(NOT ${result}) + message(FATAL_ERROR "No valid architectures found. In case of cross-compiling make sure you have CMAKE_SYSTEM_PROCESSOR in your toolchain file.") + endif() + set(${result} ${${result}} PARENT_SCOPE) endfunction() function(add_gn_build_aritfacts_to_target cmakeTarget ninjaTarget module buildDir completeStatic) @@ -1053,14 +1061,9 @@ function(add_gn_build_aritfacts_to_target cmakeTarget ninjaTarget module buildDi # the minimum cmake we support get_configs(configs) get_architectures(archs) - if(NOT configs) - message(FATAL_ERROR "No valid configurations found !") - endif() - if(NOT archs) - message(FATAL_ERROR "No valid architectures found. In case of cross-compiling make sure you have CMAKE_SYSTEM_PROCESSOR in your toolchain file.") - endif() foreach(config ${configs}) foreach(arch ${archs}) + set(target ${ninjaTarget}_${config}_${arch}) add_ninja_target(${target} ${cmakeTarget} ${ninjaTarget} ${config} ${arch} ${buildDir}) add_ninja_command( @@ -1080,15 +1083,14 @@ function(add_gn_build_aritfacts_to_target cmakeTarget ninjaTarget module buildDi else() extend_cmake_target(${target} ${buildDir}/${config}/${arch} ${completeStatic}) endif() + unset(target) endforeach() + list(GET archs 0 arch) + set(target ${ninjaTarget}_${config}_${arch}) if(QT_IS_MACOS_UNIVERSAL) - set(arch ${CMAKE_SYSTEM_PROCESSOR}) - set(target ${ninjaTarget}_${config}_${arch}) add_lipo_command(${target} ${buildDir}/${config}) endif() if(IOS) - list(GET archs 0 arch) - set(target ${ninjaTarget}_${config}_${arch}) add_ios_lipo_command(${target} ${buildDir}/${config}) endif() endforeach() -- cgit v1.2.1