How to create the new target in Xcode for app extension using CMake?

≯℡__Kan透↙ 提交于 2019-12-20 02:43:26

问题


I want to use Notification Content Extension in my Xcode project. I use CMake to generate my project. Now the project has only one target.

I can add the extension as new target manually in Xcode using menu File - New - Target - Notification Content Extension.

Could you provide an example how to create new Xcode project with additional target for app extension by using CMake?


回答1:


Since CMake 3.8, you could use XCODE_PRODUCT_TYPE target property to let CMake generate specific type of application.

Minimal example that should troubleshoot you:

# add app bundle
add_executable(MyApp MACOSX_BUNDLE ${APP_SOURCE_FILES})

# add app extension bundle
add_library(MyAppExtension MODULE ${APPEX_SOURCE_FILES})
set_target_properties(MyAppExtension PROPERTIES
    BUNDLE YES
    XCODE_PRODUCT_TYPE com.apple.product-type.app-extension)

# link extension bundle with UserNotifications frameworks
find_library(UN_LIB UserNotifications)
find_library(UNUI_LIB UserNotificationsUI)
target_link_libraries(MyAppExtension PRIVATE ${UN_LIB} ${UNUI_LIB})


来源:https://stackoverflow.com/questions/40805431/how-to-create-the-new-target-in-xcode-for-app-extension-using-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!