如何使用CMake在Xcode中为应用程序扩展创建新目标? [英] How to create the new target in Xcode for app extension using CMake?

查看:210
本文介绍了如何使用CMake在Xcode中为应用程序扩展创建新目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Xcode项目中使用Notification Content Extension. 我使用CMake生成我的项目. 现在该项目只有一个目标.

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.

我可以使用菜单文件-新建-目标-Notification内容扩展名,在Xcode中手动将扩展名添加为新目标.

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

您能否提供一个示例,说明如何使用CMake创建带有附加目标扩展应用程序的新Xcode项目?

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

推荐答案

自CMake 3.8起,您可以使用XCODE_PRODUCT_TYPE target属性使CMake生成特定类型的应用程序.

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})

这篇关于如何使用CMake在Xcode中为应用程序扩展创建新目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