Using CMake to create xpc service in macOS.

Hi, I’d like to create an xpc service from cmake. Basically, a simple XPC service contains the following bundle (compiled a builtin skeleton xpc service from xcode)

Build/Products/Debug/myxpcservice.xpc/
Build/Products/Debug/myxpcservice.xpc/Contents
Build/Products/Debug/myxpcservice.xpc/Contents/_CodeSignature
Build/Products/Debug/myxpcservice.xpc/Contents/_CodeSignature/CodeResources
Build/Products/Debug/myxpcservice.xpc/Contents/MacOS
Build/Products/Debug/myxpcservice.xpc/Contents/MacOS/myxpcservice
Build/Products/Debug/myxpcservice.xpc/Contents/Info.plist

So in order to make a bundle, I’ve used the cmake BUNDLE properties, and set MACOSX_BUNDLE_NAME to myxpcservice.xpc, but when I generated the project and compiled it, I saw that the bundle name is myxpcservice.app and not myxpcservice.xpc.

add_executable(myxpcservice MACOSX_BUNDLE)
set_target_properties(myxpcservice PROPERTIES
  BUNDLE True
  MACOSX_BUNDLE_GUI_IDENTIFIER com.blabla.myxpcservice
  MACOSX_BUNDLE_BUNDLE_NAME myxpcservice.xpc
  MACOSX_BUNDLE_BUNDLE_VERSION "1.0"
  MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0"
  MACOSX_BUNDLE_INFO_PLIST Info.plist.template.in
)

And idea how to resolve this ? are there any example that generate xpc service ?

Thanks !

You can change the bundle suffix using the BUNDLE_EXTENSION property.

Disclamer: I’ve never had to deal with xpc services, so for all I know, just changing the bundle extension might not be sufficient.

Yes, that’s what I needed. thanks.

1 Like