Repository: bitcoin/bitcoin (language: cpp)

Issue:
cmake: incorrectly reporting MSVC as using ccache
Mentioned by @stickies-v. The CMake configure currently outputs that MSVC builds are using ccache, i.e (https://github.com/bitcoin/bitcoin/actions/runs/13063954360/job/36452895056#step:8:2374):
```bash
Treat compiler warnings as errors ..... ON
Use ccache for compiling .............. ON
```

However that's a bug, as MSVC is currently excluded entirely from using ccache: 
https://github.com/bitcoin/bitcoin/blob/8fa10edcd1706a1f0dc9d8c3adbc8efa3c7755bf/cmake/ccache.cmake#L4-L6


Discussion / hints:
Hey, can I contribute to this issue

@vijayabhaskar78 

> Hey, can I contribute to this issue

Sure! No need to ask :)
@hebasto sir Proposing a fix for #31771:

    Set USE_CCACHE=OFF for MSVC in cmake/ccache.cmake.
    Update status reporting in CMakeLists.txt.

Questions:

    Does this align with project conventions?
    Any edge cases (MinGW/cross-compile) to test?
I don't understand the motivation for setting `CMAKE_<lang>_COMPILER_LAUNCHER` from inside the project. Ideally, the project should not interfere with compiler launchers at all.

This gives individual users as well as CI instances the highest flexibility.

Assuming I have `ENV{CMAKE_CXX_COMPILER_LAUNCHER}` set locally to use [`sccache`](https://github.com/mozilla/sccache). What is the expected behavior when `cmake/ccache.cmake` invokes `list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})`? Will it use `sccache`, `ccache`, or both?
@purpleKarrot Should we remove the CMAKE_*_COMPILER_LAUNCHER assignments from ccache.cmake to prioritize user/CI flexibility? This would:

    Avoid conflicts with external launchers like sccache set via ENV{CMAKE_CXX_COMPILER_LAUNCHER}.
    Follow CMake best practices by letting users control launchers externally.
    Prevent invalid command chains (e.g., sccache;ccache;cl.exe) when multiple launchers are set.

If agreed, I can update the PR to delete these lines and add documentation instead
I'm a newbie to this repository. Can you help me to understand it?
@vijayabhaskar78, I am a newbe in this repository too, but I am not a newbie with CMake ;-)
My recommendation would be to remove `cmake/ccache.cmake` for the reason you wrote.
But let the original authors of that file chime in.
OK let us see 
@fanquake @hebasto @purpleKarrot  

### **Problem Summary**  

- **False Reporting:** CMake incorrectly reports `ccache` as "ON" for MSVC builds despite excluding it in `cmake/ccache.cmake`.  
- **Launcher Conflicts:** Forced `CMAKE_*_COMPILER_LAUNCHER` assignments override user/CI settings (e.g., `sccache`).  

### **Proposed Fix**  

#### **1. Delete `cmake/ccache.cmake`**  

```bash
rm cmake/ccache.cmake
```

- **Why?** Removes forced `ccache` logic conflicting with external launchers.  
- **Impact:** Users/CI regain full control via `CMAKE_CXX_COMPILER_LAUNCHER`.  

#### **2. Update Status Message**  

```cmake
if(DEFINED ENV{CMAKE_CXX_COMPILER_LAUNCHER})  
  message(STATUS "Compiler launcher .............. $ENV{CMAKE_CXX_COMPILER_LAUNCHER}")  
else()  
  message(STATUS "Use ccache for compiling .............. NO")  
endif()
```

- **Result:** Accurately reflects whether a launcher (e.g., `ccache`) is active.  

#### **3. Document MSVC + `ccache` Workflow**  

Add to `doc/build-windows.md`:  


### **Caching MSVC Builds**  
- **Step 1**: Use Ninja:  
  ```sh
  -G "Ninja"
  ```
- **Step 2**: Configure launcher:  
  ```sh
  cmake -B build -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
  ```
- **Step 3**: Use `/Z7` (not `/Zi`) for debug flags.  


### **Why This Approach?**  

- **Flexibility:** No forced `ccache`/generator logic. Users/CI control launchers via CMake/env vars.  
- **CMake Compliance:** Follows [CMake best practices](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html).  
- **Simplification:** Deletes 50+ lines of error-prone code.  

### **Feedback Requested**  

- @purpleKarrot: Does this address your concerns about launcher flexibility?  
- Maintainers (@fanquake, @hebasto): Any objections to deleting `ccache.cmake`?  


> I don't understand the motivation for setting `CMAKE_<lang>_COMPILER_LAUNCHER` from inside the project.

I'm also ignorantly curious about this. Is it primarily a requirement from the feature parity list with the prior `autotools`?

https://gist.github.com/hebasto/2ef97d3a726bfce08ded9df07f7dab5e

Is the msvc configure summary a blocker for the release? I've removed the milestone from https://github.com/bitcoin/bitcoin/pull/30861 because it looks more like an involved feature than a bugfix, so maybe it can be removed here as well?

Fix patch:
diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake
index d1cc204c8e463..0bfd3a41f62db 100644
--- a/cmake/ccache.cmake
+++ b/cmake/ccache.cmake
@@ -23,6 +23,8 @@ if(NOT MSVC)
   else()
     set(WITH_CCACHE OFF)
   endif()
+else()
+  set(WITH_CCACHE OFF)
 endif()
 
 mark_as_advanced(CCACHE_EXECUTABLE)


Test patch: