编译目录使用xcodebuild联编

问题描述:

xcodebuild手册页上写着:编译目录使用xcodebuild联编

Run xcodebuild from the directory containing your project (i.e. the directory containing the projectname.xcodeproj package).

我想保持我的源目录(这是一个颠覆外部)清洁和修改,并建立我的对象文件和可执行文件到位置完全在源目录之外。

有什么办法打造成为使用xcodebuild一样可以用make工具在Windows上做甚至msbuild终端的编译目录?

您可以从命令行设置构建设置。 CONFIGURATION_BUILD_DIR将设置构建目录。例如:

xcodebuild -project YourProject.xcodeproj -configuration Debug -target All ARCHS=x86_64 ONLY_ACTIVE_ARCH=YES CONFIGURATION_BUILD_DIR=../some/other/dir 

的引用苹果公司的网站上发现:

+4

我发现我还需要设置CONFIGURATION_TEMP_DIR,然后这为我工作。 – 2013-02-09 21:40:06

+2

你可以设置BUILD_DIR,也可以工作:D – 2016-02-08 18:25:36

为了实现完全分离以下构建设置必须改变(不仅仅是CONFIGURATION_BUILD_DIR喜欢接受答案建议),否则Xcode仍然在其默认构建文件夹下构建它的一些工件。

在我的机器上,Xcode通常会将所有东西构建到./Build./DerivedData,其中当前目录是我的项目之一。

我想xcodebuild联编建Build-command-line文件夹下的一切,所以我用xcodebuild -scheme MyScheme -showBuildSettings | grep Build\/找到所有建立对应于所有的构建路径设置,并通过试端错误,我发现“生成性”构建足以重定向所有设置将由xcodebuild生成的文物建立到自定义文件夹。

我结束了使用下面的命令:

BUILD_DIR=./Build-command-line 
DERIVED_DATA_DIR=$(BUILD_DIR)/DerivedData 

xcodebuild -project MyProject.xcodeproj \ 
     -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=`sysctl -n hw.ncpu` \ 
     -scheme MyScheme \ 
     -sdk iphonesimulator \ 
     -destination 'platform=iOS Simulator,name=iPhone 6S Plus,OS=latest' \ 
     -xcconfig command-line-build.xcconfig \ 
     -derivedDataPath $(DERIVED_DATA_DIR) \ 
     test 

其中command-line-build.xcconfig是:

HERE_BUILD=$(SRCROOT)/Build-command-line 
HERE_INTERMEDIATES=$(HERE_BUILD)/Intermediates 

// Paths 
// the following paths are enough to redirect everything to $HERE_BUILD 
MODULE_CACHE_DIR = $(HERE_BUILD)/DerivedData/ModuleCache 
OBJROOT    = $(HERE_INTERMEDIATES) 
SHARED_PRECOMPS_DIR = $(HERE_INTERMEDIATES)/PrecompiledHeaders 
SYMROOT 

注:确保您在xcconfig使用绝对路径,否则,你可能有错误: Xcode crashing on startup “parentPath must be nil but it is not

我已经写了一篇关于这个解决方案的文章,内容有点背景:xcodebuild: how to really change its build path

P.S.当然这些信息可能会有所变化,但是从Xcode Version 7.3.1 (7D1014)开始它对我来说是完美的。

在我的项目中,设置SYMROOT证明足以在不同位置构建项目,而不会触及其他位置。

从Apple的Xcode Build Setting Reference(我在这里遇到另一个答案,谢谢!):

SYMROOT (Build Products Path)

Description: Directory path. Identifies the root of the directory hierarchy that contains product files and intermediate build files. Product and build files are placed in subdirectories of this directory.

...

Affects: BUILT_PRODUCTS_DIR, CONFIGURATION_BUILD_DIR (...)

此设置也是在xcodebuild man页面几次提到:

Available actions are:

build: Build the target in the build root (SYMROOT)...

clean: Remove build products and intermediate files from the build root (SYMROOT)....

应设置SYMROOT构建设置到所需位置。所有其他相关的构建设置都源自它。