VS: Race condition with INSTALL for multiple targets from same directory
The following issue appears to be specific for the MSVC generator, due to the functionality of the deferred INSTALL target being "partially" integrated within the build of each target.
For all targets defined in the same source directory, only a single, monolithic cmake_install.cmake
is created, which every target building from that source directory immediately invokes script in a PostBuildEvent
event.
Example:
Take two independent targets foo
and bar
declared from the same CMakeList.txt
, both using INSTALL
.
When building the solution, foo
and bar
build concurrently in an unspecified order. The first of foo
or bar
to reach the install step will call cmake_install.cmake
, which then attempts to install artifacts from both targets, despite the other target still being in-flight.
The results is a spuriously breaking (clean) build in the best case (as the referenced artifacts don't exist yet, or the copy process encounters a file system lock on the install destination), or a silently corrupted installation in the worst case (as the referenced artifact is copied in a dirty state).
For an incremental build, the risk of spurious breaking is reduced, but the risk of corruption persists.
Expected Behavior:
Given that the integrated install step for the MSVC generator should be preserved, cmake_install.cmake
must gain support to only execute install actions for artifacts generated from a specific target.
In the generated MSVC project, cmake_install.cmake
must be invoked in a way which only performs the installation for the built target, rather than for the entire directory yet. Specifically, installation must not be performed on behalf of a different target.