Swift/C++ interop.

I’m trying to use the relatively-new interop feature of Swift and C++.

Apple provides this example repo:

But their interop example only compiles using the Ninja generator, and fails with the Xcode generator.

Is there any example/resource on doing something like that in a way that works with Xcode as well?

The README for that repo explicitly says the following:

These projects build with the Ninja generator (e.g cmake -G 'Ninja' ... ) and likely do not work with the other generators.

You may need to open an issue in that repo to ask the authors of that repo to find out why. Evan Wilde is active in the CMake issue tracker for Swift-related things, but he doesn’t appear to have an account here in the CMake forums.

1 Like

Hey @craig.scott!

First of all I love your book, it’s been extremely helpful when I just got into CMake, so thank you!

I will open an issue with Apple’s repo now, but I don’t mind so much if Apple’s repo works or not.

I’m just looking for a way to get it to work myself. I wonder if that’s a CMake limitation, or a scripting issue that can be solved on the user’s side (mine)?

I definitely don’t mind passing special flags only to get the Xcode generator, if I could find some docs/examples to show what they are.

When I made vanilla repos myself, and passed similar compile options to the one Apple uses:

      -module-name "${ARG_MODULE_NAME}"
      -cxx-interoperability-mode=default
      -emit-clang-header-path ${header_path}

I got similar results (works with Ninja, fails with Xcode).

The Apple repository was forked from my original work - the only supported generator is the Ninja generator. The Xcode generator support for Swift is older and does not support all the features that Evan and I have worked on for Ninja. Neither one of us is actively working on the Xcode generator and if someone is interested in use of the new features in the Xcode generator, they would need to update the implementation for that.

2 Likes