Caching with CPM.cmake and ccache on GitHub Actions (original) (raw)

Caching with GitHub Actions

You can use CPM_SOURCE_CACHE on GitHub Actions workflows cache and combine it with ccache, to make your CI faster.

CPM.cmake

You need to set a path on actions/cache to CPM and use the same path on CPM_SOURCE_CACHE. Here we are using ~/cpm-cache:

ccache

To implement ccache to your workflow:

You need to define some environment variable to tell where ccache will put .ccache and additional informations:

env: CCACHE_VERSION: 4.6 CCACHE_BASEDIR: ${GITHUB_WORKSPACE} CCACHE_DIR: ${GITHUB_WORKSPACE}/.ccache CCACHE_COMPRESS: true CCACHE_COMPRESSLEVEL: 6 CCACHE_MAXSIZE: 400M

You need to install it:

Enable ccache support:

Finally when running your CMake your either need to add:

-D CMAKE_C_COMPILER_LAUNCHER=ccache
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache

or you can have a look at CCache.cmake.

More information on how to set up your CMake to use ccache here. The author also created a complete example : cristianadam/HelloWorld

Add a custom footer