怎样用ccache加速cocos2d-x android版本号的编译

下面步骤在MAC下測试通过:

首先是安装CCache, 

能够用homebrew

brew install --HEAD ccache

也能够用源代码安装

git clone https://github.com/jrosdahl/ccache.git

cd ccache

./autogen.sh

./configure

make

make install

假设提示autoheader找不到,要先装个automake

brew install automake

当然,假设提示brew找不到,要先装一个homebrew

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"


CCache装好以后,须要配置一下环境变量:

vim ~/.bash_profile

加上例如以下配置:

export USE_CCACHE=1
export CCACHE_DIR=/Developer/ccache
export NDK_CCACHE=/usr/local/bin/ccache

保存退出

然后在bash下执行:

source ~/.bash_profile

让设置生效。

然后再执行:

ccache -F 10G
这个命令是设置编译文件缓存的大小,假设硬盘够大,能够设50G。

最后找到NDK文件夹,编辑$NDK_ROOT/build/core/default-build-commands.mk文件:

#
# IMPORTANT: The following definitions must use lazy assignment because
# the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by
# the toolchain's setup.mk script.
#

ifneq ($(findstring ccc-analyzer,$(CC)),)
TARGET_CC       = $(CC)
else
TARGET_CC       = ccache $(TOOLCHAIN_PREFIX)gcc
endif
TARGET_CFLAGS   =
TARGET_CONLYFLAGS =

ifneq ($(findstring c++-analyzer,$(CXX)),)
TARGET_CXX      = $(CXX)
else
TARGET_CXX      = ccache $(TOOLCHAIN_PREFIX)g++
endif
TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti

在如上所看到的位置加上ccache

配置完成


測试一下效果:

切到coco2d-x根文件夹,执行:

python build/android-build.py -p 10 cpp-tests

然后再开一个bash窗体,执行

ccache -s

这个命令是用来查看ccache的统计数据的

第一次编译是建立缓存。在我的mbp i7 SSD下大概要7分钟,会比没有加速慢一些

假设出现编译错误:

ccache找不到

须要检查一下ccache是否安装正确,能够在命令行上输入ccache -V測试一下。假设有没有输出版本号信息,就表明ccache没有成功安装。假设命令行里測试通过,但编译时仍提示ccache找不到,有可能是path设置不正确。能够用绝对路径试试。


用git clean -xdf 把编译结果清掉(请注意:此命令慎用,会一并删除全部没有增加git管理的文件)

再编译一次,就无比快了,不到半分钟

用ccache -s 查看下数据:

cocos2dxs-Mac-mini:core cocos2dx$ ccache -s
cache directory                     /Developer/ccache
primary config                      /Developer/ccache/ccache.conf
secondary config      (readonly)    /usr/local/etc/ccache.conf
cache hit (direct)                  8328
cache hit (preprocessed)               1
cache miss                          2609
called for link                       31
multiple source files              10939
compile failed                         1
couldn't find the compiler             3
files in cache                      6618
cache size                           1.6 GB
max cache size                       5.0 GB
假设cache hit/cache size/files in cache都是0。说明ccache没有生效。


UPDATE: 这个办法对其它NDKproject也适用




原文地址:https://www.cnblogs.com/yxysuanfa/p/6917262.html