The installation

Terminal command: brew install ccacheCopy the code

Creating a script file

Ccache -clang++ file (c++); if else (c++); if else (c++)

Touch ccache-clang open /User/ XXX (your MAC User name)/ccache-clang /bin/sh export PATH=$PATH:/usr/local/bin export CCACHE_MAXSIZE=10G export CCACHE_CPP2=true export CCACHE_HARDLINK=true Export CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,file_stat_matches Export CCACHE_LOGFILE=~/Desktop/CCache. Log exec CCache /usr/bin/clang "$@" export CCACHE_LOGFILE=~/Desktop/CCache.Copy the code

Xcode configuration

  • Add the + sign next to the Build Settings search box, select Add User-defined Setting, type CC, and Add the path of ccache-clang to the right, such as $(SRCROOT)/ccache-clang in the project root directory
  • Build Settings search Enable Modules change to NO, and then compile

To solve the error

“_kUTTypeImage”, referenced from, “_kUTTagClassMIMEType”, referenced from:, etc

Add MobileCoreServices to Build Phases Link Binary With Libraries

“_NSSQLiteStoreType”, referenced from: SQLite,”OBJC_CLASS$_NSManagedObjectModel”, referenced from:

Add CoreData library

OBJC_CLASS$_CADisplayLink”, referenced from

Add the QuartzCore library

CGRect UIImageView,OBJC_CLASS$_UIResponder “, referenced from:, etc

Add CoreGraphics library

The problem of Cocoapods

If CCache is required by Cocoapods, Enable Modules need to be set to NO. However, libraries in Cocoapods rely on multiple system libraries. If the Enable Modules are disabled, the associated system Libraries will need to be added manually to Link Binary With Libraries

post_install do |installer_representation| installer_representation.pods_project.targets.each do |target| Target. Build_configurations. Each do | config | # close Enable Modules config. Build_settings [' CLANG_ENABLE_MODULES] = 'NO' Config. Build_settings ['CC'] = '$(PODS_ROOT)/ccache-clang' end end endCopy the code

speed

Because the current project has a large number of Cocoapods libraries and system libraries that need to be added, I didn’t change them for the moment to see the effect. Therefore, the speed of improvement without closing Cocoapods Enable Modules is as follows: Build speed increase 100s -> 58s Archive Speed increase 142s -> 73s

conclusion

The code of our project is not too much, not too big, so the speed is not too slow. After optimization, the compilation and packaging speed has been improved by 50%. For other old projects, I believe the improvement is even more. In addition, my device is a MAC of 2015. If there is a gap in hardware, better hardware will speed up.