Library/Framework linking inconsistent between swift CLI and XCode Project


(Spencer Kohan) #1

I'm trying to build a swift package which contains a C language target
linked against a system module. I would like to be able to compile it from
the swift CLI, and also via XCode (using `swift package
generate-xcodeproj`), but no matter how I try to include the headers from
the system module, it will either compile successfully from the command
line, or in XCode, but not both.

I've created a github repo to demonstrate the issue:

https://github.com/spencerkohan/Swift-FrameworkLinkingTestCase

This depends on the system module defined here:

https://github.com/spencerkohan/Swift-Cbullet (requires `brew install
bullet`)

This version, when built from the command line using `swift build` compiles
successfully, but when run from the project generated by `swift pacakge
generate-xcodeproj` I get the error: "file not found" on this include:

#include <BulletDynamics/btBulletDynamicsCommon.h>

in the cpp file:
https://github.com/spencerkohan/Swift-FrameworkLinkingTestCase/blob/master/Sources/Ctarget/Ctarget.cpp

It's a bit perplexing, because the linker flags from the pkgConfig for that
framework are present in the "other linker flags" section of the build
settings, namely `-lBulletDynamics`, and presumably this is the same flag
which allows clang to find this header during `swift build` as run from the
command line.

I am able to get this include to work as written by adding
"/Library/Frameworks" (the BulletDynamics install location)to the
"Framework Search Paths" section of the build settings in XCode, but it is
highly undesirable to have to do this every time I generate the XCode
project.

Is there something I'm missing?

Cheers,
Spencer