Convert: Move access to CurrentBinaryDirectory out of loops

This commit is contained in:
Stephen Kelly 2016-09-06 23:52:42 +02:00
parent 21b5fdf9a3
commit 839c65bca0
8 changed files with 42 additions and 41 deletions

View File

@ -189,6 +189,8 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
cmGeneratedFileStream fcStream(fcName.c_str()); cmGeneratedFileStream fcStream(fcName.c_str());
fcStream << "# Remove fortran modules provided by this target.\n"; fcStream << "# Remove fortran modules provided by this target.\n";
fcStream << "FILE(REMOVE"; fcStream << "FILE(REMOVE";
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (std::set<std::string>::const_iterator i = provides.begin(); for (std::set<std::string>::const_iterator i = provides.begin();
i != provides.end(); ++i) { i != provides.end(); ++i) {
std::string mod_upper = mod_dir; std::string mod_upper = mod_dir;
@ -205,18 +207,16 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
stamp += ".mod.stamp"; stamp += ".mod.stamp";
fcStream << "\n"; fcStream << "\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->ConvertToRelativePath( << this->LocalGenerator->ConvertToRelativePath(currentBinDir,
this->LocalGenerator->GetCurrentBinaryDirectory(), mod_lower)
mod_lower)
<< "\"\n"; << "\"\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->ConvertToRelativePath( << this->LocalGenerator->ConvertToRelativePath(currentBinDir,
this->LocalGenerator->GetCurrentBinaryDirectory(), mod_upper)
mod_upper)
<< "\"\n"; << "\"\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->ConvertToRelativePath( << this->LocalGenerator->ConvertToRelativePath(currentBinDir,
this->LocalGenerator->GetCurrentBinaryDirectory(), stamp) stamp)
<< "\"\n"; << "\"\n";
} }
fcStream << " )\n"; fcStream << " )\n";

View File

@ -319,18 +319,15 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
std::string cache = this->GetCMakeInstance()->GetHomeOutputDirectory(); std::string cache = this->GetCMakeInstance()->GetHomeOutputDirectory();
cache += "/CMakeCache.txt"; cache += "/CMakeCache.txt";
std::string currentBinDir = lg->GetCurrentBinaryDirectory();
// Save the list to the cmake file. // Save the list to the cmake file.
cmakefileStream cmakefileStream
<< "# The top level Makefile was generated from the following files:\n" << "# The top level Makefile was generated from the following files:\n"
<< "set(CMAKE_MAKEFILE_DEPENDS\n" << "set(CMAKE_MAKEFILE_DEPENDS\n"
<< " \"" << " \"" << lg->ConvertToRelativePath(currentBinDir, cache) << "\"\n";
<< lg->ConvertToRelativePath(lg->GetCurrentBinaryDirectory(), cache)
<< "\"\n";
for (std::vector<std::string>::const_iterator i = lfiles.begin(); for (std::vector<std::string>::const_iterator i = lfiles.begin();
i != lfiles.end(); ++i) { i != lfiles.end(); ++i) {
cmakefileStream << " \"" cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, *i)
<< lg->ConvertToRelativePath(
lg->GetCurrentBinaryDirectory(), *i)
<< "\"\n"; << "\"\n";
} }
cmakefileStream << " )\n\n"; cmakefileStream << " )\n\n";
@ -344,12 +341,9 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
cmakefileStream << "# The corresponding makefile is:\n" cmakefileStream << "# The corresponding makefile is:\n"
<< "set(CMAKE_MAKEFILE_OUTPUTS\n" << "set(CMAKE_MAKEFILE_OUTPUTS\n"
<< " \"" << " \""
<< lg->ConvertToRelativePath(lg->GetCurrentBinaryDirectory(), << lg->ConvertToRelativePath(currentBinDir, makefileName)
makefileName)
<< "\"\n" << "\"\n"
<< " \"" << " \"" << lg->ConvertToRelativePath(currentBinDir, check)
<< lg->ConvertToRelativePath(lg->GetCurrentBinaryDirectory(),
check)
<< "\"\n"; << "\"\n";
cmakefileStream << " )\n\n"; cmakefileStream << " )\n\n";

View File

