Makefile Generator doesn't use `$<TARGET_FILE>` dependencies, breaking parallel builds
Consider the following reproducer:
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
project(break_makefile)
add_library(a SHARED src/empty.cpp)
add_library(b SHARED src/empty.cpp)
target_link_libraries(b PUBLIC $<TARGET_FILE:a>)
> make -j8
make[2]: *** No rule to make target 'liba.so', needed by 'libb.so'. Stop.
make[2]: *** Waiting for unfinished jobs....
[ 25%] Building CXX object CMakeFiles/a.dir/src/empty.cpp.o
[ 50%] Building CXX object CMakeFiles/b.dir/src/empty.cpp.o
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/b.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 75%] Linking CXX shared library liba.so
[ 75%] Built target a
make: *** [Makefile:91: all] Error 2
Given the dependency between a
and b
, we would expect a
to be built before b
. The Ninja Generator correctly uses the TARGET_FILE
dependency to order parallel builds, while the Makefile Generator doesn't.
Tested with:
- CMake 3.14.7
- CMake 3.23.2
So this issue predates the changes we made to support https://cmake.org/cmake/help/latest/policy/CMP0112.html