Interop C++/Swift with CMake?

I'm trying to create a hybrid project that bridges both C++ and Swift.

I'm currently using Objective C++ for that - but would like to transition most/all of the Objective C++ code to Swift if possible.

I've cloned the official Apple Swift-CMake example repo:

However, the interop example, that's similar to what I'm trying to accomplish, only compiles using the Ninja generator, and doesn't compile using the Xcode generator.

Has anyone managed to create a working CMake project with C++/Swift interop that works with all generators?

1 Like

Swift support is only possible with the Ninja generator currently. There is some Xcode generator support but that is relatively old compared to the Ninja support and is not as flexible AFAIK.

Thank you for your answer!

  1. Do you know where I can find an example for that old Xcode generator support?

  2. What is missing for the official implementation to work? Is it something that CMake needs to add on their backend that currently isn't implemented for Xcode, or just some scripting that can be achieved with CMake but no one has done it yet?

Sorry, I don’t, I’ve not really used the Xcode backend.

There is quite a bit missing. It is something which would need to be done in CMake itself in the C++ portion. I’m sure that the patches for those would be likely welcome (I don’t mind help reviewing them if needed), but given that I’m not using the Xcode generator, it is not something that I’ve looked into.