@ -382,6 +382,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
{ {
VisualStudioFolders.clear(); VisualStudioFolders.clear();
std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin(); for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
tt != projectTargets.end(); ++tt) { tt != projectTargets.end(); ++tt) {
cmGeneratorTarget const* target = *tt; cmGeneratorTarget const* target = *tt;
@ -405,8 +406,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
if (vcprojName) { if (vcprojName) {
cmLocalGenerator* lg = target->GetLocalGenerator(); cmLocalGenerator* lg = target->GetLocalGenerator();
std::string dir = lg->GetCurrentBinaryDirectory(); std::string dir = lg->GetCurrentBinaryDirectory();
dir = root->ConvertToRelativePath(root->GetCurrentBinaryDirectory(), dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
dir.c_str());
if (dir == ".") { if (dir == ".") {
dir = ""; // msbuild cannot handle ".\" prefix dir = ""; // msbuild cannot handle ".\" prefix
} }

View File

@ -177,11 +177,11 @@ void cmLocalGenerator::GenerateTestFiles()
} }
typedef std::vector<cmState::Snapshot> vec_t; typedef std::vector<cmState::Snapshot> vec_t;
vec_t const& children = this->Makefile->GetStateSnapshot().GetChildren(); vec_t const& children = this->Makefile->GetStateSnapshot().GetChildren();
std::string parentBinDir = this->GetCurrentBinaryDirectory();
for (vec_t::const_iterator i = children.begin(); i != children.end(); ++i) { for (vec_t::const_iterator i = children.begin(); i != children.end(); ++i) {
// TODO: Use add_subdirectory instead? // TODO: Use add_subdirectory instead?
std::string outP = i->GetDirectory().GetCurrentBinary(); std::string outP = i->GetDirectory().GetCurrentBinary();
outP = outP = this->ConvertToRelativePath(parentBinDir, outP);
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), outP);
outP = cmOutputConverter::EscapeForCMake(outP); outP = cmOutputConverter::EscapeForCMake(outP);
fout << "subdirs(" << outP << ")" << std::endl; fout << "subdirs(" << outP << ")" << std::endl;
} }
@ -2243,11 +2243,11 @@ std::string cmLocalGenerator::ConstructComment(
std::string comment; std::string comment;
comment = "Generating "; comment = "Generating ";
const char* sep = ""; const char* sep = "";
std::string currentBinaryDir = this->GetCurrentBinaryDirectory();
for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin(); for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
o != ccg.GetOutputs().end(); ++o) { o != ccg.GetOutputs().end(); ++o) {
comment += sep; comment += sep;
comment += comment += this->ConvertToRelativePath(currentBinaryDir, *o);
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), *o);
sep = ", "; sep = ", ";
} }
return comment; return comment;

View File

@ -952,6 +952,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// Add each command line to the set of commands. // Add each command line to the set of commands.
std::vector<std::string> commands1; std::vector<std::string> commands1;
std::string currentBinDir = this->GetCurrentBinaryDirectory();
for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) { for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
// Build the command line in a single string. // Build the command line in a single string.
std::string cmd = ccg.GetCommand(c); std::string cmd = ccg.GetCommand(c);
@ -976,8 +977,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// working directory will be the start-output directory. // working directory will be the start-output directory.
bool had_slash = cmd.find('/') != cmd.npos; bool had_slash = cmd.find('/') != cmd.npos;
if (workingDir.empty()) { if (workingDir.empty()) {
cmd = cmd = this->ConvertToRelativePath(currentBinDir, cmd);
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cmd);
} }
bool has_slash = cmd.find('/') != cmd.npos; bool has_slash = cmd.find('/') != cmd.npos;
if (had_slash && !has_slash) { if (had_slash && !has_slash) {
@ -1069,7 +1069,8 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
std::vector<std::string>& commands, const std::vector<std::string>& files, std::vector<std::string>& commands, const std::vector<std::string>& files,
cmGeneratorTarget* target, const char* filename) cmGeneratorTarget* target, const char* filename)
{ {
std::string cleanfile = this->GetCurrentBinaryDirectory(); std::string currentBinDir = this->GetCurrentBinaryDirectory();
std::string cleanfile = currentBinDir;
cleanfile += "/"; cleanfile += "/";
cleanfile += this->GetTargetDirectory(target); cleanfile += this->GetTargetDirectory(target);
cleanfile += "/cmake_clean"; cleanfile += "/cmake_clean";
@ -1087,8 +1088,7 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
fout << "file(REMOVE_RECURSE\n"; fout << "file(REMOVE_RECURSE\n";
for (std::vector<std::string>::const_iterator f = files.begin(); for (std::vector<std::string>::const_iterator f = files.begin();
f != files.end(); ++f) { f != files.end(); ++f) {
std::string fc = std::string fc = this->ConvertToRelativePath(currentBinDir, *f);
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), *f);
fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n"; fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n";
} }
fout << ")\n"; fout << ")\n";

View File

