Consider the following workflow:
cmake -B build -DBUILD_TESTS=OFF
cmake --build build
cmake -B build -DBUILD_TESTS=OFF -DBUILD_GUI=ON
cmake --build build
The last command builds not only bitcoin-qt and bitcoin-gui, but also unnecessarily rebuilds other targets.
This is caused by including GUI-specific definitions, such as USE_DBUS and USE_QRCODE, in bitcoin-build-config.h, which in turn triggers the recompilation for all targets that consume this header.
This PR resolves the issue. This is useful on its own, but it is also a necessary prerequisite for effectively addressing #29914.