CMAKE_CXX_COMPILER_LAUNCHER=ccache usage question

What happens if I set CMAKE_CXX_COMPILER_LAUNCHER=ccache and ccache doesn’t exist?

Will CMake error out? Or will CMake just ignore CMAKE_CXX_COMPILER_LAUNCHER?

Configure and generate will succeed, but the build tool will fail with “no such file or directory” when it tries to run ccache itself. I’ve run into this multiple times when running CI scripts that set up sccache but I don’t inside of containers (as the cache isn’t going to do much once the container disappears).

1 Like

I generally protect set(CMAKE_CXX_COMPILER_LAUNCHER ccache) with a find_program(CCACHE_EXECUTABLE ccache) before it. Depending on the strategy you want to employ, if the find_program() call fails, you’d either issue a fatal error or you’d skip setting CMAKE_CXX_COMPILER_LAUNCHER.

1 Like