diff options
author | Vitaly Stakhovsky <vvs31415@gitlab.org> | 2018-01-23 01:47:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-23 16:10:04 (GMT) |
commit | 25243014e5367108604e03682b04dd5ec1e93673 (patch) | |
tree | 768fba75536e0f500660b05a4050a21d16099925 | |
parent | b058d92b33ab37a56ac4dcf2f1e49aec89f554e3 (diff) | |
download | CMake-25243014e5367108604e03682b04dd5ec1e93673.zip CMake-25243014e5367108604e03682b04dd5ec1e93673.tar.gz CMake-25243014e5367108604e03682b04dd5ec1e93673.tar.bz2 |
cmMakefile: use std::string in more methods; cleanup c_str()s
Follow up commit 969c1f94ae (cmSourceGroup: code improvements; use
std::string and C++11 loops, 2017-01-10).
-rw-r--r-- | Source/cmAddExecutableCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmExtraEclipseCDT4Generator.cxx | 2 | ||||
-rw-r--r-- | Source/cmGhsMultiTargetGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 43 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 4 |
7 files changed, 31 insertions, 30 deletions
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index b9e200a..2e95032 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -164,7 +164,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args, std::vector<std::string> srclists(s, args.end()); cmTarget* tgt = - this->Makefile->AddExecutable(exename.c_str(), srclists, excludeFromAll); + this->Makefile->AddExecutable(exename, srclists, excludeFromAll); if (use_win32) { tgt->SetProperty("WIN32_EXECUTABLE", "ON"); } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index a200385..1fc0828 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -498,7 +498,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) // Add the file to the list of sources. std::string const& source = sf->GetFullPath(); cmSourceGroup* sourceGroup = - makefile->FindSourceGroup(source.c_str(), sourceGroups); + makefile->FindSourceGroup(source, sourceGroups); sourceGroup->AssignSource(sf); } diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index b3e3393..d459436 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -486,7 +486,7 @@ void cmGhsMultiTargetGenerator::WriteSources( for (std::vector<cmSourceFile*>::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { std::vector<cmSourceGroup> sourceGroups(this->Makefile->GetSourceGroups()); - char const* sourceFullPath = (*si)->GetFullPath().c_str(); + std::string const& sourceFullPath = (*si)->GetFullPath(); cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(sourceFullPath, sourceGroups); std::string sgPath = sourceGroup->GetFullName(); @@ -604,7 +604,7 @@ std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory( dir_max += "/"; std::vector<cmSourceGroup> sourceGroups( localGhsMultiGenerator->GetMakefile()->GetSourceGroups()); - char const* const sourceFullPath = sourceFile->GetFullPath().c_str(); + std::string const& sourceFullPath = sourceFile->GetFullPath(); cmSourceGroup* sourceGroup = localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath, sourceGroups); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 59c20a9..b55fa49 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1410,7 +1410,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // Add the file to the list of sources. std::string const source = sf->GetFullPath(); cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); + this->Makefile->FindSourceGroup(source, sourceGroups); sourceGroup->AssignSource(sf); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index eeeb54f..c12cd9e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -664,7 +664,7 @@ struct file_not_persistent bool operator()(const std::string& path) const { return !(path.find("CMakeTmp") == std::string::npos && - cmSystemTools::FileExists(path.c_str())); + cmSystemTools::FileExists(path)); } }; } @@ -755,8 +755,9 @@ void cmMakefile::AddCustomCommandToTarget( return; } + cmTarget& t = ti->second; if (objLibraryCommands == RejectObjectLibraryCommands && - ti->second.GetType() == cmStateEnums::OBJECT_LIBRARY) { + t.GetType() == cmStateEnums::OBJECT_LIBRARY) { std::ostringstream e; e << "Target \"" << target << "\" is an OBJECT library " @@ -764,7 +765,7 @@ void cmMakefile::AddCustomCommandToTarget( this->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } - if (ti->second.GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (t.GetType() == cmStateEnums::INTERFACE_LIBRARY) { std::ostringstream e; e << "Target \"" << target << "\" is an INTERFACE library " @@ -791,13 +792,13 @@ void cmMakefile::AddCustomCommandToTarget( cc.SetDepfile(depfile); switch (type) { case cmTarget::PRE_BUILD: - ti->second.AddPreBuildCommand(cc); + t.AddPreBuildCommand(cc); break; case cmTarget::PRE_LINK: - ti->second.AddPreLinkCommand(cc); + t.AddPreLinkCommand(cc); break; case cmTarget::POST_BUILD: - ti->second.AddPostBuildCommand(cc); + t.AddPostBuildCommand(cc); break; } } @@ -1180,14 +1181,14 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) static cmsys::RegularExpression valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$"); // Make sure the definition matches. - if (!valid.find(def.c_str())) { + if (!valid.find(def)) { return false; } // Definitions with non-trivial values require a policy check. static cmsys::RegularExpression trivial( "^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$"); - if (!trivial.find(def.c_str())) { + if (!trivial.find(def)) { // This definition has a non-trivial value. switch (this->GetPolicyStatus(cmPolicies::CMP0005)) { case cmPolicies::WARN: @@ -1409,9 +1410,9 @@ void cmMakefile::Configure() // make sure the CMakeFiles dir is there std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary(); filesDir += cmake::GetCMakeFilesDirectory(); - cmSystemTools::MakeDirectory(filesDir.c_str()); + cmSystemTools::MakeDirectory(filesDir); - assert(cmSystemTools::FileExists(currentStart.c_str(), true)); + assert(cmSystemTools::FileExists(currentStart, true)); this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); cmListFile listFile; @@ -1572,7 +1573,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, newSnapshot.GetDirectory().SetCurrentSource(srcPath); newSnapshot.GetDirectory().SetCurrentBinary(binPath); - cmSystemTools::MakeDirectory(binPath.c_str()); + cmSystemTools::MakeDirectory(binPath); cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot); this->GetGlobalGenerator()->AddMakefile(subMf); @@ -1876,7 +1877,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname, return target; } -cmTarget* cmMakefile::AddExecutable(const char* exeName, +cmTarget* cmMakefile::AddExecutable(const std::string& exeName, const std::vector<std::string>& srcs, bool excludeFromAll) { @@ -1936,7 +1937,7 @@ cmSourceFile* cmMakefile::GetSourceFileWithOutput( { // If the queried path is not absolute we use the backward compatible // linear-time search for an output with a matching suffix. - if (!cmSystemTools::FileIsFullPath(name.c_str())) { + if (!cmSystemTools::FileIsFullPath(name)) { return this->LinearGetSourceFileWithOutput(name); } // Otherwise we use an efficient lookup map. @@ -2055,7 +2056,7 @@ cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(const std::string& name) * inherited ones. */ cmSourceGroup* cmMakefile::FindSourceGroup( - const char* source, std::vector<cmSourceGroup>& groups) const + const std::string& source, std::vector<cmSourceGroup>& groups) const { // First search for a group that lists the file explicitly. for (std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin(); @@ -3232,7 +3233,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, this->IsSourceFileTryCompile = fast; // does the binary directory exist ? If not create it... if (!cmSystemTools::FileIsDirectory(bindir)) { - cmSystemTools::MakeDirectory(bindir.c_str()); + cmSystemTools::MakeDirectory(bindir); } // change to the tests directory and run cmake @@ -3410,7 +3411,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const cmSystemTools::ConvertToUnixSlashes(itempl); itempl += "/"; itempl += filename; - if (cmSystemTools::FileExists(itempl.c_str())) { + if (cmSystemTools::FileExists(itempl)) { moduleInCMakeModulePath = itempl; break; } @@ -3422,7 +3423,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const moduleInCMakeRoot += "/Modules/"; moduleInCMakeRoot += filename; cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot); - if (!cmSystemTools::FileExists(moduleInCMakeRoot.c_str())) { + if (!cmSystemTools::FileExists(moduleInCMakeRoot)) { moduleInCMakeRoot.clear(); } @@ -3554,11 +3555,11 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, this->AddCMakeOutputFile(soutfile); mode_t perm = 0; - cmSystemTools::GetPermissions(sinfile.c_str(), perm); + cmSystemTools::GetPermissions(sinfile, perm); std::string::size_type pos = soutfile.rfind('/'); if (pos != std::string::npos) { std::string path = soutfile.substr(0, pos); - cmSystemTools::MakeDirectory(path.c_str()); + cmSystemTools::MakeDirectory(path); } if (copyonly) { @@ -3618,7 +3619,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, soutfile.c_str())) { res = 0; } else { - cmSystemTools::SetPermissions(soutfile.c_str(), perm); + cmSystemTools::SetPermissions(soutfile, perm); } cmSystemTools::RemoveFile(tempOutputFile); } @@ -3707,7 +3708,7 @@ void cmMakefile::AddCMakeDependFilesFromUser() cmSystemTools::ExpandListArgument(deps_str, deps); } for (std::string const& dep : deps) { - if (cmSystemTools::FileIsFullPath(dep.c_str())) { + if (cmSystemTools::FileIsFullPath(dep)) { this->AddCMakeDependFile(dep); } else { std::string f = this->GetCurrentSourceDirectory(); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index f06e2ff..2721277 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -180,7 +180,7 @@ public: /** * Add an executable to the build. */ - cmTarget* AddExecutable(const char* exename, + cmTarget* AddExecutable(const std::string& exename, const std::vector<std::string>& srcs, bool excludeFromAll = false); @@ -516,7 +516,7 @@ public: /** * find what source group this source is in */ - cmSourceGroup* FindSourceGroup(const char* source, + cmSourceGroup* FindSourceGroup(const std::string& source, std::vector<cmSourceGroup>& groups) const; #endif diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 1b09600..0ea8976 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1366,7 +1366,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() si != sources.end(); ++si) { std::string const& source = si->Source->GetFullPath(); cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); + this->Makefile->FindSourceGroup(source, sourceGroups); groupsUsed.insert(sourceGroup); } @@ -1538,7 +1538,7 @@ void cmVisualStudio10TargetGenerator::WriteGroupSources( cmSourceFile const* sf = s.SourceFile; std::string const& source = sf->GetFullPath(); cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); + this->Makefile->FindSourceGroup(source, sourceGroups); std::string const& filter = sourceGroup->GetFullName(); this->WriteString("<", 2); std::string path = this->ConvertPath(source, s.RelativePath); |