cmGlobalVisualStudio7Generator: Factor out computation of path to .sln

This commit is contained in:
Brad King
2025-08-25 15:25:57 -04:00
parent 0a17f4e996
commit d32b78f139
5 changed files with 33 additions and 22 deletions
+3 -7
View File
@@ -1065,6 +1065,8 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
std::string makeProgramSelected = std::string makeProgramSelected =
this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand()); this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
std::string const slnFile = this->GetSLNFile(projectDir, projectName);
// Check if the caller explicitly requested a devenv tool. // Check if the caller explicitly requested a devenv tool.
std::string makeProgramLower = makeProgramSelected; std::string makeProgramLower = makeProgramSelected;
cmSystemTools::LowerCase(makeProgramLower); cmSystemTools::LowerCase(makeProgramLower);
@@ -1079,12 +1081,6 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
// an Intel Fortran .vfproj then we have to use devenv. Parse it to find out. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
cmSlnData slnData; cmSlnData slnData;
{ {
std::string slnFile;
if (!projectDir.empty()) {
slnFile = cmStrCat(projectDir, '/');
}
slnFile += projectName;
slnFile += ".sln";
cmVisualStudioSlnParser parser; cmVisualStudioSlnParser parser;
if (parser.ParseFile(slnFile, slnData, if (parser.ParseFile(slnFile, slnData,
cmVisualStudioSlnParser::DataGroupAll)) { cmVisualStudioSlnParser::DataGroupAll)) {
@@ -1125,7 +1121,7 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
makeCommand.Add(makeProgramSelected); makeCommand.Add(makeProgramSelected);
if (tname == "clean"_s) { if (tname == "clean"_s) {
makeCommand.Add(cmStrCat(projectName, ".sln")); makeCommand.Add(slnFile);
makeCommand.Add("/t:Clean"); makeCommand.Add("/t:Clean");
} else { } else {
std::string targetProject = cmStrCat(tname, ".vcxproj"); std::string targetProject = cmStrCat(tname, ".vcxproj");
+6 -5
View File
@@ -206,15 +206,16 @@ char const* cmGlobalVisualStudio7Generator::ExternalProjectType(
std::vector<cmGlobalGenerator::GeneratedMakeCommand> std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalVisualStudio7Generator::GenerateBuildCommand( cmGlobalVisualStudio7Generator::GenerateBuildCommand(
std::string const& makeProgram, std::string const& projectName, std::string const& makeProgram, std::string const& projectName,
std::string const& /*projectDir*/, std::string const& projectDir, std::vector<std::string> const& targetNames,
std::vector<std::string> const& targetNames, std::string const& config, std::string const& config, int /*jobs*/, bool /*verbose*/,
int /*jobs*/, bool /*verbose*/, cmBuildOptions /*buildOptions*/, cmBuildOptions /*buildOptions*/, std::vector<std::string> const& makeOptions)
std::vector<std::string> const& makeOptions)
{ {
// Select the caller- or user-preferred make program, else devenv. // Select the caller- or user-preferred make program, else devenv.
std::string makeProgramSelected = std::string makeProgramSelected =
this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand()); this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
std::string const slnFile = this->GetSLNFile(projectDir, projectName);
// Ignore the above preference if it is msbuild. // Ignore the above preference if it is msbuild.
// Assume any other value is either a devenv or // Assume any other value is either a devenv or
// command-line compatible with devenv. // command-line compatible with devenv.
@@ -249,7 +250,7 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand(
GeneratedMakeCommand makeCommand; GeneratedMakeCommand makeCommand;
makeCommand.RequiresOutputForward = requiresOutputForward; makeCommand.RequiresOutputForward = requiresOutputForward;
makeCommand.Add(makeProgramSelected); makeCommand.Add(makeProgramSelected);
makeCommand.Add(cmStrCat(projectName, ".sln")); makeCommand.Add(slnFile);
makeCommand.Add((clean ? "/clean" : "/build")); makeCommand.Add((clean ? "/clean" : "/build"));
makeCommand.Add((config.empty() ? "Debug" : config)); makeCommand.Add((config.empty() ? "Debug" : config));
makeCommand.Add("/project"); makeCommand.Add("/project");
+1 -1
View File
@@ -306,7 +306,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
std::string argS = cmStrCat("-S", lg.GetSourceDirectory()); std::string argS = cmStrCat("-S", lg.GetSourceDirectory());
std::string argB = cmStrCat("-B", lg.GetBinaryDirectory()); std::string argB = cmStrCat("-B", lg.GetBinaryDirectory());
std::string const sln = std::string const sln =
cmStrCat(lg.GetBinaryDirectory(), '/', lg.GetProjectName(), ".sln"); this->GetSLNFile(lg.GetBinaryDirectory(), lg.GetProjectName());
cmCustomCommandLines commandLines = cmMakeSingleCommandLine( cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list", { cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list",
stampList, "--vs-solution-file", sln }); stampList, "--vs-solution-file", sln });
+19 -9
View File
@@ -38,14 +38,6 @@
#include "cmUuid.h" #include "cmUuid.h"
#include "cmake.h" #include "cmake.h"
namespace {
std::string GetSLNFile(cmLocalGenerator const* root)
{
return cmStrCat(root->GetCurrentBinaryDirectory(), '/',
root->GetProjectName(), ".sln");
}
}
cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm) cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm)
: cmGlobalGenerator(cm) : cmGlobalGenerator(cm)
{ {
@@ -771,7 +763,7 @@ bool cmGlobalVisualStudioGenerator::Open(std::string const& bindir,
std::string const& projectName, std::string const& projectName,
bool dryRun) bool dryRun)
{ {
std::string sln = cmStrCat(bindir, '/', projectName, ".sln"); std::string sln = this->GetSLNFile(bindir, projectName);
if (dryRun) { if (dryRun) {
return cmSystemTools::FileExists(sln, true); return cmSystemTools::FileExists(sln, true);
@@ -1092,6 +1084,24 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
return solution; return solution;
} }
std::string cmGlobalVisualStudioGenerator::GetSLNFile(
cmLocalGenerator const* root) const
{
return this->GetSLNFile(root->GetCurrentBinaryDirectory(),
root->GetProjectName());
}
std::string cmGlobalVisualStudioGenerator::GetSLNFile(
std::string const& projectDir, std::string const& projectName) const
{
std::string slnFile = projectDir;
if (!slnFile.empty()) {
slnFile.push_back('/');
}
slnFile = cmStrCat(slnFile, projectName, ".sln");
return slnFile;
}
void cmGlobalVisualStudioGenerator::Generate() void cmGlobalVisualStudioGenerator::Generate()
{ {
// first do the superclass method // first do the superclass method
+4
View File
@@ -196,6 +196,10 @@ protected:
cm::VS::Solution::Folder* CreateSolutionFolder( cm::VS::Solution::Folder* CreateSolutionFolder(
cm::VS::Solution& solution, cm::string_view rawName) const; cm::VS::Solution& solution, cm::string_view rawName) const;
std::string GetSLNFile(cmLocalGenerator const* root) const;
std::string GetSLNFile(std::string const& projectDir,
std::string const& projectName) const;
void Generate() override; void Generate() override;
void GenerateSolution(cmLocalGenerator const* root, void GenerateSolution(cmLocalGenerator const* root,