macos 使用 xcodebuild 分离构建目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4969932/
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
Separate build directory using xcodebuild
提问by Dave Mateer
The man page for xcodebuild
reads:
阅读的手册页xcodebuild
:
Run xcodebuild from the directory containing your project (i.e. the directory containing the projectname.xcodeproj package).
从包含项目的目录(即包含 projectname.xcodeproj 包的目录)运行 xcodebuild。
I would like to keep my source directory (which is a Subversion external) clean and unmodified, and build my object files and executables to a location completely outside of the source directory.
我想保持我的源目录(它是一个 Subversion 外部)干净且未经修改,并将我的目标文件和可执行文件构建到完全在源目录之外的位置。
Is there any way to build into a separate build directory from a terminal using xcodebuild
like you can do with make
tools or even msbuild
on Windows?
有什么方法可以xcodebuild
像使用make
工具甚至msbuild
在 Windows 上一样从终端构建到单独的构建目录中吗?
回答by Dave Mateer
You can set build settings from the command line. The CONFIGURATION_BUILD_DIR
will set the build directory. For example:
您可以从命令行设置构建设置。该CONFIGURATION_BUILD_DIR
会设置生成目录。例如:
xcodebuild -project YourProject.xcodeproj -configuration Debug -target All ARCHS=x86_64 ONLY_ACTIVE_ARCH=YES CONFIGURATION_BUILD_DIR=../some/other/dir
A reference is found on Apple's site:
在 Apple 的网站上找到了一个参考:
回答by Stanislav Pankevich
To achieve complete separation the following build settings have to be changed (more than just CONFIGURATION_BUILD_DIR
like accepted answer suggests), otherwise Xcode still builds some of its artifacts under its default build folder.
为了实现完全分离,必须更改以下构建设置(不仅仅是CONFIGURATION_BUILD_DIR
像接受的答案所建议的那样),否则 Xcode 仍会在其默认构建文件夹下构建其一些工件。
On my machine Xcode normally builds everything to ./Build
and ./DerivedData
where current directory is one of my project.
在我的机器的Xcode通常会生成一切./Build
和./DerivedData
地方当前目录是我的项目之一。
I wanted xcodebuild to build everything under Build-command-line
folder so I used xcodebuild -scheme MyScheme -showBuildSettings | grep Build\/
to find all build settings that correspond to all build paths and by trial-end-error I found "the generative" build settings that are enough to redirect all build artefacts produced by xcodebuildto custom folder.
我希望 xcodebuild 在Build-command-line
文件夹下构建所有内容,所以我曾经xcodebuild -scheme MyScheme -showBuildSettings | grep Build\/
找到与所有构建路径相对应的所有构建设置,并且通过试验结束错误我发现“生成性”构建设置足以将xcodebuild 生成的所有构建工件重定向到自定义文件夹。
I ended up using the following command:
我最终使用了以下命令:
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
Where command-line-build.xcconfig
is:
在哪里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
Note:Make sure you use absolute paths in your xcconfig, otherwise you may have error: Xcode crashing on startup “parentPath must be nil but it is not.
注意:确保在 xcconfig 中使用绝对路径,否则可能会出现错误:Xcode 在启动时崩溃“parentPath must be nil but it is not.
I have written a post about this solution with a bit of background: xcodebuild: how to really change its build path.
我写了一篇关于这个解决方案的文章,有一点背景:xcodebuild: how to real change its build path。
P.S. Of course this information is subject to change but as of Xcode Version 7.3.1 (7D1014)
it works perfectly for me.
PS 当然,这些信息可能会发生变化,但Xcode Version 7.3.1 (7D1014)
它对我来说非常有效。
回答by Ashley
In my project, setting SYMROOT
turned out to be sufficient to build the project in a different location, leaving other locations untouched.
在我的项目中,设置SYMROOT
足以在不同的位置构建项目,而其他位置保持不变。
From Apple's Xcode Build Setting Reference(which I came across via another answer here, thanks!):
来自 Apple 的Xcode 构建设置参考(我是通过这里的另一个答案遇到的,谢谢!):
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 (...)
SYMROOT(构建产品路径)
说明:目录路径。标识包含产品文件和中间构建文件的目录层次结构的根。产品和构建文件放置在此目录的子目录中。
...
影响:BUILT_PRODUCTS_DIR、CONFIGURATION_BUILD_DIR (...)
This setting is also mentioned a few times in the xcodebuild
man page:
xcodebuild
手册页中也多次提到此设置:
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)中构建目标...
清洁:从构建根 (SYMROOT) 中删除构建产品和中间文件。...
回答by Guy Daher
Xcode 10
Xcode 10
For a Workspace if you're using CocoaPods:
对于工作区,如果您使用 CocoaPods:
xcodebuild -workspace youProject.xcworkspace -scheme yourScheme -sdk iphonesimulator -configuration Release SYMROOT=$(PWD)/build
That will put your .app in ./build/Release-iphonesimulator
这会将您的 .app 放入 ./build/Release-iphonesimulator
回答by Jeremy Huddleston Sequoia
You should set the SYMROOT
build setting to your desired location. All of the other relevant build settings are derived from it.
您应该将SYMROOT
构建设置设置为您想要的位置。所有其他相关的构建设置都源自它。