How to change output directory for a target
XcodeXcode4Xcode Problem Overview
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!
Xcode Solutions
Solution 1 - Xcode
-
Go to File -> Project Settings.
-
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.
-
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.
Solution 2 - Xcode
Updated instructions for Xcode 5 up to 6.3.
- Go to
File
->Project settings
- Click the
Advanced
button - Click
Done
, thenDone
once more.
And you are done!
Solution 3 - Xcode
Here's a solution you can check into source control, and which I've verified works with Xcode 6.2.
- Add a .xcconfig file to your project - see this SO question for details.
- 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
Solution 4 - Xcode
According to @gp-coder, the scenario will be following for xcode 9.* Follow the step as given in the picture
And Do Done
Thats all, Thanks
Solution 5 - Xcode
Another way to do this is to edit Build Locations > Per-configuration Build Products Path in your target's Build Settings.
Solution 6 - Xcode
If you want to change build path of your project you can change using following steps.
-
Choose Xcode > Preferences, and click Locations.
-
Click the Advanced button for the Derived Data setting.
-
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
Solution 7 - Xcode
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'