I have a package (https://github.com/dowobeha/Foma) that wraps a C library (https://github.com/mhulden/foma/tree/master/foma). On my machines, this C library was installed by hand (using ./configure, make, make install) rather than through apt or brew. As such, there is no corresponding .pc file. The C library lives in /usr/local/lib.
In order to get my Foma package to compile, I started off writing a Makefile that passed -Xlinker -L/usr/local/lib to swift build. That worked.
But when I tried opening my package in XCode, XCode didn't know where to find the C library. So, in Package.swift, I modified the .target with linkerSettings: [LinkerSetting.unsafeFlags(["-Xlinker", "-L/usr/local/lib"])]),. That worked. Now my Foma project compiles cleanly in XCode.
But I need to have my Foma package serve as a dependency for another package of mine. In my other project, I added the dependency as .package(url: "https://github.com/dowobeha/Foma.git", from: "0.0.7"),.
This causes XCode to complain that "the target 'Foma' in product 'Foma' contains unsafe build flags." That is true. I searched online and found documentation (https://github.com/apple/swift-evolution/blob/master/proposals/0238-package-manager-build-settings.md) explaining this behavior by XCode.
I understand what is going on. But I'm stuck. To summarize:
- I have a Swift package (Foma) that wraps a C library that lives in /usr/local/lib that was not installed through a package manager
- I need to tell SPM how to find the C library
- I need other Swift packages to depend on my Foma package
- The only way I have found to resolve point 1 and 2 (using LinkerSetting.unsafeFlags) prevents me from doing point 3
What is "the right way" to resolve this situation?