Unable to link & embed iOS framework with CMake 3.20
Problem report based on CMake 3.20.3 (latest).
It's really great to see that CMake 3.20 finally support embedding of Xcode "frameworks" when targeting macOS & iOS. However, the new
XCODE_EMBED_FRAMEWORKS properties seem quite sparsely documented, and I've so far been unable to find any sample code online to help me get started. I've therefore created a sample project on https://github.com/forderud/QtCmakeIOS where I've unsuccessfully tried to get framework embedding to work for iOS.
Extract from CMakeLists.txt:
# create MyLib shared lib add_library(MyLib SHARED MyLib.cpp MyLib.h ) # configure MyLib as "framework" on iOS set_target_properties(MyLib PROPERTIES FRAMEWORK TRUE MACOSX_FRAMEWORK_IDENTIFIER com.mycompany.MyLib ) add_executable(AnalogClock MACOSX_BUNDLE main.cpp rasterwindow.cpp rasterwindow.h ) target_link_libraries(AnalogClock PRIVATE MyLib Qt5::Widgets ) set_target_properties(AnalogClock PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER AnalogClock2 # must be unique XCODE_LINK_BUILD_PHASE_MODE BUILT_ONLY XCODE_EMBED_FRAMEWORKS MyLib XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON )
It seems to me like XCODE_LINK_BUILD_PHASE_MODE and XCODE_EMBED_FRAMEWORKS will trigger "Link Binary With Libraries" and "Embed Frameworks" in the Xcode project. However, application startup still fail with
dyld: Library not loaded: @rpath/MyLib.framework/MyLib Referenced from: /private/var/containers/Bundle/Application/CAD1EF2E-BA61-4B55-A3CA-27B05729C13D/helloworld.app/helloworld Reason: image not found
Is this due to incorrect CMake project configuration or have I encountered a bug in CMake?