I have a C++ project that produces a lot of libraries that require C++20.
I have tried to set the requirement for that in the module.modulemap like so (for example):
module cxx_library {
requires cplusplus20
header "library.h"
link "CXXLibrary"
}
This seems to be correct per the clang documentation: https://clang.llvm.org/docs/Modules.html#requires-declaration
However I cannot figure out how to get cmd+click on the imported module in my sample swift file to work with this. For one, Xcode seems to refuse to even import my module when it requires C++20.
How do I tell Xcode that all of my C++/ObjectiveC++ requires C++20? The compiler default is C++14, but it's not clear how to properly change that so that I can import a C++20-enabled clang module into some sample swift projects to try out the new interior features.
If I remove the 20 from my requires statement, and just use my code as-is, It always complains in the UI that:
Couldn't Generate Swift Representation
Error (from SourceKit): "Could not load module: cxx_library (could not build Objective-C module 'cxx_library', unknown type name 'char8_t')"
Which is very frustrating. When I compile with CMake, I can just set this:
add_executable(E
E.swift)
target_compile_options(E PRIVATE
-cxx-interoperability-mode=default
SHELL:-Xcc SHELL:-std=c++20)
target_link_libraries(E PRIVATE
cxx_library)
And swiftc compiles the code with no issue.
I have uploaded a minimized version of my code as a fork of a project by compnerd on GitHub here: https://github.com/ADKaster/swift-cmake-examples/tree/main/Interop
The project builds just fine with
cmake -S Interop -B build -GNinja
cmake --build build
But by creating an Xcode project from it:
cmake -S Interop -B build-xcode -GXcode
and then opening build-xcode/P.xcodeproj in Xcode 15 Beta, and trying to cmd-click on import cxx_library
in E.swift does not work.