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?
Asked
Active
Viewed 3.2k times
30
Paresh Mangukiya
- 37,512
- 17
- 201
- 182
adit
- 30,916
- 67
- 221
- 365
-
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 Answers
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,849
- 16
- 22
28
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,436
- 2
- 46
- 69
Xavi Gil
- 11,102
- 4
- 53
- 69
0
Another interesting method is using a Run Script Phase in Build phases:
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,302
- 14
- 19