Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - How to copy executable to new location after build?

Tags:

xcode

xcode4

I'm building a command line application using Xcode 4.

Once the build is complete the executable is located inside the default DerivedData folder. This is OK, however I'd then like to copy this file to a specific folder. I'd like this to happen regardless of the type of build (release/debug).

Can anyone please suggest a way of doing this?

As an aside, the subdirectory for my project inside DerivedData has a tag of random characters in it:

myProject-fnkwvtitgroivocadokaayqexhqy

Does anyone know if this can change over time (thus changing the location of my executable to be copied), or is it fixed for this project?

like image 663
tarmes Avatar asked Nov 22 '12 09:11

tarmes


2 Answers

There's actually a great way to automate this. Assuming you're in your Xcode project currently, click on the project file and click on the target (since you said that it's a simple command-line program, there should only be one).

Next click on the tab Build Phases and open the triangle for Copy Files.

(If you don't see a triangle with "Copy Files", click on the + symbol to add it.)

Now in the navigator in the Products folder will be the executable that is built. Drag this into the Copy Files build phase.

In the Copy Files little menu click on the drop menu to choose Absolute Path and below that type in the path where you'd like it to be installed. Make sure to check "Copy only when installing" and every time you build the project and it succeeds it will copy the executable to that location.

like image 111
GW.Rodriguez Avatar answered Nov 16 '22 00:11

GW.Rodriguez


In my case, I wanted the newly built app to be copied over existing builds in the Application's folder. In the Build Rules, add a New Run Script Phase to the list. I use /bin/bash, but you can probably use the default /bin/sh too. Then, I added the following code to the script.

cp -f -R ${BUILT_PRODUCTS_DIR}/${APPLICATION_NAME} /Applications
like image 41
Scott Combs Avatar answered Nov 16 '22 00:11

Scott Combs