summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-01-07 14:39:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-01-07 14:39:22 (GMT)
commit229455307065f3d438928d6a7a5059f5a2337bf6 (patch)
tree18836ab8789ebe6319d91df210676118954eda12 /Source
parent11b0ab167224d7bda2f7ccfacd026c322b4a1ca5 (diff)
parent3b7520b94db1cae997b4b2302bdae1bed821b811 (diff)
downloadCMake-229455307065f3d438928d6a7a5059f5a2337bf6.zip
CMake-229455307065f3d438928d6a7a5059f5a2337bf6.tar.gz
CMake-229455307065f3d438928d6a7a5059f5a2337bf6.tar.bz2
Merge topic 'refactor_vsproject_type'
3b7520b94d Consolidate usage of VsProjectType 938a53f4f1 Refactor VsProjectType to its own header Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6830
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeLists.txt1
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx6
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx4
-rw-r--r--Source/cmLocalVisualStudioGenerator.h9
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx64
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h7
-rw-r--r--Source/cmVsProjectType.h11
7 files changed, 55 insertions, 47 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 677fd2f..a9aec6c 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -766,6 +766,7 @@ if (WIN32)
cmGlobalVisualStudio9Generator.h
cmVisualStudioGeneratorOptions.h
cmVisualStudioGeneratorOptions.cxx
+ cmVsProjectType.h
cmVisualStudio10TargetGenerator.h
cmVisualStudio10TargetGenerator.cxx
cmLocalVisualStudio10Generator.cxx
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index fd13c0b..4bf8df6 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -40,6 +40,7 @@
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cmValue.h"
+#include "cmVsProjectType.h"
#include "cmXMLParser.h"
#include "cmake.h"
@@ -574,7 +575,8 @@ public:
{
// If any commands were generated, finish constructing them.
if (!this->First) {
- std::string finishScript = this->LG->FinishConstructScript(IsCSharp::No);
+ std::string finishScript =
+ this->LG->FinishConstructScript(VsProjectType::vcxproj);
this->Stream << this->LG->EscapeForXML(finishScript) << "\"";
}
@@ -1817,7 +1819,7 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
if (this->FortranProject) {
cmSystemTools::ReplaceString(script, "$(Configuration)", config);
}
- script += this->FinishConstructScript(IsCSharp::No);
+ script += this->FinishConstructScript(VsProjectType::vcxproj);
/* clang-format off */
fout << "\t\t\t\t\t<Tool\n"
<< "\t\t\t\t\tName=\"" << customTool << "\"\n"
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index a21293b..93f01ed 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -245,14 +245,14 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
}
std::string cmLocalVisualStudioGenerator::FinishConstructScript(
- IsCSharp isCSharp, const std::string& newline)
+ VsProjectType projectType, const std::string& newline)
{
bool useLocal = this->CustomCommandUseLocal();
// Store the script in a string.
std::string script;
- if (useLocal && isCSharp == IsCSharp::Yes) {
+ if (useLocal && projectType == VsProjectType::csproj) {
// This label is not provided by MSBuild for C# projects.
script += newline;
script += this->GetReportErrorLabel();
diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h
index 82a62cf..cf4f4d9 100644
--- a/Source/cmLocalVisualStudioGenerator.h
+++ b/Source/cmLocalVisualStudioGenerator.h
@@ -10,6 +10,7 @@
#include "cmGlobalVisualStudioGenerator.h"
#include "cmLocalGenerator.h"
+#include "cmVsProjectType.h"
class cmCustomCommand;
class cmCustomCommandGenerator;
@@ -30,15 +31,9 @@ public:
cmLocalVisualStudioGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
virtual ~cmLocalVisualStudioGenerator();
- /** Construct a script from the given list of command lines. */
- enum class IsCSharp
- {
- No,
- Yes
- };
std::string ConstructScript(cmCustomCommandGenerator const& ccg,
const std::string& newline = "\n");
- std::string FinishConstructScript(IsCSharp isCSharp,
+ std::string FinishConstructScript(VsProjectType projectType,
const std::string& newline = "\n");
/** Label to which to jump in a batch file after a failed step in a
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 84044e4..685d34d 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -235,14 +235,27 @@ static bool cmVS10IsTargetsFile(std::string const& path)
return cmSystemTools::Strucmp(ext.c_str(), ".targets") == 0;
}
-static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
+static VsProjectType computeProjectType(cmGeneratorTarget const* t)
{
- std::string res;
- res = ".vcxproj";
if (t->IsCSharpOnly()) {
- res = ".csproj";
+ return VsProjectType::csproj;
+ }
+ return VsProjectType::vcxproj;
+}
+
+static std::string computeProjectFileExtension(VsProjectType projectType)
+{
+ switch (projectType) {
+ case VsProjectType::csproj:
+ return ".csproj";
+ default:
+ return ".vcxproj";
}
- return res;
+}
+
+static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
+{
+ return computeProjectFileExtension(computeProjectType(t));
}
cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
@@ -339,21 +352,18 @@ std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString(
void cmVisualStudio10TargetGenerator::Generate()
{
+ this->ProjectType = computeProjectType(this->GeneratorTarget);
+ this->Managed = this->ProjectType == VsProjectType::csproj;
const std::string ProjectFileExtension =
- computeProjectFileExtension(this->GeneratorTarget);
- if (ProjectFileExtension == ".vcxproj") {
- this->ProjectType = VsProjectType::vcxproj;
- this->Managed = false;
- } else if (ProjectFileExtension == ".csproj") {
- if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
- std::string message = "The C# target \"" +
- this->GeneratorTarget->GetName() +
- "\" is of type STATIC_LIBRARY. This is discouraged (and may be "
- "disabled in future). Make it a SHARED library instead.";
- this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message);
- }
- this->ProjectType = VsProjectType::csproj;
- this->Managed = true;
+ computeProjectFileExtension(this->ProjectType);
+
+ if (this->ProjectType == VsProjectType::csproj &&
+ this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
+ std::string message = "The C# target \"" +
+ this->GeneratorTarget->GetName() +
+ "\" is of type STATIC_LIBRARY. This is discouraged (and may be "
+ "disabled in future). Make it a SHARED library instead.";
+ this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message);
}
if (this->Android &&
@@ -406,7 +416,7 @@ void cmVisualStudio10TargetGenerator::Generate()
char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
BuildFileStream.write(magic, 3);
- if (this->Managed && this->ProjectType == VsProjectType::csproj &&
+ if (this->ProjectType == VsProjectType::csproj &&
this->GeneratorTarget->IsDotNetSdkTarget() &&
this->GlobalGenerator->GetVersion() >=
cmGlobalVisualStudioGenerator::VS16) {
@@ -832,7 +842,7 @@ void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile(
void cmVisualStudio10TargetGenerator::WriteSdkStyleProjectFile(
cmGeneratedFileStream& BuildFileStream)
{
- if (!this->Managed || this->ProjectType != VsProjectType::csproj ||
+ if (this->ProjectType != VsProjectType::csproj ||
!this->GeneratorTarget->IsDotNetSdkTarget()) {
std::string message = "The target \"" + this->GeneratorTarget->GetName() +
"\" is not eligible for .Net SDK style project.";
@@ -1711,11 +1721,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule(
}
}
}
- cmLocalVisualStudioGenerator::IsCSharp isCSharp =
- (this->ProjectType == VsProjectType::csproj)
- ? cmLocalVisualStudioGenerator::IsCSharp::Yes
- : cmLocalVisualStudioGenerator::IsCSharp::No;
- script += lg->FinishConstructScript(isCSharp);
+ script += lg->FinishConstructScript(this->ProjectType);
if (this->ProjectType == VsProjectType::csproj) {
std::string name = "CustomCommand_" + c + "_" +
cmSystemTools::ComputeStringMD5(sourcePath);
@@ -4449,11 +4455,7 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
}
}
if (!script.empty()) {
- cmLocalVisualStudioGenerator::IsCSharp isCSharp =
- (this->ProjectType == VsProjectType::csproj)
- ? cmLocalVisualStudioGenerator::IsCSharp::Yes
- : cmLocalVisualStudioGenerator::IsCSharp::No;
- script += lg->FinishConstructScript(isCSharp);
+ script += lg->FinishConstructScript(this->ProjectType);
}
comment = cmVS10EscapeComment(comment);
if (this->ProjectType != VsProjectType::csproj) {
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 37b8dfd..8d2b77d 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -14,6 +14,7 @@
#include <vector>
#include "cmGeneratorTarget.h"
+#include "cmVsProjectType.h"
class cmComputeLinkInformation;
class cmCustomCommand;
@@ -211,11 +212,7 @@ private:
OptionsMap LinkOptions;
std::string LangForClCompile;
- enum class VsProjectType
- {
- vcxproj,
- csproj
- } ProjectType;
+ VsProjectType ProjectType;
bool InSourceBuild;
std::vector<std::string> Configurations;
std::vector<TargetsFileAndConfigs> TargetsFileAndConfigsVec;
diff --git a/Source/cmVsProjectType.h b/Source/cmVsProjectType.h
new file mode 100644
index 0000000..8899267
--- /dev/null
+++ b/Source/cmVsProjectType.h
@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include "cmConfigure.h" // IWYU pragma: keep
+
+enum class VsProjectType
+{
+ vcxproj,
+ csproj
+};