Setup Cpp-Swift Interoperability using CMake

I have been using the Cpp-Swift Interoperability in Xcode15 for direct communication between Cpp and Swift code. It required a few Build settings changes for the Swift Compiler, creating clang modules(module map file) to access cpp code in swift, specifying module map path to the swift compiler etc.

I wanted to use this interoperability feature in my visual studio project which is using Cmake. I want to build via cmake, using Xcode generator.

Prior to Swift5.9, we were using a ObjC bridging header whose support was provided in the Cmake using the Xcode attribute flag 'XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER'. Similarly we were specifying the generated header using the attribute 'XCODE_ATTRIBUTE_SWIFT_OBJC_INTERFACE_HEADER_NAME'

I m not able to find similar Xcode attribute property flags for my Cmake to enable this interoperability. Some attributes that are requires for this new interoperability are:

  1. to set the C++ and Objective-C Interoperability in the Swift Compiler - Language
  2. to set the import paths in the Swift Compiler - Search Paths : to have access to the module map file
  3. to set the Generated Header Name in the Swift Compiler - General.
    What are the changes that we need to make in the Cmake(using Xcode generator) for this new interoperability to work. Can someone help with this?

You can enable Swift/C++ interoperability by using a Swift compiler flag -cxx-interoperability-mode=default. This works regardless of which build system you are using.

You can either pass -I {your include search path} as an argument to the Swift compiler, or use CMake's target_include_directories feature for your Swift target.

This is an example of a CMakeLists file that we use to build Swift code that uses Swift/C++ interoperability using CMake: