How do I instruct XCODE to find headers in a DERIVED_FILES_DIR of a subproject

1.7k Views Asked by At

I have a static library project that builds .h and .m files and places them into ${DERIVED_FILES_DIR}. This works fine. However, I can't figure out how to reference them when the library project is added as a sub-project.

When I add this project as a sub-project it builds and output is placed into the parent project path at Build/Intermediates/SubProj.build/Debug-iphonesimulator/SubProj.build/DerivedSources.

How can I tell xcode to use these Intermediates in the containing project?

Alternatively, how can I modify the subproject to copy these to the Products Directory where perhaps they will get picked up by the parent project?

2

There are 2 best solutions below

3
On

I solved this by adding a Run Script build phase in the library project that copies the derived files using this script:

cp -a ${DERIVED_FILES_DIR}/*.h ${BUILT_PRODUCTS_DIR}

Then, when adding this library to another project I add a User Header Search Path under Build Settings as

${BUILT_PRODUCTS_DIR}

Be sure to select recursive.

0
On

DERIVED_FILES_DIR is for files that are automatically generated during a build and should be used by that very same build. Files placed in that location should either match a "Build Rule" in Xcode, in which case Xcode will build them automatically according to this rule (e.g. generated .c files are automatically built by Xcode and linked to your current target binary) or they serve as input for another script phase.

If your target is a static library to be used by another target (same project or other project doesn't matter), then the static library and its headers are your actually build products of your current build and thus should both go into BUILT_PRODUCTS_DIR where Xcode will find them if other targets reference them.