XCODE_EMBED_FRAMEWORKS does not support imported framework or xcframework targets
When using the Xcode generator, the XCODE_EMBED_FRAMEWORKS
accepts targets or paths. You can create an imported target for a shared framework, and starting with CMake 3.28, an imported shared library target should be able to represent a XCFramework. One can successfully create such an imported target (framework or xcframework), but it generates an error if you set XCODE_EMBED_FRAMEWORKS
to it. Here's a rough sketch of the problem:
# An XCFramework I've built in a separate project. For this problem, this could be
# either a .framework or a .xcframework.
set(XPLATXCF_LIBRARY /path/to/xplatxcf.xcframework)
# Imported target to represent the XCFramework (should be valid starting with CMake 3.28)
add_library(xplatxcf SHARED IMPORTED GLOBAL)
set_target_properties(xplatxcf PROPERTIES
IMPORTED_LOCATION ${XPLATXCF_LIBRARY}
)
add_executable(XCApp ...)
set_target_properties(XCApp PROPERTIES
... # Many other properties
# Embedding by target fails
XCODE_EMBED_FRAMEWORKS xplatxcf
# Embedding by path works
#XCODE_EMBED_FRAMEWORKS ${XPLATXCF_LIBRARY}
XCODE_LINK_BUILD_PHASE_MODE "KNOWN_LOCATION"
)
target_link_libraries(XCApp PRIVATE xplatxcf)
If you set XCODE_EMBED_FRAMEWORKS
to the xplatxcf
target, CMake fails with the following error:
CMake Error: Can not find a target for xplatxcf
CMake Generate step failed. Build files cannot be regenerated correctly.
Setting it to the actual location of the framework or XCFramework and setting the XCODE_LINK_BUILD_PHASE_MODE
to KNOWN_LOCATION
generates no such error and I have an example iOS project which uses this successfully.
Edited by Craig Scott