VS: Exclude ZERO_CHECK.proj from .sln for include_external_msproject

In `cmGlobalVisualStudio7Generator::WriteTargetsToSolution`, we skip
writing `ZERO_CHECK.proj` to solution file as the check in
`cmGlobalVisualStudioGenerator::IsInSolution` returns `false` for
`ZERO_CHECK`. However, we write ZERO_CHECK to ProjectDependencies for
external projects as there are no checks in
`cmGlobalVisualStudio71Generator::WriteExternalProject`.

Similar to `cmGlobalVisualStudioGenerator::IsInSolution`, we introduce
`IsDepInSolution(const std::string&)` which excludes `ZERO_CHECK.proj`
from being added to sln file for the cases where we have `ZERO_CHECK.proj`.

Fixes: #23708
This commit is contained in:
Sumit Bhardwaj 2022-07-15 23:52:27 -07:00 committed by Brad King
parent 9d9c09b3df
commit 7219988b00
9 changed files with 63 additions and 1 deletions

View File

@ -1294,6 +1294,14 @@ bool cmGlobalVisualStudio10Generator::IsInSolution(
gt->GetName() == CMAKE_CHECK_BUILD_SYSTEM_TARGET);
}
bool cmGlobalVisualStudio10Generator::IsDepInSolution(
const std::string& targetName) const
{
return !targetName.empty() &&
!(this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 &&
targetName == CMAKE_CHECK_BUILD_SYSTEM_TARGET);
}
bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
{
if (this->DefaultPlatformToolset == "v100") {

View File

@ -120,6 +120,8 @@ public:
bool IsInSolution(const cmGeneratorTarget* gt) const override;
bool IsDepInSolution(const std::string& targetName) const override;
/** Return true if building for WindowsCE */
bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; }

View File

@ -180,7 +180,7 @@ void cmGlobalVisualStudio71Generator::WriteExternalProject(
fout << "\tProjectSection(ProjectDependencies) = postProject\n";
for (BT<std::pair<std::string, bool>> const& it : depends) {
std::string const& dep = it.Value.first;
if (!dep.empty()) {
if (this->IsDepInSolution(dep)) {
fout << "\t\t{" << this->GetGUID(dep) << "} = {" << this->GetGUID(dep)
<< "}\n";
}

View File

@ -843,6 +843,12 @@ bool cmGlobalVisualStudioGenerator::IsInSolution(
return gt->IsInBuildSystem();
}
bool cmGlobalVisualStudioGenerator::IsDepInSolution(
const std::string& targetName) const
{
return !targetName.empty();
}
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
{

View File

@ -101,6 +101,9 @@ public:
// return true if target should be included in solution.
virtual bool IsInSolution(const cmGeneratorTarget* gt) const;
// return true if project dependency should be included in solution.
virtual bool IsDepInSolution(const std::string& targetName) const;
/** Get the top-level registry key for this VS version. */
std::string GetRegistryBase();

View File

@ -0,0 +1,9 @@
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
}
}
}

View File

@ -10,3 +10,14 @@ if(RunCMake_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])")
run_cmake(SkipGetTargetFrameworkProperties)
run_cmake(VSCSharpReference)
endif()
if(RunCMake_GENERATOR MATCHES "^Visual Studio (1[6-9]|[2-9][0-9])")
function(run_VSCSharpOnlyProject)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VSCSharpOnlyProject-build)
run_cmake(VSCSharpOnlyProject)
set(RunCMake_TEST_NO_CLEAN 1)
set(build_flags /restore)
run_cmake_command(VSCSharpOnlyProject-build ${CMAKE_COMMAND} --build . -- ${build_flags})
endfunction()
run_VSCSharpOnlyProject()
endif()

View File

@ -0,0 +1,9 @@
project(VSCSharpOnlyProject)
file(COPY
${CMAKE_CURRENT_SOURCE_DIR}/Program.cs
${CMAKE_CURRENT_SOURCE_DIR}/consoleapp.csproj
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
include_external_msproject(
test "${CMAKE_CURRENT_BINARY_DIR}/consoleapp.csproj")

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<RootNamespace>ConsoleApp</RootNamespace>
<AssemblyName>ConsoleApp</AssemblyName>
<PlatformTarget>x64</PlatformTarget>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
</Project>