4

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?

2 Answers 2

3

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

I tested on cmake3.23 on mac, app extension is a executable not library. It should be like this:

add_executable(MyAppExtension MACOSX_BUNDLE ${APPEX_SOURCE_FILES})
set_target_properties(MyAppExtension PROPERTIES
    XCODE_PRODUCT_TYPE com.apple.product-type.app-extension)

Then you can embed app extension to app :

set_target_properties(MyApp PROPERTIES
        XCODE_EMBED_APP_EXTENSIONS MyAppExtension)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.