Xcode Build Phases: Headers vs Copy Files
Asked Answered
B

1

7

What's the difference between these Xcode Build Phases: Headers & Copy Files?

When I add a Cocoa Touch Static Library (iOS) to my project, it comes with a Copy Files build phase, whereas when I add a Plain Static Library (macOS), it comes with a Headers build phase.

The source code of the target I'm adding is written entirely in C. And, I want to be able to include this project in my other projects that contain iOS & macOS application targets.

Baseler answered 21/10, 2017 at 16:54 Comment(0)
S
0

The difference between the two is very simple in fact (applicable for static libraries, but not frameworks):

  • Headers Phase copies all Public and Private headers into /usr/local/include folder, so they are available system-wide on macOS when installing the library (while developing, Xcode just creates this folder hierarchy under $(TARGET_BUILD_DIR) for you, so you can inspect the headers as needed).
  • Copy Files offers product-specific destination $(TARGET_BUILD_DIR)/include/$(PRODUCT_NAME), where headers are supposed to be delivered alongside the library binary.

The second approach is more flexible (while you can use the Copy Files phase in both macOS and iOS, using Headers Phase makes sense in macOS only).

P.S. Be advised that for frameworks the Headers Phase works differently and in fact embed the headers with the framework being developed, so in this case it's a more preferred way.

Shotputter answered 26/9, 2022 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.