CMake failes to reconfigure after failing to reconfigure due to a target missing files
Hi! We've found a weird bug in reconfiguration that is pretty easy to reproduce. We've tested this in cmake-3.8.0. When you add a new file to an existing target, and the new file isn't found by CMake, the first attempt to build will stop after failing to find the missing file.
Subsequent attempts to build will continue without reconfiguration, even when the file is added. In other words, CMake leaves a partially configured tree that cannot be built in subsequent attempts to build.
This plays havoc with attempts to build a large toolkit incrementally. We can work around this through a variety of means, but it would be better to fix this directly in CMake.
Start with:
int main(int argc, char** argv)
{
return 0;
}
and:
cmake_minimum_required(VERSION 3.0)
project(test)
set(CMAKE_BUILD_TYPE Debug)
add_executable(hello hello.cpp)
Initial configuration works:
[Build] $ cmake ..
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /XXXX/gcc/4.9.3/bin/cc
-- Check for working C compiler: /XXXX/gcc/4.9.3/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /XXXX/gcc/4.9.3/bin/c++
-- Check for working CXX compiler: /XXXX/gcc/4.9.3/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /export/home/dicuccio/test-cmake/cmake-new-file/Build
[Build] $ make
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello
If you then add a file that doesn't exist:
cmake_minimum_required(VERSION 3.0)
project(test)
set(CMAKE_BUILD_TYPE Debug)
add_executable(hello hello.cpp hello2.cpp)
and type 'make', CMake properly handles the missing file:
[Build] $ make
-- Configuring done
CMake Error at CMakeLists.txt:7 (add_executable):
Cannot find source file:
hello2.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: hello
CMake Error: Cannot determine link language for target "hello".
-- Generating done
-- Build files have been written to: /export/home/dicuccio/test-cmake/cmake-new-file/Build
make: *** [cmake_check_build_system] Error 1
However, if you immediately type 'make' again, the system fails to reconfigure:
[Build] $ make
Scanning dependencies of target hello
make[2]: *** No rule to make target `CMakeFiles/hello.dir/build'. Stop.
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2