Should CMake prevent build system regeneration from depending on the build?
We had a bug in LLVM's build recently where the rule to regenerate the build system (build.ninja
, since we were using Ninja) ended up depending on part of the build. This was effectively a circular dependency, and meant that incremental builds would spuriously fail on CMake changes, because the build system regeneration step would fail to build before it could perform the regeneration.
https://github.com/smeenai/ninja-regeneration is a simple repro to demonstrate what I mean:
git clone https://github.com/smeenai/ninja-regeneration
cd ninja-regeneration
git checkout HEAD^
mkdir build
cd build
cmake -G Ninja ..
git checkout main
ninja generate
You'll get a spurious link error, because build system regeneration is itself attempting to build generate
, which needs the CMake changes to be reflected in the build system in order to work. Manually regenerating the build system (cmake -S .. -B .
) will make the build work.
Should CMake error out for this sort of scenario? It never seems desirable and will always lead to broken incremental builds; it's basically a circular dependency in disguise (since all other targets implicitly depend on the build system regeneration). I'm not sure if this is more of a CMake concern or a Ninja concern; I posted a Ninja issue as well.