From a0468331761b497992e9d554c210583781308272 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 30 Jun 2020 16:11:29 +0200 Subject: [PATCH] CMake: Enable bitcode when targeting UIKIT aka iOS Building an iOS app with qmake failed because Qt itself was not built with bitcode enabled. Enable building with bitcode. Make sure qrc resource files and bundled 3rd party libraries also build with the regular Qt module flags and thus with bitcode enabled. As a consequence gc_sections has to be disabled for UIKIT platforms. Task-number: QTBUG-82581 Task-number: QTBUG-84781 Task-number: QTBUG-85240 Change-Id: I15fe668725a139c02f2a32a5db849b46d4ce325c Reviewed-by: Joerg Bornemann Reviewed-by: Qt CI Bot --- cmake/QtBuild.cmake | 10 +++++++--- cmake/QtInternalTargets.cmake | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index ec4a156d541..f0adaf93797 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1667,7 +1667,7 @@ function(qt_internal_apply_gc_binaries target visibility) message(FATAL_ERROR "Visibitily setting must be one of PRIVATE, INTERFACE or PUBLIC.") endif() - if ((GCC OR CLANG) AND NOT EMSCRIPTEN) + if ((GCC OR CLANG) AND NOT EMSCRIPTEN AND NOT UIKIT) if(APPLE) set(gc_sections_flag "-Wl,-dead_strip") elseif(SOLARIS) @@ -1680,7 +1680,7 @@ function(qt_internal_apply_gc_binaries target visibility) target_link_options("${target}" ${visibility} "${gc_sections_flag}") endif() - if((GCC OR CLANG OR ICC) AND NOT EMSCRIPTEN) + if((GCC OR CLANG OR ICC) AND NOT EMSCRIPTEN AND NOT UIKIT) set(split_sections_flags "-ffunction-sections" "-fdata-sections") endif() if(split_sections_flags) @@ -3835,6 +3835,10 @@ function(qt_add_resource target resourceName) set(rcc_object_file_path $>) endif() set_property(TARGET ${target} APPEND PROPERTY QT_RCC_OBJECTS "${rcc_object_file_path}") + + # Make sure that the target cpp files are compiled with the regular Qt internal compile + # flags, needed for building iOS apps with qmake where bitcode is involved. + target_link_libraries("${out_target}" PRIVATE Qt::PlatformModuleInternal) endforeach() endif() @@ -4520,7 +4524,7 @@ function(qt_add_3rdparty_library target) DEFINES ${arg_DEFINES} PUBLIC_LIBRARIES ${arg_PUBLIC_LIBRARIES} - LIBRARIES ${arg_LIBRARIES} + LIBRARIES ${arg_LIBRARIES} Qt::PlatformModuleInternal COMPILE_OPTIONS ${arg_COMPILE_OPTIONS} PUBLIC_COMPILE_OPTIONS ${arg_PUBLIC_COMPILE_OPTIONS} LINK_OPTIONS ${arg_LINK_OPTIONS} diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index 9fca5d41de3..6eb4bd96f9b 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -108,6 +108,21 @@ endif() target_compile_definitions(PlatformCommonInternal INTERFACE $<$>:QT_NO_DEBUG>) +function(qt_internal_apply_bitcode_flags target) + # See mkspecs/features/uikit/bitcode.prf + set(release_flags "-fembed-bitcode") + set(debug_flags "-fembed-bitcode-marker") + + set(is_release_genex "$>") + set(flags_genex "$") + set(is_enabled_genex "$>>") + + set(bitcode_flags "$<${is_enabled_genex}:${flags_genex}>") + + target_link_options("${target}" INTERFACE ${bitcode_flags}) + target_compile_options("${target}" INTERFACE ${bitcode_flags}) +endfunction() + if(UIKIT) # Do what mkspecs/features/uikit/default_pre.prf does, aka enable sse2 for # simulator_and_device_builds. @@ -118,6 +133,7 @@ if(UIKIT) # TODO: Figure out if this ok or not (sounds ok to me). target_compile_definitions(PlatformCommonInternal INTERFACE QT_COMPILER_SUPPORTS_SSE2) endif() + qt_internal_apply_bitcode_flags(PlatformCommonInternal) endif() # Taken from mkspecs/common/msvc-version.conf and mkspecs/common/msvc-desktop.conf