17

I'm trying to create a framework in Xcode and have successfully done so, but as it turns out, Xcode flattens the directory structure of when copying headers in the Copy Headers build phase. I've tried adding the files as Folder References instead of the groups, but then it won't even recognize the header-files as header files!

So, how can I tell Xcode to keep the directory structure when copying the header files to my .framework-bundle?

JMax
  • 26,109
  • 12
  • 69
  • 88
Erik Rothoff
  • 4,826
  • 9
  • 41
  • 59

5 Answers5

14

Use Copy Files instead of Copy Headers in the Build Phases UI.

Create a separate Copy Files (Editor -> Add Build Phase) for each output folder needed.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
  • 9
    Great, this works! But the answer needs more details. I found that *Destination* needs to be set to *Wrapper* and *Subpath* must be (or begin with) `Headers` if you want the header files to be copied into the framework's public headers folder or a subfolder thereof. – CodeSmile May 27 '15 at 12:53
5

If you cannot use a folder reference because the folders contain non-header-files, too, which you don't want to copy, add a Run Script build phase instead:

cd "${SRCROOT}/path/from/project/root/to/headers"

echo 'Copying headers into Framework..'
for H in `find . -name "*.h"`;  do
    echo "copying ${H} to ${BUILT_PRODUCTS_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/${H}"
    ditto "${H}" "${BUILT_PRODUCTS_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/${H}"
done

That will copy all .h files from the path you cd'd to into YourFramework.framework/Versions/A/Headers just like marking them as public would.

ctietze
  • 2,805
  • 25
  • 46
  • Thank you. This worked for me. I have .hpp file too also so I modified my the script like this `find . -name "*.h" -o -name "*.hpp"`. – Steve Ham Jan 23 '22 at 02:47
1

It seems that this is not currently a built in feature of xcode, so you must revert to scripts to copy files recursively (presumably selecting only header files): How can I preserve subgroups when changing role to public in Copy Headers build phase in XCode?

Here's a discussion about how to accomplish just that: http://www.cocoabuilder.com/archive/xcode/259185-copy-headers-that-preserves-subdirectory-structure.html

Community
  • 1
  • 1
kevlar
  • 1,110
  • 3
  • 17
  • 30
1

Add source folder as reference to folder (radio button in the "Add files..." dialog). Then drag'n'drop those folders from Navigator tab to "Build Phases->Copy Files". After this headers will be located in folders on next build.

user2041064
  • 131
  • 7
0

From this question's accepted answer:

Right click on Resources, add existing files, choose your directory and select "Create Folder References for any added folders".

Community
  • 1
  • 1
Juguang
  • 621
  • 2
  • 5
  • 15