简体   繁体   English

如何在 Windows MSVC 上使用 ccache > 4.6.1 和 cmake?

[英]How to use ccache > 4.6.1 on Windows MSVC with cmake?

As of version 4.6.1 , ccache supports compilation with msvc.4.6.1 版本开始,ccache 支持使用 msvc 进行编译。

On my Windows environment, I have ccache installed and available via the command line.在我的 Windows 环境中,我安装了 ccache 并且可以通过命令行使用。 I try to integrate ccache to my cmake project in the following way:我尝试通过以下方式将 ccache 集成到我的 cmake 项目中:

Root CMakeLists.txt:根 CMakeLists.txt:

find_program(CCACHE_FOUND ccache) 
if(CCACHE_FOUND)
    message("CCACHE is found")
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) # Less useful to do it for linking, see edit2
else(CCACHE_FOUND)
    message("CCACHE is NOT found")
endif(CCACHE_FOUND)

Here is my cmake configuration in CMakePresets.json:这是我在 CMakePresets.json 中的 cmake 配置:

{
"name": ",
"hidden": false,
"generator": "Visual Studio 17 2022",
"toolset": {
"value": "host=x64",
"strategy": "external"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": {
value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "${sourceDir}/build/packages",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
}

When Running the build, I can see ccache is found but I see no indication that it works or called by the build system.运行构建时,我可以看到 ccache 已找到,但没有任何迹象表明它可以工作或被构建系统调用。

Running ccache -s shows every stat is 0 as if ccache is never called.运行ccache -s显示每个 stat 都是 0,就好像从未调用 ccache 一样。

Questions:问题:

  • How to correctly configure ccache with MSVC & cmake?如何使用 MSVC & cmake 正确配置 ccache?
  • How can I ensure ccache is working and the right commands are being used by the build system?如何确保 ccache 正常工作并且构建系统正在使用正确的命令? is there a "verbose" option I can provide to cmake / ccache to debug this?有没有我可以提供给 cmake / ccache 的“详细”选项来调试这个?

The <LANG>_COMPILER_LAUNCHER property does not work with the Visual Studio generator. <LANG>_COMPILER_LAUNCHER属性不适用于 Visual Studio 生成器。 According do the docs, it is only available for the Makefile and Ninja generators: https://cmake.org/cmake/help/v3.24/prop_tgt/LANG_COMPILER_LAUNCHER.html根据文档,它仅适用于 Makefile 和 Ninja 生成器: https://cmake.org/cmake/help/v3.24/prop_tgt/LANG_COMPILER_LAUNCHER.Z7FC35FDC30D825

Specify a semicolon-separated list containing a command line for a compiler launching tool.指定一个以分号分隔的列表,其中包含用于编译器启动工具的命令行。 The Makefile Generators and the Ninja generator will run this tool and pass the compiler and its arguments to the tool. Makefile 生成器和 Ninja 生成器将运行此工具并将编译器及其 arguments 传递给该工具。 Some example tools are distcc and ccache.一些示例工具是 distcc 和 ccache。

To make it work you need to specify the generator when configuring your CMake project, eg要使其工作,您需要在配置 CMake 项目时指定生成器,例如

cmake -S C:\project\src -B C:\project\build -G "Ninja"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM