CMake: Don't hardcode Xcode SDK frameworks into public dependencies

Using find_library() to find an Xcode framework will end up embedding
the absolute path of the framework into INTERFACE_LINK_LIBRARIES.
A different machine might not have the SDK installed in the same
location, which will cause build failures. This happens in our CI
because Xcode is installed to /Applications/Xcode11.app.

To fix this, replace all system framework paths with
'-framework Foo' flags instead.
We already do this for OpenGL and OpenGL ES.

In the future we might want to convert these into full standalone
FindFoo scripts that expose proper targets.

Fixes: QTBUG-86299
Task-number: QTBUG-86422
Task-number: QTBUG-85240
Change-Id: I22b2b2d1d9e92108098d3974105e3758978cd8e2
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alexandru Croitor 2020-09-07 16:44:45 +02:00
parent 7a2f129748
commit 948f2a9cac

View File

@ -1,33 +1,52 @@
macro(qt_find_apple_system_frameworks) macro(qt_find_apple_system_frameworks)
if(APPLE) if(APPLE)
find_library(FWAppKit AppKit) qt_internal_find_apple_system_framework(FWAppKit AppKit)
find_library(FWAssetsLibrary AssetsLibrary) qt_internal_find_apple_system_framework(FWAssetsLibrary AssetsLibrary)
find_library(FWAudioToolbox AudioToolbox) qt_internal_find_apple_system_framework(FWAudioToolbox AudioToolbox)
find_library(FWApplicationServices ApplicationServices) qt_internal_find_apple_system_framework(FWApplicationServices ApplicationServices)
find_library(FWCarbon Carbon) qt_internal_find_apple_system_framework(FWCarbon Carbon)
find_library(FWCoreFoundation CoreFoundation) qt_internal_find_apple_system_framework(FWCoreFoundation CoreFoundation)
find_library(FWCoreServices CoreServices) qt_internal_find_apple_system_framework(FWCoreServices CoreServices)
find_library(FWCoreGraphics CoreGraphics) qt_internal_find_apple_system_framework(FWCoreGraphics CoreGraphics)
find_library(FWCoreText CoreText) qt_internal_find_apple_system_framework(FWCoreText CoreText)
find_library(FWCoreVideo CoreVideo) qt_internal_find_apple_system_framework(FWCoreVideo CoreVideo)
find_library(FWcups cups) qt_internal_find_apple_system_framework(FWDiskArbitration DiskArbitration)
find_library(FWDiskArbitration DiskArbitration) qt_internal_find_apple_system_framework(FWFoundation Foundation)
find_library(FWFoundation Foundation) qt_internal_find_apple_system_framework(FWIOBluetooth IOBluetooth)
find_library(FWIOBluetooth IOBluetooth) qt_internal_find_apple_system_framework(FWIOKit IOKit)
find_library(FWIOKit IOKit) qt_internal_find_apple_system_framework(FWIOSurface IOSurface)
find_library(FWIOSurface IOSurface) qt_internal_find_apple_system_framework(FWImageIO ImageIO)
find_library(FWImageIO ImageIO) qt_internal_find_apple_system_framework(FWMetal Metal)
find_library(FWMetal Metal) qt_internal_find_apple_system_framework(FWMobileCoreServices MobileCoreServices)
find_library(FWMobileCoreServices MobileCoreServices) qt_internal_find_apple_system_framework(FWQuartzCore QuartzCore)
find_library(FWQuartzCore QuartzCore) qt_internal_find_apple_system_framework(FWSecurity Security)
find_library(FWSecurity Security) qt_internal_find_apple_system_framework(FWSystemConfiguration SystemConfiguration)
find_library(FWSystemConfiguration SystemConfiguration) qt_internal_find_apple_system_framework(FWUIKit UIKit)
find_library(FWUIKit UIKit)
find_library(FWWatchKit WatchKit) qt_internal_find_apple_system_framework(FWWatchKit WatchKit)
find_library(FWGameController GameController) qt_internal_find_apple_system_framework(FWGameController GameController)
endif() endif()
endmacro() endmacro()
# Given framework_name == 'IOKit', sets non-cache variable 'FWIOKit' to '-framework IOKit' in
# the calling directory scope if the framework is found, or 'IOKit-NOTFOUND'.
function(qt_internal_find_apple_system_framework out_var framework_name)
# To avoid creating many FindFoo.cmake files for each apple system framework, populate each
# FWFoo variable with '-framework Foo' instead of an absolute path to the framework. This makes
# the generated CMake target files relocatable, so that Xcode SDK absolute paths are not
# hardcoded, like with Xcode11.app on the CI.
# We might revisit this later.
set(cache_var_name "${out_var}Internal")
find_library(${cache_var_name} "${framework_name}")
if(${cache_var_name} AND ${cache_var_name} MATCHES ".framework$")
set(${out_var} "-framework ${framework_name}" PARENT_SCOPE)
else()
set(${out_var} "${out_var}-NOTFOUND" PARENT_SCOPE)
endif()
endfunction()
# Copy header files to QtXYZ.framework/Versions/6/Headers/ # Copy header files to QtXYZ.framework/Versions/6/Headers/
# Use this function for header files that # Use this function for header files that
# - are not added as source files to the target # - are not added as source files to the target