How to Use CCache with CMake?

前端 未结 8 731
陌清茗
陌清茗 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: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...

提交回复
热议问题