I have a large C++ / CMake code base, complete with a C API. I'm looking to wrap this as a pre-built binary xcframework, and delivered via a Swift package.
I have this working, along with a relatively permissive modules.modulemap
file, but only in the case where I have curated the header files carefully to have #include
directives pointing to other headers files in a relative manner.
The example modules.modulemap
file:
framework module COOLKit {
umbrella header "COOLKit.h"
module * { export * }
export *
}
An example of the Headers
folder for this framework looks like the following, called COOLKit
:
├── COOLKit.h
└── cool
├── additions.h
├── cpp.h
├── exported
│ ├── callbacks.h
│ ├── structs.h
│ ├── results.h
│ └── image.h
└── cool.h
Each header file, if referring to another one, does so relatively, so e.g. structs.h
may do the following
#include "../cpp.h"
Ordinarily, though, the original code has all been written in such a way that a common, root include path is specified, and the above should ideally just read
#include "cool/cpp.h"
… but this fails with SwiftPM when it emits the module during build: 'cool/cpp.h' file not found
Specifying paths in terms of the root framework, does work:
#include <COOLKit/cool/cpp.h>
… however I'm keen to avoid this requirement, as changes to includes in the original C++ library would be extensive.
Is there a way forward where I can keep #include
statements as is and work from the root of the Headers
folder within the framework as the search path to work from?