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

View File

@@ -1065,6 +1065,8 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
std::string makeProgramSelected =
this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
std::string const slnFile = this->GetSLNFile(projectDir, projectName);
// Check if the caller explicitly requested a devenv tool.
std::string makeProgramLower = makeProgramSelected;
cmSystemTools::LowerCase(makeProgramLower);
@@ -1079,12 +1081,6 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
// an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
cmSlnData slnData;
{
std::string slnFile;
if (!projectDir.empty()) {
slnFile = cmStrCat(projectDir, '/');
}
slnFile += projectName;
slnFile += ".sln";
cmVisualStudioSlnParser parser;
if (parser.ParseFile(slnFile, slnData,
cmVisualStudioSlnParser::DataGroupAll)) {
@@ -1125,7 +1121,7 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
makeCommand.Add(makeProgramSelected);
if (tname == "clean"_s) {
makeCommand.Add(cmStrCat(projectName, ".sln"));
makeCommand.Add(slnFile);
makeCommand.Add("/t:Clean");
} else {
std::string targetProject = cmStrCat(tname, ".vcxproj");

View File

@@ -206,15 +206,16 @@ char const* cmGlobalVisualStudio7Generator::ExternalProjectType(
std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalVisualStudio7Generator::GenerateBuildCommand(
std::string const& makeProgram, std::string const& projectName,
std::string const& /*projectDir*/,
std::vector<std::string> const& targetNames, std::string const& config,
int /*jobs*/, bool /*verbose*/, cmBuildOptions /*buildOptions*/,
std::vector<std::string> const& makeOptions)
std::string const& projectDir, std::vector<std::string> const& targetNames,
std::string const& config, int /*jobs*/, bool /*verbose*/,
cmBuildOptions /*buildOptions*/, std::vector<std::string> const& makeOptions)
{
// Select the caller- or user-preferred make program, else devenv.
std::string makeProgramSelected =
this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
std::string const slnFile = this->GetSLNFile(projectDir, projectName);
// Ignore the above preference if it is msbuild.
// Assume any other value is either a devenv or
// command-line compatible with devenv.
@@ -249,7 +250,7 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand(
GeneratedMakeCommand makeCommand;
makeCommand.RequiresOutputForward = requiresOutputForward;
makeCommand.Add(makeProgramSelected);
makeCommand.Add(cmStrCat(projectName, ".sln"));
makeCommand.Add(slnFile);
makeCommand.Add((clean ? "/clean" : "/build"));
makeCommand.Add((config.empty() ? "Debug" : config));
makeCommand.Add("/project");

View File

@@ -306,7 +306,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
std::string argS = cmStrCat("-S", lg.GetSourceDirectory());
std::string argB = cmStrCat("-B", lg.GetBinaryDirectory());
std::string const sln =
cmStrCat(lg.GetBinaryDirectory(), '/', lg.GetProjectName(), ".sln");
this->GetSLNFile(lg.GetBinaryDirectory(), lg.GetProjectName());
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list",
stampList, "--vs-solution-file", sln });

View File

@@ -38,14 +38,6 @@
#include "cmUuid.h"
#include "cmake.h"
namespace {
std::string GetSLNFile(cmLocalGenerator const* root)
{
return cmStrCat(root->GetCurrentBinaryDirectory(), '/',
root->GetProjectName(), ".sln");
}
}
cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm)
: cmGlobalGenerator(cm)
{
@@ -771,7 +763,7 @@ bool cmGlobalVisualStudioGenerator::Open(std::string const& bindir,
std::string const& projectName,
bool dryRun)
{
std::string sln = cmStrCat(bindir, '/', projectName, ".sln");
std::string sln = this->GetSLNFile(bindir, projectName);
if (dryRun) {
return cmSystemTools::FileExists(sln, true);
@@ -1092,6 +1084,24 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
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()
{
// first do the superclass method

View File

@@ -196,6 +196,10 @@ protected:
cm::VS::Solution::Folder* CreateSolutionFolder(
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 GenerateSolution(cmLocalGenerator const* root,