VS: Cross compiling in VS2019 causes VCTargetsPath.vcxproj to fail
I am trying to cross compile in Visual Studio 2019 with CMake 3.19.2, unfortunately I cannot specify what platform I am trying to compile for because it is under NDA. I will still outline the issue in a general sense.
When I try to generate VS2019 using a custom toolchain I get this error
Project "\build\CMakeFiles\3.19.2\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(777,5): error : The OutputPath property is not set for project 'VCTargetsPath.vcxproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='MYPLATFORM'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [\build\CMakeFiles\3.19.2\VCTargetsPath.vcxproj]
Now my toolchain is set up correctly, I believe. I have CMAKE_CXX_COMPILER
set to the correct path, as well as everything else.
This setup was working is with VS2017, and I am trying to upgrade.
I am using the CMakePresets.json and have the flags set up as follows
"toolset": "v142,host=x64",
"architecture": "MYPLATFORM",
I have tried declaring the VCTargets manually, but found that I just hit the same issue when I reach ALL_BUILD and ZERO_CHECK.
I did some digging and it looks like for the VCTargetsPath.vcxproj generation you use the declared CMAKE_GENERATOR_PLATFORM, then when you call it to build, you neglect to put in a platform at all. As such I believe the MSBuild behavior is to default to x64?
I may be completely incorrect and am missing something and would like to hear thoughts.
Generation of VCTargetsPath.vcxproj: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.20.1/Source/cmGlobalVisualStudio10Generator.cxx#L914
cmXMLElement eig(eprj, "ItemGroup");
eig.Attribute("Label", "ProjectConfigurations");
cmXMLElement epc(eig, "ProjectConfiguration");
epc.Attribute("Include", "Debug|" + this->GetPlatformName());
cmXMLElement(epc, "Configuration").Content("Debug");
cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
Calling of the command: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.20.1/Source/cmGlobalVisualStudio10Generator.cxx#L990
std::vector<std::string> cmd;
cmd.push_back(this->GetMSBuildCommand());
cmd.push_back(vcxproj);
cmd.push_back("/p:Configuration=Debug");
cmd.push_back(std::string("/p:VisualStudioVersion=") +
this->GetIDEVersion());
This is in the VS Version 10 code, I did not find any VCTargets related code anywhere else. This code also looks like it is getting ran, as the source matches exactly what the project looks like.
Perhaps adding the correct platform to the MSBuild call is a solution. It may work just using defaults for config and platform, but I do not know. This is a larger issue with ALL_BUILD, ZERO_CONFIG, and likely other CMake generated projects having the same issue. If there is something I can change with how my CMake is set up, I am willing to hear it.
Let me know if you need more info.