CCache is a compiler the cache for C + +. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation was being Done again. We can use the This tool to the speed up cocos2d-x Android compilation.
The following instructions is tested on MAC:
Installation:
can use homebrew:
Brew install--head CCache
Or Install by Source:
git clone https://github.com/jrosdahl/ccache.git
CD CCache
./autogen.sh
./configure
Make
Make install
If bash prompts it can not find Autoheader, you need install Automake:
Brew Install Automake
But, if Bash complains it can not find brew, you need install one:
ruby-e "$ (curl-fssl https://raw.github.com/Homebrew/homebrew/go/install)"
Make sure CCache can is found in your $PATH, Run command:
ccache
If you can not see the help message, check your installation.
Configuration
To use CCache, you need setup some environment variables:
Vim ~/.bash_profile
Add following lines:
export use_ccache=1
Export Ndk_ccache=/usr/local/bin/ccache
Then run command:
Ccache-m 10G
This command would set max cache size to 10G, If your Mac has a large hard disk, you can set the cache size to 50G.
Then, find your NDK path, if you forget where you put it, try the following command:
which ndk-build
The result on my MBP:
/developer/android/android-ndk-r9b/ndk-build
So my ndk_root is:
/developer/android/android-ndk-r9b
Open file: $NDK _root/build/core/default-build-commands.mk
Find the following Section,add CCache as shown:
# important:the Following definitions must use lazy assignment because
# The value of Toolchain_prefix or target_cflags can is changed later by
# The Toolchain ' s setup.mk script.
#
Ifneq ($ (findstring ccc-analyzer,$ (CC)),)
TARGET_CC = $ (CC)
Else
TARGET_CC = CCache $ (toolchain_prefix) GCC #Add ccache support
endif
Target_cflags =
Target_conlyflags =
Ifneq ($ (findstring c++-analyzer,$ (CXX)),)
Target_cxx = $ (CXX)
Else
Target_cxx = CCache $ (toolchain_prefix) g++ #Add ccache Support
endif
Target_cxxflags = $ (target_cflags)-fno-exceptions-fno-rtti
Build
Switch to Cocos2d-x Root path, run:
python build/android-build.py-p ten cpp-tests
Open Another bash window, run:
Ccache-s
This command would print the CCache statistics,
Cache Directory/users/heliclei/.ccache
Primary config/users/heliclei/.ccache/ccache.conf
Secondary config (readonly)/usr/local/etc/ccache.conf
Cache Hit (direct) 13588
Cache Hit (preprocessed) 11145
Cache Miss 4696
called for link 1
called for preprocessing 14
Preprocessor Error 1
Can ' t use Precompiled header 1629
No input file 5
Files in cache 32222
Cache Size 5.4 GB
Max Cache size 30.0 GB
If both cache Hit & cache size is 0, that's means ccache doesn ' t work, you need check your configuration.