How to Use CCache with CMake?

前端 未结 8 730
陌清茗
陌清茗 2020-12-02 09:32

I would like to do the following: If CCache is present in PATH, use \"ccache g++\" for compilation, else use g++. I tried writing a small my-cmake script containing

相关标签:
8条回答
  • 2020-12-02 10:18

    I personally have /usr/lib/ccache in my $PATH. This directory contains loads of symlinks for every possible name the compiler could be called from (like gcc and gcc-4.3), all pointing to ccache.

    And I didn't even create the symlinks. That directory comes pre-filled when I install ccache on Debian.

    0 讨论(0)
  • 2020-12-02 10:20

    I didn't like to set a symlink from g++ to ccache. And CXX="ccache g++" didn't work for me as some cmake test case wanted to have just the compiler program without attributes.

    So I used a small bash script instead:

    #!/bin/bash
    ccache g++ "$@"
    

    and saved it as an executable in /usr/bin/ccache-g++.

    Then C configured cmake to use /usr/bin/ccache-g++ as C++ compiler. This way it passes the cmake test cases and I feel more comfortable than having symlinks that I might forget about in 2 or 3 weeks and then maybe wonder if something doesn't work...

    0 讨论(0)
提交回复
热议问题