1

In XCode 11.7, when I add a Copy Files build phase, it only allows me to select files, not directories, and while I can select files from within sub-directories, they all get mashed together into the top-level.

I can work around it by adding multiple Copy Files phases with a different subpath so that the structure ends up correct, but this is tedious and feels wrong.

Is there a better way to make the output directory structure of Copy Files match the input?

Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59

1 Answers1

0

I figured out how to do it - instead of a Copy Files phase, I added a Run Script phase and used the cp -R command.

In my case, I wanted to copy a TargetApp/www folder to the "Wrapper" (root of the app), so my full script is:

echo "copying $SRCROOT/TargetApp/www to $TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH"
cp -R "$SRCROOT/TargetApp/www" "$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH"
Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59
  • 2
    This actually is the wrong answer. The correct procedure is to use a _folder reference_. When you do that, the entire folder is what is copied, lock stock and barrel, including the entire folder-and-file hierarchy that it contains, intact. I provide fairly detailed instructions here: https://stackoverflow.com/a/48758433/341994 – matt Oct 01 '20 at 21:04
  • 1
    I wasn't able to use a folder reference to copy headers from a static library since it contained C files but Run Script did the trick. – Raphaël Mar 15 '21 at 15:42