Build tool mode does not respect dependencies of include_external_msproject() targets
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.1)
include_external_msproject(ImportedProject
${CMAKE_CURRENT_LIST_DIR}/ConsoleApplication1/ConsoleApplication1.vcxproj
PLATFORM "x64"
TYPE 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942)
add_custom_target(CustomTarget
COMMAND ${CMAKE_COMMAND} -E echo Custom command executed)
add_dependencies(ImportedProject CustomTarget)
Steps to reproduce
mkdir build
cd build
cmake -G "Visual Studio 15 2017" ..
cmake --build .
Expected result
CustomTarget
is built before ImportedProject
is built, and "Custom command executed" appears on the command line.
Actual result
Only ImportedProject
is built, and CustomTarget
is not built.
When building instead with msbuild Project.sln /p:Configuration=Release /p:Platform="Win32"
, the target CustomTarget
is built before ImportedProject
is built, and the message appears on the command line.
Further information
The dependency of ImportedProject
on CustomTarget
is only present in the generated Project.sln
file:
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CustomTarget", "CustomTarget.vcxproj", "{2D0AD49C-D8BC-3914-A39B-5818974BE26D}"
ProjectSection(ProjectDependencies) = postProject
{0D714CCF-3240-3272-933C-481BF60F78F2} = {0D714CCF-3240-3272-933C-481BF60F78F2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImportedProject", "C:\Development\CMakeTest\ConsoleApplication1\ConsoleApplication1.vcxproj", "{BA130801-4373-4EB3-A577-67344BDF75AB}"
ProjectSection(ProjectDependencies) = postProject
{2D0AD49C-D8BC-3914-A39B-5818974BE26D} = {2D0AD49C-D8BC-3914-A39B-5818974BE26D}
{0D714CCF-3240-3272-933C-481BF60F78F2} = {0D714CCF-3240-3272-933C-481BF60F78F2}
EndProjectSection
EndProject
However, cmake --build
does not invoke MSBuild with the .sln file, but instead with ALL_BUILD.vcxproj
, which does not contain that dependency information.
Even when specifying the ALL
keyword for CustomTarget
, there is still no dependency between the targets, as can be seen when renaming CustomTarget
to ZZ_CustomTarget
. In that case, ImportedProject
is built first, and ZZ_CustomTarget
is built second.