From 8e654a37857b7cefabf142b16fe8a6e03b75b5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Thu, 23 Nov 2017 14:18:23 +0100 Subject: [PATCH] VS: Enable generation of CSharp projects without initial .cs files fixes #17388 --- Source/cmVisualStudio10TargetGenerator.cxx | 16 ++++++++++------ Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 1 + .../VsCSharpWithoutSources-check.cmake | 5 +++++ .../VS10Project/VsCSharpWithoutSources.cmake | 7 +++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/VS10Project/VsCSharpWithoutSources-check.cmake create mode 100644 Tests/RunCMake/VS10Project/VsCSharpWithoutSources.cmake diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index caeeeb9d00..540d877f9f 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -66,11 +66,14 @@ static bool cmVS10IsTargetsFile(std::string const& path) return cmSystemTools::Strucmp(ext.c_str(), ".targets") == 0; } -static std::string computeProjectFileExtension(cmGeneratorTarget const* t) +static std::string computeProjectFileExtension(cmGeneratorTarget const* t, + const std::string& config) { std::string res; res = ".vcxproj"; - if (cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(t)) { + std::string lang = t->GetLinkerLanguage(config); + if (cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(t) || + lang == "CSharp") { res = ".csproj"; } return res; @@ -199,8 +202,8 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT")) { return; } - this->ProjectFileExtension = - computeProjectFileExtension(this->GeneratorTarget); + this->ProjectFileExtension = computeProjectFileExtension( + this->GeneratorTarget, *this->Configurations.begin()); if (this->ProjectFileExtension == ".vcxproj") { this->ProjectType = vcxproj; this->Managed = false; @@ -1393,7 +1396,8 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::string path = this->LocalGenerator->GetCurrentBinaryDirectory(); path += "/"; path += this->Name; - path += computeProjectFileExtension(this->GeneratorTarget); + path += computeProjectFileExtension(this->GeneratorTarget, + *this->Configurations.begin()); path += ".filters"; cmGeneratedFileStream fout(path.c_str()); fout.SetCopyIfDifferent(true); @@ -3670,7 +3674,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() path = lg->GetCurrentBinaryDirectory(); path += "/"; path += dt->GetName(); - path += computeProjectFileExtension(dt); + path += computeProjectFileExtension(dt, *this->Configurations.begin()); } this->ConvertToWindowsSlash(path); (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n"; diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 6e7c2f3135..7100b31dcd 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -5,3 +5,4 @@ run_cmake(VsCustomProps) run_cmake(VsDebuggerWorkingDir) run_cmake(VsCSharpCustomTags) run_cmake(VsCSharpReferenceProps) +run_cmake(VsCSharpWithoutSources) diff --git a/Tests/RunCMake/VS10Project/VsCSharpWithoutSources-check.cmake b/Tests/RunCMake/VS10Project/VsCSharpWithoutSources-check.cmake new file mode 100644 index 0000000000..90ae7c3c07 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpWithoutSources-check.cmake @@ -0,0 +1,5 @@ +set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj") +if(NOT EXISTS "${csProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/VS10Project/VsCSharpWithoutSources.cmake b/Tests/RunCMake/VS10Project/VsCSharpWithoutSources.cmake new file mode 100644 index 0000000000..5fdeaa0a2e --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpWithoutSources.cmake @@ -0,0 +1,7 @@ +enable_language(CSharp) + +add_library(foo SHARED + "${CMAKE_CURRENT_LIST_FILE}") + +set_target_properties(foo PROPERTIES + LINKER_LANGUAGE CSharp)