Ninja error: manifest 'build.ninja' still dirty after 100 tries
The following CMakeLists.txt file makes Ninja (>=1.6.0) re-run CMake indefinitely until it finally gives up with the message ninja: error: manifest 'build.ninja' still dirty after 100 tries
:
cmake_minimum_required(VERSION 3.18)
project(CMakeInfiniteLoopTest)
add_library(mylib main.cpp)
# Variable containing a generator expression.
set(mylib_LIBRARY $<TARGET_FILE_NAME:mylib>)
# Substitue expression @VAR@ by contents of variables.
configure_file(mylib-config.cmake.in ${PROJECT_BINARY_DIR}/mylib-config.cmake.tmp)
# Create final output file, evaluating generator expression(s).
file(GENERATE OUTPUT mylib-config.cmake INPUT ${PROJECT_BINARY_DIR}/mylib-config.cmake.tmp)
The problem is that the temporary intermediate file mylib-config.cmake.tmp
is included in the rebuild manifest created by CMake. This leads to CMake being re-run over and over again. Earlier versions of Ninja (<=1.5.3) limited the numbers of re-runs to 2 and ignored the fact that build.ninja
was still dirty, but with newer versions of Ninja this is a problem.
See also discussion here: https://discourse.cmake.org/t/infinite-re-run-loop-with-cmake-3-5-1-and-ninja-1-10-0/1435