Unknown argument: '-cxx-interoperability-mode=default'

I am creating an Xcode project using xcode generator in Cmake. The project has a library which contains cpp files and swift files. I m trying to test swift-cpp interoperability that is introduced in xcode15 to perform direct cpp calls from swift and vice-versa. For this to work, we need to set a xcode build setting 'C++ and Objective-C Interoperability' which I m doing via cmake, Below is my cmake file:

cmake_minimum_required(VERSION 3.18)

project(CxxInterop LANGUAGES CXX Swift)


add_executable(CxxInterop ./Sources/CxxInterop/main.swift

#include the directory with modulemap file and Student.hpp

target_include_directories(CxxInterop PUBLIC

#setting the xcode C++ and Objective-C Interoperability setting 

target_compile_options(CxxInterop PRIVATE

when building the generated xcode project I get the error unknown argument: '-cxx-interoperability-mode=default'.

However the weird thing is when I separate out the cpp code in a different library and swift files in a different one, then this works and I m able to invoke the cpp methods in my swift file after importing the clang module from the module map file.

Is there any reason to why having cpp and swift files in same library producing this error? I m following this link to setup the project via cmake.

That's because you're passing this flag as an option for both the Swift file and the C++ file in your target. You need to only pass this flag to the Swift files. You can do that by using a cmake expression to set a flag only for a particular language, e.g.:

target_compile_options(TARGET PUBLIC

You can reference the Swift cmake examples for more details: https://github.com/apple/swift-cmake-examples/blob/main/3_bidirectional_cxx_interop/lib/fibonacci/CMakeLists.txt .