VS: Generate a custom command only in the least dependent target

If a custom command is assigned to multiple targets, generate the build
rule only in the least-dependent `.vcxproj` file.  Otherwise MSBuild
will run the command on the first build of a dependent target even if
its dependencies already brought the command up to date (in order to
populates its build log).

Generate targets in least-to-most-dependent order, and assign a custom
command to the least dependent target.

Added cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst to call
cmVisualStudio10TargetGenerator::Generate in least-dependent order.

Moved SourcesVisited from cmVisualStudio10TargetGenerator to
cmLocalVisualStudio10Generator to avoid attaching a custom command to
multiple targets among the local generator.

Fixes: #16767
Status Job ID Name Coverage
  External
passed cdash

passed cmake-dash3win7-windows-release-ninja

passed cmake-hythloth-linux-debug-makefiles+sphinx

passed cmake-hythloth-linux-release-lint-iwyu-tidy

passed cmake-moonshade-osx-debug-ninja

passed cmake-moonshade-osx-release-makefiles

passed cmake-terfin-windows-release-vs2017

passed ghostflow-branch-check-master

passed ghostflow-commit-check

passed ghostflow-stager

passed cmake-dash3win7-windows-release-ninja

passed cmake-dash3win7-windows-release-ninja

passed cmake-dash3win7-windows-release-ninja

01:25:19

passed cmake-dash3win7-windows-release-ninja

passed cmake-hythloth-linux-debug-makefiles+sphinx

passed cmake-hythloth-linux-debug-makefiles+sphinx

passed cmake-hythloth-linux-debug-makefiles+sphinx

00:50:36

passed cmake-hythloth-linux-debug-makefiles+sphinx

passed cmake-hythloth-linux-release-lint-iwyu-tidy

passed cmake-hythloth-linux-release-lint-iwyu-tidy

passed cmake-hythloth-linux-release-lint-iwyu-tidy

00:17:13

passed cmake-hythloth-linux-release-lint-iwyu-tidy

passed cmake-moonshade-osx-debug-ninja

00:12:30

passed cmake-moonshade-osx-debug-ninja

passed cmake-moonshade-osx-debug-ninja

passed cmake-moonshade-osx-debug-ninja

passed cmake-moonshade-osx-release-makefiles

passed cmake-moonshade-osx-release-makefiles

passed cmake-moonshade-osx-release-makefiles

passed cmake-moonshade-osx-release-makefiles

00:12:12

passed cmake-terfin-windows-release-vs2017

passed cmake-terfin-windows-release-vs2017

passed cmake-terfin-windows-release-vs2017

passed cmake-terfin-windows-release-vs2017

00:35:30

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager

passed ghostflow-stager