summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2022-01-25 08:44:55 +0100
committerMichal Klocek <michal.klocek@qt.io>2022-02-04 18:28:07 +0100
commit8998563677e3f308083ba1c4c28efd6fe3d850f7 (patch)
tree45514dad6dea3db885b758824b9d3571a8ef3eb6 /cmake
parent8e549e6e0ccd6078b3bd2e38b87337fd367dec55 (diff)
downloadqtwebengine-8998563677e3f308083ba1c4c28efd6fe3d850f7.tar.gz
Add QtPdf iOS builds
QtPDf iOS builds must support fat libs builds. Compared to 5.15 however this is done differently. Before we tweaked gn to compile multi arch with 'Xarch' parameter. This had few downsides as we could not determine which arch/cpu compiles given file as compilation was opaque to gn. The current approach is to follow mac universal builds, compile builds separately for each architecture and lipo the outcome. However, this introduces some issues as ios builds are static builds and creating lipo archive will gather object files, which should end up in final QtPdf lib instead. Therefore create multi arch object file instead of archive and use this one. Note the compiler now uses arch triple for Pdfium as Chromium does, however qt files still use 'arch' and '*-version-min' combination. Task-number: QTBUG-88614 Pick-to: 6.3 6.2 Change-Id: I7775c8b4d1554df497eb61fa6187f12c00b9032d Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Functions.cmake127
1 files changed, 109 insertions, 18 deletions
diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake
index 7d3dd493c..ab151c329 100644
--- a/cmake/Functions.cmake
+++ b/cmake/Functions.cmake
@@ -345,6 +345,14 @@ function(get_darwin_sdk_version result)
endif()
endfunction()
+function(get_ios_target_triple_and_sysroot result arch)
+ get_ios_sysroot(sysroot ${arch})
+ set(${result}
+ -target ${arch}-apple-ios${CMAKE_OSX_DEPLOYMENT_TARGET}
+ -isysroot ${sysroot} PARENT_SCOPE
+ )
+endfunction()
+
function(add_ninja_target target cmakeTarget ninjaTarget config arch buildDir)
string(TOUPPER ${config} cfg)
add_custom_target(${target} DEPENDS ${buildDir}/${config}/${arch}/${ninjaTarget}.stamp)
@@ -464,36 +472,86 @@ function(add_rsp_command target buildDir completeStatic)
)
endfunction()
-function(add_lipo_command target buildDir)
+function(add_ios_rsp_command target buildDir completeStatic)
get_target_property(config ${target} CONFIG)
+ get_target_property(arch ${target} ARCH)
+ get_target_property(ninjaTarget ${target} NINJA_TARGET)
get_target_property(cmakeTarget ${target} CMAKE_TARGET)
- set(libs_rsp "${buildDir}/x86_64/${ninjaTarget}_libs.rsp")
- # Lipo the object files together to a single fat archive
- add_library(${cmakeTarget}_${config} STATIC IMPORTED GLOBAL)
+ string(TOUPPER ${config} cfg)
+ get_ios_target_triple_and_sysroot(args ${arch})
+ set(objects_rsp "${buildDir}/${ninjaTarget}_objects.rsp")
+ set(objects_out "${buildDir}/${cmakeTarget}_objects.o")
add_custom_command(
- OUTPUT ${buildDir}/lib${cmakeTarget}.a
- COMMAND lipo -create
- -output ${buildDir}/lib${cmakeTarget}.a
- ARGS
- ${buildDir}/arm64/${cmakeTarget}.a
- ${buildDir}/x86_64/${cmakeTarget}.a
+ OUTPUT ${objects_out}
+ COMMAND clang++ -r -nostdlib
+ ${args}
+ -o ${objects_out}
+ -Wl,-keep_private_externs
+ @${objects_rsp}
DEPENDS
- ${buildDir}/arm64/${cmakeTarget}.a
- ${buildDir}/x86_64/${cmakeTarget}.a
+ ${buildDir}/${ninjaTarget}.stamp
+ WORKING_DIRECTORY "${buildDir}/../../.."
+ COMMENT "Creating intermediate object files for ${cmakeTarget}/${config}/${arch}"
USES_TERMINAL
VERBATIM
+ COMMAND_EXPAND_LISTS
)
+endfunction()
+
+# Lipo the object files together to a single fat archive
+function(create_lipo_command target buildDir fileName)
+ get_target_property(config ${target} CONFIG)
+ get_architectures(archs)
+ foreach(arch ${archs})
+ list(APPEND lipo_objects ${buildDir}/${arch}/${fileName})
+ endforeach()
+ add_custom_command(
+ OUTPUT ${buildDir}/${fileName}
+ COMMAND lipo -create
+ -output ${buildDir}/${fileName}
+ ARGS ${lipo_objects}
+ DEPENDS ${lipo_objects}
+ USES_TERMINAL
+ COMMENT "Running lipo for ${target}/${config}/${arch}"
+ VERBATIM
+ )
+endfunction()
+
+# this function only deals with objects as it is only
+# used by qtpdf and we do not need anything more
+function(add_ios_lipo_command target buildDir)
+ get_target_property(config ${target} CONFIG)
+ get_target_property(cmakeTarget ${target} CMAKE_TARGET)
+ set(fileName ${cmakeTarget}_objects.o)
+ create_lipo_command(${target} ${buildDir} ${fileName})
+ add_custom_target(lipo_${cmakeTarget}_${config} DEPENDS
+ ${buildDir}/${fileName}
+ )
+ add_dependencies(${cmakeTarget} lipo_${cmakeTarget}_${config})
+ qt_internal_get_target_property(options ${cmakeTarget} STATIC_LIBRARY_OPTIONS)
+ set_target_properties(${cmakeTarget} PROPERTIES STATIC_LIBRARY_OPTIONS
+ "${options}$<$<CONFIG:${config}>:${buildDir}/${fileName}>"
+ )
+endfunction()
+
+function(add_lipo_command target buildDir)
+ get_target_property(config ${target} CONFIG)
+ get_target_property(cmakeTarget ${target} CMAKE_TARGET)
+ set(fileName ${cmakeTarget}.a)
+ create_lipo_command(${target} ${buildDir} ${fileName})
+ add_library(${cmakeTarget}_${config} STATIC IMPORTED GLOBAL)
set_property(TARGET ${cmakeTarget}_${config}
- PROPERTY IMPORTED_LOCATION ${buildDir}/lib${cmakeTarget}.a
+ PROPERTY IMPORTED_LOCATION ${buildDir}/${fileName}
)
add_custom_target(lipo_${cmakeTarget}_${config} DEPENDS
- ${buildDir}/lib${cmakeTarget}.a
+ ${buildDir}/${fileName}
)
add_dependencies(${cmakeTarget}_${config} lipo_${cmakeTarget}_${config})
target_link_libraries(${cmakeTarget} PRIVATE ${cmakeTarget}_${config})
# Just link with dynamic libs once
# TODO: this is evil hack, since cmake has no idea about libs
+ set(libs_rsp "${buildDir}/x86_64/${ninjaTarget}_libs.rsp")
target_link_options(${cmakeTarget} PRIVATE "$<$<CONFIG:${config}>:@${libs_rsp}>")
endfunction()
@@ -580,6 +638,19 @@ function(get_gn_is_clang result)
endif()
endfunction()
+function(get_ios_sysroot result arch)
+ if(NOT CMAKE_APPLE_ARCH_SYSROOTS)
+ message(FATAL_ERROR "CMAKE_APPLE_ARCH_SYSROOTS not set.")
+ endif()
+ get_architectures(archs)
+ list(FIND archs ${arch} known_arch)
+ if (known_arch EQUAL "-1")
+ message(FATAL_ERROR "Unknown iOS architecture ${arch}.")
+ endif()
+ list(GET CMAKE_APPLE_ARCH_SYSROOTS ${known_arch} sysroot)
+ set(${result} ${sysroot} PARENT_SCOPE)
+endfunction()
+
function(configure_gn_toolchain name binTargetCpu v8TargetCpu toolchainIn toolchainOut)
set(GN_TOOLCHAIN ${name})
get_gn_os(GN_OS)
@@ -727,7 +798,8 @@ macro(append_build_type_setup)
CONDITION FEATURE_developer_build
)
- if(NOT QT_FEATURE_webengine_full_debug_info)
+ #TODO: refactor to not check for IOS here
+ if(NOT QT_FEATURE_webengine_full_debug_info AND NOT IOS)
list(APPEND gnArgArg blink_symbol_level=0 remove_v8base_debug_symbols=true)
endif()
@@ -779,6 +851,14 @@ macro(append_compiler_linker_sdk_setup)
mac_sdk_min="${macSdkVersion}"
)
endif()
+ if(IOS)
+ list(APPEND gnArgArg
+ use_system_xcode=true
+ enable_ios_bitcode=true
+ ios_deployment_target="${CMAKE_OSX_DEPLOYMENT_TARGET}"
+ ios_enable_code_signing=false
+ )
+ endif()
else()
if(QT_FEATURE_use_lld_linker)
get_filename_component(clangBasePath ${CMAKE_LINKER} DIRECTORY)
@@ -887,6 +967,10 @@ macro(append_toolchain_setup)
else()
get_gn_arch(cpu ${arch})
list(APPEND gnArgArg target_cpu="${cpu}")
+ if(IOS)
+ get_ios_sysroot(sysroot ${arch})
+ list(APPEND gnArgArg target_sysroot="${sysroot}" target_os="ios")
+ endif()
endif()
endmacro()
@@ -932,10 +1016,10 @@ function(get_configs result)
endfunction()
function(get_architectures result)
- if(NOT QT_IS_MACOS_UNIVERSAL)
- set(${result} ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
- else()
+ if(QT_IS_MACOS_UNIVERSAL OR IOS)
set(${result} ${CMAKE_OSX_ARCHITECTURES} PARENT_SCOPE)
+ else()
+ set(${result} ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
endif()
endfunction()
@@ -967,6 +1051,8 @@ function(add_gn_build_aritfacts_to_target cmakeTarget ninjaTarget module buildDi
)
if(QT_IS_MACOS_UNIVERSAL)
add_rsp_command(${target} ${buildDir}/${config}/${arch} ${completeStatic})
+ elseif(IOS)
+ add_ios_rsp_command(${target} ${buildDir}/${config}/${arch} ${completeStatic})
else()
extend_cmake_target(${target} ${buildDir}/${config}/${arch} ${completeStatic})
endif()
@@ -976,6 +1062,11 @@ function(add_gn_build_aritfacts_to_target cmakeTarget ninjaTarget module buildDi
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()
endfunction()