Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Using ccache with Qt Creator, cmake and MSVC
Forum Updated to NodeBB v4.3 + New Features

Using ccache with Qt Creator, cmake and MSVC

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
8 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by Asperamanca
    #1

    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?

    cristian-adamC 1 Reply Last reply
    0
    • A Asperamanca

      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?

      cristian-adamC Offline
      cristian-adamC Offline
      cristian-adam
      wrote on last edited by
      #2

      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?

      A 1 Reply Last reply
      1
      • cristian-adamC cristian-adam

        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?

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by Asperamanca
        #3

        @cristian-adam
        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-adamC 1 Reply Last reply
        0
        • A Asperamanca

          @cristian-adam
          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-adamC Offline
          cristian-adamC Offline
          cristian-adam
          wrote on last edited by
          #4

          Notice that you didn't answer which ccache version you are using. Is it 4.8.2?

          /Z7 is needed for corect Debug and RelWithDebInfo builds.

          A 1 Reply Last reply
          0
          • cristian-adamC cristian-adam

            Notice that you didn't answer which ccache version you are using. Is it 4.8.2?

            /Z7 is needed for corect Debug and RelWithDebInfo builds.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @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.

            cristian-adamC 1 Reply Last reply
            0
            • A Asperamanca

              @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.

              cristian-adamC Offline
              cristian-adamC Offline
              cristian-adam
              wrote on last edited by
              #6

              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.

              A 1 Reply Last reply
              0
              • cristian-adamC cristian-adam

                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.

                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @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?

                A 1 Reply Last reply
                0
                • A Asperamanca

                  @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?

                  A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  1
                  • A Asperamanca has marked this topic as solved on

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved