As mentioned in other topics, I'm currently designing a Swift wrapper for a C++ library (which already provides a C wrapper). I've been able to set up the whole thing and it compiles and runs but I have to rely on multiple
unsafeFlags which make distribution impossible.
Some background: the C++ library depends on Boost, which can be installed via Homebrew so declaring a
.systemLibrary target came to mind. However, Boost does not provide a
.pc file so pkg-config is out of the picture (note: I've actually used a tool to produce one "automatically" and Xcode was able to find the headers, but I cannot ask package users to install a
.pc file). So last option seems to be a modulemap, but this is completely out of my depth (and even with
#include <boost/config.hpp> in a shim.h header did not work).
I've therefore resorted the following: since headers and libs are in
/usr/local/opt/boost, symlinked to
/usr/local/lib, I've set
cxxSettings: [.unsafeFlags("-I", "/usr/local/include")] on both the C++ and the C target (because the C target is actually C++ with
extern "C"). Without those flags, Xcode is unable to find the Boost headers.
To my surprise though, while tinkering with
swift build, the latter compiles the whole package even when I remove the
unsafeFlags! Based on some research with
swift build includes
/usr/local/include in its default header search paths, whereas Xcode's invocation doesn't.
My question is: why doesn't Xcode look at the same header search paths as
Follow-up: what's the best solution? Why does a
.systemTarget with an (admittedly bad) modulemap not find the headers for Boost? but