Skip to content

Xcode: Add XCODE_EMBED_FRAMEWORKS target property

Gusts Kaksis requested to merge gusc/cmake:xcode-embed-frameworks into master

This merge request tries to address #18073 (closed) by taking the initial work of @palmerc in !2089 (closed) and updating it a bit.

This allows embedding frameworks (and libraries) through a set of special target properties:

  • XCODE_EMBED_FRAMEWORKS - list of absolute paths to frameworks or libraries, or target names that produce frameworks or libraries
  • XCODE_EMBED_FRAMEWORKS_PATH - specify sub directory name where to place frameworks passed in XCODE_EMBED_FRAMEWORKS
  • XCODE_EMBED_FRAMEWORKS_REMOVE_HEADERS_ON_COPY - boolean flag whether to strip headers from embedded frameworks
  • XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY - boolean flag whether to code sign embedded frameworks

Currently this allows embedding frameworks using this syntax:

cmake_minimum_required(VERSION 3.20)

project(MyAppleApp)

add_library(MyLib SHARED lib.m)
set_target_properties(MyLib PROPERTIES FRAMEWORK TRUE)

add_executable(${PROJECT_NAME} MACOSX_BUNDLE main.m)
target_link_libraries(${PROJECT_NAME} PUBLIC MyLib)

set_property(TARGET ${PROJECT_NAME} PROPERTY XCODE_EMBED_FRAMEWORKS 
    "/path/to/AKnown.framework"
    MyLib)
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_EMBED_FRAMEWORKS_PATH "my_subdir")
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_EMBED_FRAMEWORKS_REMOVE_HEADERS_ON_COPY ON)
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON)
Edited by Gusts Kaksis

Merge request reports