是否可以通过环境变量获取 Xcode 4 中的工作区路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8658836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:50:50  来源:igfitidea点击:

Is it possible to acquire the workspace path in Xcode 4 via an environment variable

xcodexcode4

提问by Brian Lawson

I can't find anything workspace related in the Xcode Build Setting Reference.

我在Xcode Build Setting Reference 中找不到任何与工作区相关的内容。

Essentially I need something like $(WORKSPACE_DIR). If Xcode doesn't provide it, is there any way to define a custom user variable that could somehow accurately provide the workspace path in the event that the working workspace were to move (think branches etc)?

基本上我需要像 $(WORKSPACE_DIR) 这样的东西。如果 Xcode 不提供它,是否有任何方法可以定义一个自定义用户变量,该变量可以在工作工作区移动(想想分支等)的情况下以某种方式准确地提供工作区路径?

采纳答案by Vishal

Custom variables can be defined under build settings. I think there is a button named Add Build Setting. So, a new variable workspace root can be defined relative to the SRCROOT or use absolute path.

自定义变量可以在构建设置下定义。我认为有一个名为 Add Build Setting 的按钮。因此,可以相对于 SRCROOT 或使用绝对路径定义新的变量工作区根。

The new setting is shown under "User Defined" group in build settings. "Add Build Setting" button is near lower right corner.

新设置显示在构建设置中的“用户定义”组下。“添加构建设置”按钮位于右下角附近。

回答by Sogger

If your workspace is set up like:

如果您的工作区设置如下:

//bla/bla/bla/workspace/{project directories}* 

then you can use

然后你可以使用

$(SRCROOT)/../

to get the workspace directory from a give project directory.

从给定的项目目录中获取工作区目录。



For example, if you want to have one project reference headers in another project:

例如,如果您想在另一个项目中有一个项目引用标题:

Project Build Settings->User Header Search Paths => $(SRCROOT)/../SomeLibProj

项目构建设置-> 用户头搜索路径 => $(SRCROOT)/../SomeLibProj

(and set it to 'recursive' if you don't want to add every folder)

(如果您不想添加每个文件夹,请将其设置为“递归”)