30

How do I figure out what my absolute ${PROJECT_DIR} path is for my Xcode project? Is there a way to print this in Terminal? How?

adit
  • 32,574
  • 72
  • 229
  • 373
  • I am also interested that question. Did you find any solution? I need it to create a git hook. So I don't want to run the script while building in xcode. I use a ruby script. – Mert Aug 10 '12 at 09:28

3 Answers3

37

Build Settings -> Preprocess Macros

PROJECT_DIR=@\""$PROJECT_DIR"\"

BUILD_ROOT=@\""$(BUILD_ROOT)"\"

Then you can log it directly

NSLog(@"project dir=%@, BUILD_ROOT_=%@", PROJECT_DIR, BUILD_ROOT);
vk.edward.li
  • 1,899
  • 16
  • 22
30

Run this from Terminal

For a project:

xcodebuild -project yourProject.xcodeproj -target yourTarget -showBuildSettings | grep PROJECT_DIR

For a workspace:

xcodebuild -workspace yourWorkspace.xcworkspace -scheme yourScheme -showBuildSettings | grep PROJECT_DIR

As you can see, you can retrieve any other build settings value

DeltaCap019
  • 6,532
  • 3
  • 48
  • 70
Xavi Gil
  • 11,460
  • 4
  • 56
  • 71
0

Another interesting method is using a Run Script Phase in Build phases:

enter image description here

Then paste this script that will modify a swift file in your project

fileContent="// DO NOT EDIT,
// THIS IS AUTOMATICALLY GENERATED FILE

//  params.swift
//

import Foundation
class Params {
    static let srcRoot: String = \"${PROJECT_DIR}\"
}"
echo "${SRCROOT}/YourProjectFolderName/params.swift"
echo "$fileContent" > ${SRCROOT}/YourProjectFolderName/params.swift`

Make sure you added Params.swift in you project.

Kamen Dobrev
  • 1,321
  • 15
  • 20