diff --git a/CMakeLists.txt b/CMakeLists.txt index 7945ee63a3078..9531e47d9977f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -469,6 +469,13 @@ if(MSVC) endif() if(runtime_cxxmodules) + if(NOT ROOT_CONFIGURED_FROM_CACHE) + # When using cmake --fresh (or changing the toolchain), remove possibly stale pcms that are not tracked by CMake + set(ROOT_CONFIGURED_FROM_CACHE True CACHE BOOL "Shows if ROOT is configured from an existing CMake cache") + mark_as_advanced(ROOT_CONFIGURED_FROM_CACHE) + file(GLOB left_over_pcms ${CMAKE_BINARY_DIR}/lib/*.pcm) + file(REMOVE ${left_over_pcms}) + endif() # Dummy target that does nothing, we don't need a PCH for modules. # Onepcm target has all dependencies needed for allDict.cxx.pch, which allow # to test hsimple.C after all C++ modules are updated.