@ -1298,10 +1298,11 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
std::ostream& fout, ItemVector const& libs) std::ostream& fout, ItemVector const& libs)
{ {
cmLocalVisualStudio7Generator* lg = this->LocalGenerator; cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
std::string currentBinDir = lg->GetCurrentBinaryDirectory();
for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
if (l->IsPath) { if (l->IsPath) {
std::string rel = lg->ConvertToRelativePath( std::string rel =
lg->GetCurrentBinaryDirectory(), l->Value.c_str()); lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " "; fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
} else if (!l->Target || } else if (!l->Target ||
l->Target->GetType() != cmState::INTERFACE_LIBRARY) { l->Target->GetType() != cmState::INTERFACE_LIBRARY) {
@ -1316,13 +1317,13 @@ void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
// VS < 8 does not support per-config source locations so we // VS < 8 does not support per-config source locations so we
// list object library content on the link line instead. // list object library content on the link line instead.
cmLocalVisualStudio7Generator* lg = this->LocalGenerator; cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
std::string currentBinDir = lg->GetCurrentBinaryDirectory();
std::vector<std::string> objs; std::vector<std::string> objs;
gt->UseObjectLibraries(objs, ""); gt->UseObjectLibraries(objs, "");
const char* sep = isep ? isep : ""; const char* sep = isep ? isep : "";
for (std::vector<std::string>::const_iterator oi = objs.begin(); for (std::vector<std::string>::const_iterator oi = objs.begin();
oi != objs.end(); ++oi) { oi != objs.end(); ++oi) {
std::string rel = std::string rel = lg->ConvertToRelativePath(currentBinDir, oi->c_str());
lg->ConvertToRelativePath(lg->GetCurrentBinaryDirectory(), oi->c_str());
fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
sep = " "; sep = " ";
} }
@ -1332,6 +1333,7 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
std::ostream& fout, std::vector<std::string> const& dirs) std::ostream& fout, std::vector<std::string> const& dirs)
{ {
const char* comma = ""; const char* comma = "";
std::string currentBinDir = this->GetCurrentBinaryDirectory();
for (std::vector<std::string>::const_iterator d = dirs.begin(); for (std::vector<std::string>::const_iterator d = dirs.begin();
d != dirs.end(); ++d) { d != dirs.end(); ++d) {
// Remove any trailing slash and skip empty paths. // Remove any trailing slash and skip empty paths.
@ -1345,8 +1347,8 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
// Switch to a relative path specification if it is shorter. // Switch to a relative path specification if it is shorter.
if (cmSystemTools::FileIsFullPath(dir.c_str())) { if (cmSystemTools::FileIsFullPath(dir.c_str())) {
std::string rel = this->ConvertToRelativePath( std::string rel =
this->GetCurrentBinaryDirectory(), dir.c_str()); this->ConvertToRelativePath(currentBinDir, dir.c_str());
if (rel.size() < dir.size()) { if (rel.size() < dir.size()) {
dir = rel; dir = rel;
} }

View File

@ -162,6 +162,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
// files for this target. // files for this target.
std::vector<cmSourceFile const*> customCommands; std::vector<cmSourceFile const*> customCommands;
this->GeneratorTarget->GetCustomCommands(customCommands, config); this->GeneratorTarget->GetCustomCommands(customCommands, config);
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (std::vector<cmSourceFile const*>::const_iterator si = for (std::vector<cmSourceFile const*>::const_iterator si =
customCommands.begin(); customCommands.begin();
si != customCommands.end(); ++si) { si != customCommands.end(); ++si) {
@ -172,8 +174,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
const std::vector<std::string>& outputs = ccg.GetOutputs(); const std::vector<std::string>& outputs = ccg.GetOutputs();
for (std::vector<std::string>::const_iterator o = outputs.begin(); for (std::vector<std::string>::const_iterator o = outputs.begin();
o != outputs.end(); ++o) { o != outputs.end(); ++o) {
this->CleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath( this->CleanFiles.push_back(
this->LocalGenerator->GetCurrentBinaryDirectory(), *o)); this->LocalGenerator->ConvertToRelativePath(currentBinDir, *o));
} }
} }
} }
@ -1180,11 +1182,12 @@ void cmMakefileTargetGenerator::WriteObjectsVariable(
<< this->GeneratorTarget->GetName() << "\n" << this->GeneratorTarget->GetName() << "\n"
<< variableNameExternal << " ="; << variableNameExternal << " =";
/* clang-format on */ /* clang-format on */
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (std::vector<std::string>::const_iterator i = for (std::vector<std::string>::const_iterator i =
this->ExternalObjects.begin(); this->ExternalObjects.begin();
i != this->ExternalObjects.end(); ++i) { i != this->ExternalObjects.end(); ++i) {
object = this->LocalGenerator->ConvertToRelativePath( object = this->LocalGenerator->ConvertToRelativePath(currentBinDir, *i);
this->LocalGenerator->GetCurrentBinaryDirectory(), *i);
*this->BuildFileStream << " " << lineContinue << "\n" *this->BuildFileStream << " " << lineContinue << "\n"
<< this->Makefile->GetSafeDefinition( << this->Makefile->GetSafeDefinition(
"CMAKE_OBJECT_NAME"); "CMAKE_OBJECT_NAME");

View File

@ -2415,10 +2415,12 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
{ {
typedef cmComputeLinkInformation::ItemVector ItemVector; typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector libs = cli.GetItems(); ItemVector libs = cli.GetItems();
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
if (l->IsPath) { if (l->IsPath) {
std::string path = this->LocalGenerator->ConvertToRelativePath( std::string path = this->LocalGenerator->ConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), l->Value.c_str()); currentBinDir, l->Value.c_str());
this->ConvertToWindowsSlash(path); this->ConvertToWindowsSlash(path);
libVec.push_back(path); libVec.push_back(path);
} else if (!l->Target || } else if (!l->Target ||