Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in
read-only mode
.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I'd like to try out
ccache
to speed up building. I use Qt Creator on Windows with cmake/ninja and MSVC 2022.
I've tried a few ways to make it work, and also looked for some information online, but without much luck:
First, I added ccache at the beginning of my path
Using CMAKE_CXX_COMPILER_LAUNCHER calls ccache, but results in a "ninja: fatal: ReadFile: The handle is invalid."
Renaming ccache to cl (and having it first in the path) seems to be ignored. I suspect that Qt Creator's kit knows exactly where to find cl.exe, and doesn't even try to search via path
Creating a custom compiler kit proved to be difficult, as I cannot simply clone the MSVC compiler of my choice and change the compiler path - since there is no compiler path I can actually edit
Any suggestions?
I use
ccache
with Qt Creator for building Qt Creator itself, and it works as expected.
CMAKE_C_COMPILER_LAUNCHER
and
CMAKE_CXX_COMPILER_LAUNCHER
is the correct way of using ccache.
Note that you need to use
/Z7
compiler option for
Debug
and
RelWithDebInfo
build types.
See
https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/cmake/QtCreatorAPIInternal.cmake#n123
how Qt Creator is configuring
ccache
.
Which versions of
ccache
and
ninja
are you using?
Thank you for your quick reply!
I use cmake 3.23.2 and ninja 1.11.0
I have now set both CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER to "ccache" and prepended ccache's path to the PATH environment variable.
Would that be the correct setup?
ccache is called, but seems to return with
CreateProcess failed: The system cannot find the file specified.
The actual "cl.exe" called as it's first parameter exists at the given path, and seems to be the correct one. The compiler options given look fine on first glance.
Will only /Z7 compiler option work with ccache? Because I use /Zi, which according to MS docs should be equivalent.
@cristian-adam
Yes, I use current version (4.8.2).
I see that /Zi is not (yet) supported by ccache. I guess that means I will not be able to use it on Windows for my main project.
In any case, I tried with plain release mode, but got the same error:
CreateProcess failed: The system cannot find the file specified.
When I take the offending command ("ccache <PATH_TO_CL.EXE> <FLAGS_AND_FILENAMES>") and run it on a command line (prepared with the correct PATH env), it succeeds and generates the expected .obj file. So my issue seems to be with my Creator environment.
When I open a terminal from my build environment (in Creator), "which ccache" finds the correct one, so this looks good...but doesn't seem to work.
I tried specifying the full path instead of just "ccache" in CMAKE_CXX_COMPILER_LAUNCHER, but then the setting seems to be ignored.
You'll have to pass the --verbose
flag to ninja to see what fails.
In order to find out if Qt Creator the culprit is, try a build from command line.
Then always re-try with a clean build.
@cristian-adam
Passing --verbose unfortunately does not add any useful information to the output. I get the command string and the error message - nothing else. But then, I'm not sure the "--verbose" that I pass via Creator's "Tool arguments" actually arrive at ninja - where would I find the output that includes the ninja commands?
I created a minimal example (default console application without anything else). It fails in Qt Creator with the same error.
On the command line, it succeeds.
The trick seems to be that the path to ccache needs to be prepended in the project environment. It's not sufficient to add it to the build environment.