2

I am trying to build an Xcode 9 project with cmake (3.8.0). It consists of an app target and an appex (extension) target, which needs to be copied into the app's PlugIns directory via a "Copy Files Phase" (or "Embed App Extension Phase") in the Build Phases.

I tried several attempts like calling set_source_files_properties(${myFile} PROPERTIES MACOSX_PACKAGE_LOCATION PlugIns) but with no luck so far.

I believe the difficulty (for cmake) is that the acutal file "myExtension.appex" is created at build time and therefor hardcoding the path to add it as a source file doesn't seem to work.

Any help would be appreciated!

jfjs
  • 103
  • 6

2 Answers2

1

We just managed to solve this in a bit of a weird way (And in case you have solved the problem, let this be a solution for anyone else - like me - trying to figure it out)

When you embed an appex in a project, Xcode basically changes two things in the project: adds the appex as a dependency of the project and adds a PBXCopyFilesBuildPhase to make sure that the compiled .appex ends up in the PlugIns folder of the resulting package.

So we mimicked those two steps. Adding the dependency to the appex is easy:

add_dependencies("${_PROJECT_NAME}" ${APP_EXTENSION_TARGET})

In our case, ${EXTENSION} is actually a list with all the extensions we have, so you know that can work, too. That will make sure that the extensions are built before the main app. Now, to make sure that they are put in the right place, we added a custom POST_BUILD command in the app CMakeLists.txt, like so:

add_custom_command(TARGET "${target}" POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory "${PATH_TO_APPEX}" "$<TARGET_FILE_DIR:${target}>/PlugIns/${APPEX_FILE_BASENAME}" MAIN_DEPENDENCY "${APPEX_NAME}")

There is some helper code around all this but that's the gist of it.

Hope that helps!

pkamb
  • 33,281
  • 23
  • 160
  • 191
0

You may use $(CONFIGURATION_BUILD_DIR)/$(CONTENTS_FOLDER_PATH) rather than $<TARGET_FILE_DIR:${target}> in case of Archive build.