How to use CCache to accelerate cocos2d-x Android version compilation

Source: Internet
Author: User

The following steps are tested under Mac by:

The first is to install CCache,

can be used homebrew

Brew Install--head CCache

can also be installed with the source code

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

CD CCache

./autogen.sh

./configure

Make

Make install

If the hint Autoheader can not find, to first install a automake

Brew Install Automake

Of course, if the hint brew can not be found, first install a homebrew

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


After the CCache is installed, you need to configure the environment variables:

Vim ~/.bash_profile

Add the following configuration:

Export Use_ccache=1export Ccache_dir=/developer/ccacheexport Ndk_ccache=/usr/local/bin/ccache

Save exit

Then run under bash:

SOURCE ~/.bash_profile

Let the settings take effect.

And then run:

Ccache-f 10G
This command is set to the size of the compiled file cache and can be set to 50G if the hard disk is large enough.

finally find the NDK directory and edit the $ndk_root/build/core/default-build-commands.mk file:

# # Important:the Following definitions must use lazy assignment because# the value of Toolchain_prefix or Target_cflags C An is changed later by# the Toolchain ' s setup.mk script. #ifneq ($ (findstring ccc-analyzer,$ (cc)),) target_cc       = $ (cc) El SETARGET_CC       = CCache $ (toolchain_prefix) gccendiftarget_cflags   =target_conlyflags =ifneq ($ (findstring c++- analyzer,$ (CXX)), Target_cxx      = $ (CXX) Elsetarget_cxx      = CCache $ (toolchain_prefix) G++endiftarget_cxxflags = $ (target_cflags)-fno-exceptions-fno-rtti

Add CCache to the position shown above

Configuration complete


Test the effect:

Cut to the Coco2d-x root directory and run:

Python build/android-build.py-p Ten Cpp-tests

Then open a bash window and run

Ccache-s

This command is used to view the statistics of the CCache

The first compilation is to build the cache, which is about 7 minutes under my MBP i7 SSD, which is slower than no acceleration

If a compilation error occurs:

CCache can't find them.

Need to check whether the CCache is installed correctly, you can enter the CCACHE-V test on the command line, if there is no output version information, it indicates that the CCache is not successful, if the command line test passed, but the compile still prompts CCache not found, it is possible that the path is not set, You can try it with an absolute path.


Use Git clean-xdf to clear the results of the compilation (note: This command is used with caution and will delete all files that have not been added to git management)

Compile it again, it's fast, less than half a minute.

Use Ccache-s to view the following data:

Cocos2dxs-mac-mini:core cocos2dx$ ccache-scache directory                     /developer/ccacheprimary config                      /developer/ Ccache/ccache.confsecondary config      (readonly)    /usr/local/etc/ccache.confcache hit (direct)                  8328cache Hit (preprocessed)               1cache Miss                          2609called for link                       31multiple source files              10939compile failed                         1couldn ' t find the compiler             3files in cache                      6618cache size                           1.6 Gbmax Cache size                       5.0 GB
if the cache Hit/cache Size/files in cache are all 0, the CCache does not take effect.


UPDATE: This method is also applicable to other NDK projects




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.