66

I am using a workspace where I have a main app project and then a static library project which is used by the main app. I want static library project to spit out libX.a into the main app project directory, because i want to push this libX.a into my Git repo.

The changing of build path settings for static lib project should be pushed to its own git repo so other don't have to deal with this change again and again.

I tried changing 'Build Products Path' to "$(SRCROOT)/../SharedData" for mt static lib target but it doesn't have any effect.

Thanks!

Kuldeep Kapade
  • 1,095
  • 3
  • 12
  • 17

8 Answers8

51
  1. Go to File -> Project Settings.

  2. Click the Advanced button under Derived Data Location. Under build location select custom and choose your output directory. This will change the variable $(BUILD_DIR) to whatever you set in that field.

  3. Click done and go to your target settings. Under Build Location you can now specify where the targets are output based on that $(BUILD_DIR) macro.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Jeff Sternberg
  • 519
  • 3
  • 3
  • 10
    This seems to be an XCode setting, not something you can check in to any cvs. – noobular Jul 25 '13 at 00:47
  • This doesn't seem to work if my project is `A` and I want my executable in `A/release`; I'm only being able to put it under `A/release/Release`. Any clues? – Jorge Leitao May 20 '14 at 08:14
  • Moving a project to xCode 12 had writing manifest issues. Went to Project settings and changed Shared Project Settings to New Build System and in Per-User Project Settings Changed Derived Date to Custom Location and this finally change the build locations to the new default location – Jim Geldermann Nov 23 '20 at 17:49
  • 1
    WARNING: If you clean your project, Xcode will delete everything contained in the destination folder! (Not limited to the Debug or Release folders.) – idbrii Feb 18 '21 at 19:53
  • XCode 12 still has the same problem that those "project settings" are not reflected in the project configuration files and cannot be checked into Git. – Paul Slocum May 13 '22 at 00:39
39

Updated instructions for Xcode 5 up to 6.3.

  1. Go to File -> Project settings
  2. Click the Advanced button
  3. Click Done, then Done once more.

And you are done!

Aaron
  • 358
  • 2
  • 16
gp-coder
  • 1,050
  • 11
  • 14
34

Here's a solution you can check into source control, and which I've verified works with Xcode 6.2.

  1. Add a .xcconfig file to your project - see this SO question for details.
  2. In the .xcconfig file, specify the Xcode standard environment variables PROJECT_TEMP_DIR, CONFIGURATION_BUILD_DIR, and BUILT_PRODUCTS_DIR to point to where you want files to wind up.

Reading Apple's xcconfig format reference, it would seem that simply overriding OBJROOT and SYMROOT in the .xcconfig file would do the trick - but in my testing on Xcode 6.2, changing them has no effect. You have to change those three specific environment variables listed above.

This is what I put in an Xcode 6.2 .xcconfig file so intermediate files and executables go into their "traditional" locations:

// Intermediate build files go here
PROJECT_TEMP_DIR = $(SRCROOT)/build/$(PROJECT_NAME).build

// Build-related files for the active build configuration go here
CONFIGURATION_BUILD_DIR = $(SRCROOT)/build/$CONFIGURATION

// The final product executables and other build products go here
BUILT_PRODUCTS_DIR = $(SRCROOT)/build/$CONFIGURATION

Don't forget to add the xcconfig file to a Deployment Target -> Configurations to make it work (Click on the Project, Under Info, in the Deployment Target Section under Configurations

Gideon Gyabaah
  • 388
  • 2
  • 7
Bob Murphy
  • 5,814
  • 2
  • 32
  • 35
  • 1
    As a side note, I'm confident that [it's a bug in XCode](https://forums.developer.apple.com/message/234817/) where OBJROOT and SYMROOT are evaluated before settings from project files are even considered. – Pavel P Jun 12 '17 at 03:29
  • This causes linking to fail for projects with SPM dependencies for me. Specifying the install location instead works for me, see [my answer](https://stackoverflow.com/a/73593176/3429396). – YourMJK Sep 03 '22 at 14:58
12

According to @gp-coder, the scenario will be following for xcode 9.* Follow the step as given in the picture

enter image description here enter image description hereenter image description here

And Do Done

Thats all, Thanks

Abhishek Mitra
  • 3,335
  • 4
  • 25
  • 46
  • Or you can select Legacy, then specify per target setting by set Build Products Path(in your own target's Build Settings) relative to you project directory. – ideawu Jan 02 '18 at 04:42
  • Thanks a lot! That's what I was looking for. – kodartcha Oct 07 '21 at 15:29
5

Another way to do this is to edit Build Locations > Per-configuration Build Products Path in your target's Build Settings.enter image description here

Julius Naeumann
  • 422
  • 1
  • 10
  • 19
4

If you want to change build path of your project you can change using following steps.

1) Choose Xcode > Preferences, and click Locations.

2) Click the Advanced button for the Derived Data setting.

3) Select a build location from the available options, and click Done.

ex. if you choose 'Custom' from Build Location option your build will be generate at '/Users/XYZ/Desktop/Build/Products' Location

Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81
2

In Xcode 8.x I set the derivedData directory with a command line option in a .sh file that builds the project. Developers can build into their user directories (default Xcode preference), while the official build creates the build in the traditional area:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

xcodebuild -workspace 'my project.xcworkspace' -scheme 'my project' -configuration Release -derivedDataPath '$SCRIPT_DIR/build'

DaveSawyer
  • 351
  • 4
  • 8
0

Most of the answers here that change the build location didn't work for me when building a macOS command line tool with SPM dependencies. Building fails in the linking stage because Xcode is looking for the libraries in the wrong place.
Building on the answer of @Bob Murphy, instead of changing the build location you can specify an install location in the .xcconfig file where the product gets copied to after successful building.

  1. Add a .xcconfig file to your target's "Release" configuration (relevant SO question)
  2. Config file: Add DEPLOYMENT_LOCATION = YES and specify the install location through DSTROOT and INSTALL_PATH.

INSTALL_PATH is relative to DSTROOT, so the product will then be copied to $DSTROOT/$INSTALL_PATH.
Example .xcconfig file:

DEPLOYMENT_LOCATION = YES
INSTALL_PATH = .
DSTROOT = $(SRCROOT)/build/

You might have to add SKIP_INSTALL = NO if it's already specified somewhere else.
Optionally adding DEPLOYMENT_POSTPROCESSING = YES will also reduce the size of the binary by stripping symbols.

Note that theoretically it should be possible to directly specify the directory by overriding TARGET_BUILD_DIR instead of setting both DSTROOT and INSTALL_PATH but that didn't work for me in Xcode 13 for some reason.

YourMJK
  • 1,429
  • 1
  • 11
  • 22