ExternalProject: Changing GIT_TAG requires two builds with Ninja
I've noticed when using ExternalProject_Add
that whenever I change GIT_TAG
from one commit SHA to another, while using either the Ninja
or Ninja Multi-Config
generators, it builds the external project as expected, but it doesn't seem to mark the consuming project source/object files as dirty, which can lead to weird linker errors. If you immediately run another build after that, it then builds the project source files without errors.
I tried reducing it down to a minimal repro and ended up with these two small test projects, where project1
consumes the library from project2
through ExternalProject_Add
and its GIT_REPOSITORY
. Note that I've only tested this on Windows, using Visual Studio's Native Tools Command Prompt. I don't know how these errors translate to other compilers or operating systems.
Steps to reproduce:
cmake -G "Ninja" -B .\build
cmake --build .\build
.\build\project1.exe
- Note the message saying
This message is from the old interface.
- Open
.\CMakeLists.txt
and changeGIT_TAG
to the one saying# Second commit
cmake --build .\build
- Note linker error about unresolved external symbol
cmake --build .\build
- Note successful linking
.\build\project1.exe
- Note the message saying
This message is from the new interface.
You can toggle back-and-forth between these two commits to reproduce the same error again.