add_library/add_executable sources do not depend on compiler executable

By default, CMake does not add the compiler executable as a dependency of compiled objects. Sources are rebuilt when they change, but not when the compiler changes.

This causes a concrete problem in toolchain bootstrap builds such as LLVM (GitHub - llvm/llvm-project: The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. · GitHub):

- Step 1: Build clang using host compiler.

- Step 2: LLVM runtimes (libc, libclc, etc.) are configured as a separate CMake invocation via ExternalProject, using the just-built clang as CMAKE_C_COMPILER/CMAKE_CXX_COMPILER.

When clang is subsequently modified and rebuilt, the runtimes are not rebuilt because their object files have no dependency on the clang binary. This is especially critical for some runtimes that emit LLVM bitcode, where a compiler change must invalidate all outputs.

The behavior is probably related to the explanation provided in When to reconfigure vs configure from scratch? Why? - #2 by ben.boeckel, but it forces llvm-project to work around it by adding dependency on compiler executable manually.

Request: Could CMake provide an option or a variable — so that add_library/add_executable automatically adds compiler executable as an OBJECT_DEPENDS for all compiled sources?