I'm trying to build a Swift Package Manager system package (a module.modulemap) making available two system C libraries where one includes the other.
That is, one (say libcurl) is a base module and the other C library is including
that (like so: #include "libcurl.h"
). On the regular C side this works, because
the makefiles pass in proper -I
flags and all is good (and I could presumably
do the same in SPM, but I'd like to avoid extra flags to SPM).
So what I came up with is this module map:
module CBase [system] {
header "/usr/include/curl.h"
link "curl"
export *
}
module CMyLib [system] {
use CBase
header "/usr/include/mylib.h"
link "mylib"
export *
}
I got importing CBase
in a Swift package working fine.
But when I try to import CMyLib
, the compiler complains:
error: 'curl.h' file not found
Which is kinda understandable because the compiler doesn't know where to look
(though I assumed that use CBase
would help).
Is there a way to get this to work w/o having to add -Xcc -I
flags to the
build process?
Update 1: To a degree this is covered in
Swift SR-145
and
SE-0063: SwiftPM System Module Search Paths.
The recommendation is to use the Package.swift pkgConfig
setting. This seems to work OK for my specific setup. However, it is a chicken and egg if there is no .pc
file. I tried embedding an own .pc
file in the package, but the system package directory isn't added to the PKG_CONFIG_PATH
(and hence won't be considered during the compilation of a dependent module). So the question stands: how to accomplish that in an environment where there libs are installed, but w/o a .pc
file (just header and lib).