From 23e8364aedcbeb7ce606b6075c98827e52f0c7f6 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Tue, 14 May 2019 09:16:11 -0400 Subject: Source: std::string related cleanup --- Source/cmCoreTryCompile.cxx | 10 +++--- Source/cmExtraCodeBlocksGenerator.cxx | 47 ++++++++++++-------------- Source/cmExtraCodeBlocksGenerator.h | 7 ++-- Source/cmGlobalMSYSMakefileGenerator.cxx | 6 ++-- Source/cmGlobalNinjaGenerator.cxx | 4 +-- Source/cmGlobalUnixMakefileGenerator3.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.cxx | 16 ++++----- Source/cmGlobalVisualStudio7Generator.h | 4 +-- Source/cmGlobalVisualStudio8Generator.cxx | 4 +-- Source/cmGlobalXCodeGenerator.cxx | 29 ++++++++-------- Source/cmLocalNinjaGenerator.cxx | 2 +- Source/cmMakefileExecutableTargetGenerator.cxx | 2 +- Source/cmMakefileTargetGenerator.cxx | 5 +-- Source/cmNinjaNormalTargetGenerator.cxx | 2 +- Source/cmNinjaTargetGenerator.cxx | 8 ++--- Source/cmOutputRequiredFilesCommand.cxx | 6 ++-- Source/cmTryRunCommand.cxx | 18 +++++----- Source/cmVisualStudio10TargetGenerator.cxx | 6 ++-- 18 files changed, 87 insertions(+), 91 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 2f62db1..f12ef0b 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -122,8 +122,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, } } - const char* sourceDirectory = argv[2].c_str(); - const char* projectName = nullptr; + std::string sourceDirectory = argv[2]; + std::string projectName; std::string targetName; std::vector cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0] std::vector compileDefs; @@ -309,7 +309,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, doing = DoingNone; } else if (i == 3) { this->SrcFileSignature = false; - projectName = argv[i].c_str(); + projectName = argv[i]; } else if (i == 4 && !this->SrcFileSignature) { targetName = argv[i]; } else { @@ -480,7 +480,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, // we need to create a directory and CMakeLists file etc... // first create the directories - sourceDirectory = this->BinaryDirectory.c_str(); + sourceDirectory = this->BinaryDirectory; // now create a CMakeLists.txt file in that directory FILE* fout = cmsys::SystemTools::Fopen(outFileName, "w"); @@ -950,7 +950,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, << " '" << copyFile << "'\n"; /* clang-format on */ if (!this->FindErrorMessage.empty()) { - emsg << this->FindErrorMessage.c_str(); + emsg << this->FindErrorMessage; } if (copyFileError.empty()) { this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str()); diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 93ff8f4..c6e44e3 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -280,8 +280,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( xml.StartElement("Build"); - this->AppendTarget(xml, "all", nullptr, make.c_str(), lgs[0], - compiler.c_str(), makeArgs); + this->AppendTarget(xml, "all", nullptr, make, lgs[0], compiler, makeArgs); // add all executable and library targets and some of the GLOBAL // and UTILITY targets @@ -294,8 +293,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // Only add the global targets from CMAKE_BINARY_DIR, // not from the subdirs if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) { - this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, nullptr, make, lg, compiler, + makeArgs); } } break; case cmStateEnums::UTILITY: @@ -310,8 +309,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( break; } - this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, nullptr, make, lg, compiler, + makeArgs); break; case cmStateEnums::EXECUTABLE: case cmStateEnums::STATIC_LIBRARY: @@ -319,12 +318,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: { cmGeneratorTarget* gt = target; - this->AppendTarget(xml, targetName, gt, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, gt, make, lg, compiler, + makeArgs); std::string fastTarget = targetName; fastTarget += "/fast"; - this->AppendTarget(xml, fastTarget, gt, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, fastTarget, gt, make, lg, compiler, + makeArgs); } break; default: break; @@ -378,7 +377,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( std::string const& fullPath = s->GetFullPath(); // Check file position relative to project root dir. - const std::string& relative = + const std::string relative = cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath); // Do not add this file if it has ".." in relative path and // if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on. @@ -454,7 +453,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( } // Add CMakeLists.txt - tree.BuildUnit(xml, std::string(mf->GetHomeDirectory()) + "/"); + tree.BuildUnit(xml, mf->GetHomeDirectory() + "/"); xml.EndElement(); // Project xml.EndElement(); // CodeBlocks_project_file @@ -489,8 +488,8 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile( // Generate the xml code for one target. void cmExtraCodeBlocksGenerator::AppendTarget( cmXMLWriter& xml, const std::string& targetName, cmGeneratorTarget* target, - const char* make, const cmLocalGenerator* lg, const char* compiler, - const std::string& makeFlags) + const std::string& make, const cmLocalGenerator* lg, + const std::string& compiler, const std::string& makeFlags) { cmMakefile const* makefile = lg->GetMakefile(); std::string makefileName = lg->GetCurrentBinaryDirectory(); @@ -613,25 +612,23 @@ void cmExtraCodeBlocksGenerator::AppendTarget( xml.StartElement("Build"); xml.Attribute( "command", - this->BuildMakeCommand(make, makefileName.c_str(), targetName, makeFlags)); + this->BuildMakeCommand(make, makefileName, targetName, makeFlags)); xml.EndElement(); xml.StartElement("CompileFile"); - xml.Attribute("command", - this->BuildMakeCommand(make, makefileName.c_str(), "\"$file\"", - makeFlags)); + xml.Attribute( + "command", + this->BuildMakeCommand(make, makefileName, "\"$file\"", makeFlags)); xml.EndElement(); xml.StartElement("Clean"); xml.Attribute( - "command", - this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)); + "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags)); xml.EndElement(); xml.StartElement("DistClean"); xml.Attribute( - "command", - this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)); + "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags)); xml.EndElement(); xml.EndElement(); // MakeCommands @@ -725,8 +722,8 @@ int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target) // Create the command line for building the given target using the selected // make std::string cmExtraCodeBlocksGenerator::BuildMakeCommand( - const std::string& make, const char* makefile, const std::string& target, - const std::string& makeFlags) + const std::string& make, const std::string& makefile, + const std::string& target, const std::string& makeFlags) { std::string command = make; if (!makeFlags.empty()) { @@ -747,7 +744,7 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand( } else if (generator == "MinGW Makefiles") { // no escaping of spaces in this case, see // https://gitlab.kitware.com/cmake/cmake/issues/10014 - std::string makefileName = makefile; + std::string const& makefileName = makefile; command += " -f \""; command += makefileName; command += "\" "; diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h index be3af25..173e284 100644 --- a/Source/cmExtraCodeBlocksGenerator.h +++ b/Source/cmExtraCodeBlocksGenerator.h @@ -42,12 +42,13 @@ private: std::string GetCBCompilerId(const cmMakefile* mf); int GetCBTargetType(cmGeneratorTarget* target); - std::string BuildMakeCommand(const std::string& make, const char* makefile, + std::string BuildMakeCommand(const std::string& make, + const std::string& makefile, const std::string& target, const std::string& makeFlags); void AppendTarget(cmXMLWriter& xml, const std::string& targetName, - cmGeneratorTarget* target, const char* make, - const cmLocalGenerator* lg, const char* compiler, + cmGeneratorTarget* target, const std::string& make, + const cmLocalGenerator* lg, const std::string& compiler, const std::string& makeFlags); }; diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index 606febe..7b58389 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -48,7 +48,7 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( const std::string& makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::vector locations; - std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str()); + std::string makeloc = cmSystemTools::GetProgramPath(makeProgram); locations.push_back(this->FindMinGW(makeloc)); locations.push_back(makeloc); locations.push_back("/mingw/bin"); @@ -77,8 +77,8 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() && !(1 == l.size() && l[0] == "NONE")) { cmSystemTools::Error( - "CMAKE_AR was not found, please set to archive program. ", - mf->GetDefinition("CMAKE_AR")); + "CMAKE_AR was not found, please set to archive program. " + + mf->GetSafeDefinition("CMAKE_AR")); } } diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 1b973e0..8d69f3f 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -571,7 +571,7 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() static std::string const k_DYNDEP_ = ".dyndep-"; std::string::size_type pos = this->NinjaVersion.find(k_DYNDEP_); if (pos != std::string::npos) { - const char* fv = this->NinjaVersion.c_str() + pos + k_DYNDEP_.size(); + const char* fv = &this->NinjaVersion[pos + k_DYNDEP_.size()]; cmSystemTools::StringToULong(fv, &this->NinjaSupportsDyndeps); } } @@ -1245,7 +1245,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) for (std::string const& i : unknownExplicitDepends) { // verify the file is in the build directory std::string const absDepPath = - cmSystemTools::CollapseFullPath(i, rootBuildDirectory.c_str()); + cmSystemTools::CollapseFullPath(i, rootBuildDirectory); bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath, rootBuildDirectory); if (inBuildDir) { diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 65d816e..1ea3673 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -169,7 +169,7 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( { if (this->CommandDatabase == nullptr) { std::string commandDatabaseName = - std::string(this->GetCMakeInstance()->GetHomeOutputDirectory()) + + this->GetCMakeInstance()->GetHomeOutputDirectory() + "/compile_commands.json"; this->CommandDatabase = new cmGeneratedFileStream(commandDatabaseName); *this->CommandDatabase << "[" << std::endl; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index c31dbf4..8764ee4 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -45,7 +45,6 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( cmake* cm, std::string const& platformInGeneratorName) : cmGlobalVisualStudioGenerator(cm, platformInGeneratorName) { - this->IntelProjectVersion = 0; this->DevEnvCommandInitialized = false; this->MasmEnabled = false; this->NasmEnabled = false; @@ -54,21 +53,20 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator() { - free(this->IntelProjectVersion); } // Package GUID of Intel Visual Fortran plugin to VS IDE #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}" -const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion() +const std::string& cmGlobalVisualStudio7Generator::GetIntelProjectVersion() { - if (!this->IntelProjectVersion) { + if (this->IntelProjectVersion.empty()) { // Compute the version of the Intel plugin to the VS IDE. // If the key does not exist then use a default guess. std::string intelVersion; std::string vskey = this->GetRegistryBase(); vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion"; - cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion, + cmSystemTools::ReadRegistryValue(vskey, intelVersion, cmSystemTools::KeyWOW64_32); unsigned int intelVersionNumber = ~0u; sscanf(intelVersion.c_str(), "%u", &intelVersionNumber); @@ -81,7 +79,7 @@ const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion() } else { // Version <= 9: use ProductVersion from registry. } - this->IntelProjectVersion = strdup(intelVersion.c_str()); + this->IntelProjectVersion = intelVersion; } return this->IntelProjectVersion; } @@ -237,7 +235,7 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand( GeneratedMakeCommand makeCommand; makeCommand.RequiresOutputForward = requiresOutputForward; makeCommand.Add(makeProgramSelected); - makeCommand.Add(std::string(projectName) + ".sln"); + makeCommand.Add(projectName + ".sln"); makeCommand.Add((clean ? "/clean" : "/build")); makeCommand.Add((config.empty() ? "Debug" : config)); makeCommand.Add("/project"); @@ -270,7 +268,7 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s, cmMakefile* mf) { mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION", - this->GetIntelProjectVersion()); + this->GetIntelProjectVersion().c_str()); return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf); } @@ -615,7 +613,7 @@ std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name) { std::string const& guidStoreName = name + "_GUID_CMAKE"; if (const char* storedGUID = - this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) { + this->CMakeInstance->GetCacheDefinition(guidStoreName)) { return std::string(storedGUID); } // Compute a GUID that is deterministic but unique to the build tree. diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 1e76383..f004afb 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -86,7 +86,7 @@ public: return false; } - const char* GetIntelProjectVersion(); + const std::string& GetIntelProjectVersion(); bool FindMakeProgram(cmMakefile* mf) override; @@ -163,7 +163,7 @@ protected: bool NasmEnabled; private: - char* IntelProjectVersion; + std::string IntelProjectVersion; std::string DevEnvCommand; bool DevEnvCommandInitialized; std::string GetVSMakeProgram() override { return this->GetDevEnvCommand(); } diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 21abdf7..0da9986 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -188,8 +188,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() commandLine.push_back("--check-stamp-list"); commandLine.push_back(stampList.c_str()); commandLine.push_back("--vs-solution-file"); - std::string const sln = std::string(lg->GetBinaryDirectory()) + "/" + - lg->GetProjectName() + ".sln"; + std::string const sln = + lg->GetBinaryDirectory() + "/" + lg->GetProjectName() + ".sln"; commandLine.push_back(sln); cmCustomCommandLines commandLines; commandLines.push_back(commandLine); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 6cbdefa..707757e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -202,7 +202,7 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( } } } - if (!versionFile.empty() && cmSystemTools::FileExists(versionFile.c_str())) { + if (!versionFile.empty() && cmSystemTools::FileExists(versionFile)) { parser.ParseFile(versionFile.c_str()); } else if (cmSystemTools::FileExists( "/Applications/Xcode.app/Contents/version.plist")) { @@ -479,7 +479,7 @@ void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root) this->CurrentXCodeHackMakefile = root->GetCurrentBinaryDirectory(); this->CurrentXCodeHackMakefile += "/CMakeScripts"; - cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str()); + cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile); this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make"; } @@ -600,7 +600,7 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( this->CurrentReRunCMakeMakefile = root->GetCurrentBinaryDirectory(); this->CurrentReRunCMakeMakefile += "/CMakeScripts"; - cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str()); + cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile); this->CurrentReRunCMakeMakefile += "/ReRunCMake.make"; cmGeneratedFileStream makefileStream(this->CurrentReRunCMakeMakefile); makefileStream.SetCopyIfDifferent(true); @@ -1026,8 +1026,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( std::string path = this->RelativeToSource(fullpath); std::string name = cmSystemTools::GetFilenameName(path); const char* sourceTree = - (cmSystemTools::FileIsFullPath(path.c_str()) ? "" - : "SOURCE_ROOT"); + cmSystemTools::FileIsFullPath(path) ? "" : "SOURCE_ROOT"; fileRef->AddAttribute("name", this->CreateString(name)); fileRef->AddAttribute("path", this->CreateString(path)); fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree)); @@ -1588,7 +1587,7 @@ std::string cmGlobalXCodeGenerator::ExtractFlagRegex(const char* exp, std::string::size_type offset = 0; - while (regex.find(flags.c_str() + offset)) { + while (regex.find(&flags[offset])) { const std::string::size_type startPos = offset + regex.start(matchIndex); const std::string::size_type endPos = offset + regex.end(matchIndex); const std::string::size_type size = endPos - startPos; @@ -1641,7 +1640,7 @@ void cmGlobalXCodeGenerator::AddCommandsToBuildPhase( { std::string dir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory(); dir += "/CMakeScripts"; - cmSystemTools::MakeDirectory(dir.c_str()); + cmSystemTools::MakeDirectory(dir); std::string makefile = dir; makefile += "/"; makefile += target->GetName(); @@ -1700,7 +1699,7 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } else { std::ostringstream str; str << "_buildpart_" << count++; - tname[&ccg.GetCC()] = std::string(target->GetName()) + str.str(); + tname[&ccg.GetCC()] = target->GetName() + str.str(); makefileStream << "\\\n\t" << tname[&ccg.GetCC()]; } } @@ -1824,8 +1823,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::string llang = gtgt->GetLinkerLanguage(configName); if (binary && llang.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - gtgt->GetName().c_str()); + "CMake can not determine linker language for target: " + + gtgt->GetName()); return; } std::string const& langForPreprocessor = llang; @@ -3014,10 +3013,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO")); cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (auto& CurrentConfigurationType : this->CurrentConfigurationTypes) { + for (const std::string& CurrentConfigurationType : + this->CurrentConfigurationTypes) { cmXCodeObject* buildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle); - const char* name = CurrentConfigurationType.c_str(); + const std::string& name = CurrentConfigurationType; buildStyle->AddAttribute("name", this->CreateString(name)); buildStyle->SetComment(name); cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -3263,8 +3263,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( { cmGeneratedFileStream makefileStream(this->CurrentXCodeHackMakefile); if (!makefileStream) { - cmSystemTools::Error("Could not create", - this->CurrentXCodeHackMakefile.c_str()); + cmSystemTools::Error("Could not create " + this->CurrentXCodeHackMakefile); return; } makefileStream.SetCopyIfDifferent(true); @@ -3401,7 +3400,7 @@ void cmGlobalXCodeGenerator::OutputXCodeProject( xcodeDir += "/"; xcodeDir += root->GetProjectName(); xcodeDir += ".xcodeproj"; - cmSystemTools::MakeDirectory(xcodeDir.c_str()); + cmSystemTools::MakeDirectory(xcodeDir); std::string xcodeProjFile = xcodeDir + "/project.pbxproj"; cmGeneratedFileStream fout(xcodeProjFile); fout.SetCopyIfDifferent(true); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index e6d4457..d9aafbf 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -69,7 +69,7 @@ void cmLocalNinjaGenerator::Generate() this->WritePools(this->GetRulesFileStream()); - const std::string showIncludesPrefix = + const std::string& showIncludesPrefix = this->GetMakefile()->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); if (!showIncludesPrefix.empty()) { cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(), diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index ebf5fc2..f42cd1c 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -107,7 +107,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( // Get the language to use for linking this library. std::string linkLanguage = "CUDA"; - std::string const objExt = + std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); // Build list of dependencies. diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 340e405..0f554a6 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1399,7 +1399,7 @@ void cmMakefileTargetGenerator::AppendTargetDepends( } // Loop over all library dependencies. - const char* cfg = this->LocalGenerator->GetConfigName().c_str(); + const std::string& cfg = this->LocalGenerator->GetConfigName(); if (cmComputeLinkInformation* cli = this->GeneratorTarget->GetLinkInformation(cfg)) { std::vector const& libDeps = cli->GetDepends(); @@ -1604,7 +1604,8 @@ void cmMakefileTargetGenerator::CreateLinkLibs( { std::string frameworkPath; std::string linkPath; - std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmComputeLinkInformation* pcli = this->GeneratorTarget->GetLinkInformation(config); this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index ebb7c15..5a45141 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -603,7 +603,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() // First and very important step is to make sure while inside this // step our link language is set to CUDA std::string cudaLinkLanguage = "CUDA"; - std::string const objExt = + std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); std::string const cfgName = this->GetConfigName(); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 506711a..df67db9 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -813,7 +813,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) << " target " << this->GetTargetName() << "\n\n"; - std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, config); for (cmSourceFile const* sf : customCommands) { @@ -1093,7 +1094,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (compilePP) { // In case compilation requires flags that are incompatible with // preprocessing, include them here. - std::string const postFlag = this->Makefile->GetSafeDefinition( + std::string const& postFlag = this->Makefile->GetSafeDefinition( "CMAKE_" + language + "_POSTPROCESS_FLAG"); this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); } @@ -1317,8 +1318,7 @@ void cmNinjaTargetGenerator::EnsureDirectoryExists( cmSystemTools::MakeDirectory(path); } else { cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator(); - std::string fullPath = - std::string(gg->GetCMakeInstance()->GetHomeOutputDirectory()); + std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory(); // Also ensures their is a trailing slash. gg->StripNinjaOutputPathPrefixAsSuffix(fullPath); fullPath += path; diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index cb9433f..4ed5581 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -293,8 +293,8 @@ protected: // Make sure we don't visit the same file more than once. info->DependDone = true; - const char* path = info->FullPath.c_str(); - if (!path) { + const std::string& path = info->FullPath; + if (path.empty()) { cmSystemTools::Error( "Attempt to find dependencies for file without path!"); return; @@ -356,7 +356,7 @@ protected: if (!found) { // Couldn't find any dependency information. if (this->ComplainFileRegularExpression.find(info->IncludeName)) { - cmSystemTools::Error("error cannot find dependencies for ", path); + cmSystemTools::Error("error cannot find dependencies for " + path); } else { // Destroy the name of the file so that it won't be output as a // dependency. diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 4b0707b..a92c2a0 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -146,7 +146,7 @@ bool cmTryRunCommand::InitialPass(std::vector const& argv, const char* compileOutput = this->Makefile->GetDefinition(this->OutputVariable); if (compileOutput) { - runOutputContents = std::string(compileOutput) + runOutputContents; + runOutputContents = compileOutput + runOutputContents; } this->Makefile->AddDefinition(this->OutputVariable, runOutputContents.c_str()); @@ -167,7 +167,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, int retVal = -1; std::string finalCommand; - const std::string emulator = + const std::string& emulator = this->Makefile->GetSafeDefinition("CMAKE_CROSSCOMPILING_EMULATOR"); if (!emulator.empty()) { std::vector emulatorWithArgs; @@ -233,7 +233,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, this->RunResultVariable + "__TRYRUN_OUTPUT"; bool error = false; - if (this->Makefile->GetDefinition(this->RunResultVariable) == nullptr) { + if (!this->Makefile->GetDefinition(this->RunResultVariable)) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -255,8 +255,8 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, } // is the output from the executable used ? - if (out != nullptr) { - if (this->Makefile->GetDefinition(internalRunOutputName) == nullptr) { + if (out) { + if (!this->Makefile->GetDefinition(internalRunOutputName)) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -304,7 +304,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, comment += " to\n" " the exit code (in many cases 0 for success), otherwise " "enter \"FAILED_TO_RUN\".\n"; - if (out != nullptr) { + if (out) { comment += internalRunOutputName; comment += "\n contains the text the executable " @@ -335,7 +335,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, << this->Makefile->GetDefinition(this->RunResultVariable) << "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n"; - if (out != nullptr) { + if (out) { file << "set( " << internalRunOutputName << " \n \"" << this->Makefile->GetDefinition(internalRunOutputName) << "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n"; @@ -348,7 +348,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, "please set the following cache variables " "appropriately:\n"; errorMessage += " " + this->RunResultVariable + " (advanced)\n"; - if (out != nullptr) { + if (out) { errorMessage += " " + internalRunOutputName + " (advanced)\n"; } errorMessage += detailsString; @@ -356,7 +356,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, return; } - if (out != nullptr) { + if (out) { (*out) = this->Makefile->GetDefinition(internalRunOutputName); } } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c60706d..ab9ef79 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2858,7 +2858,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( // Get compile flags for CUDA in this directory. std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG; + std::string configFlagsVar = "CMAKE_CUDA_FLAGS_" + CONFIG; std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") + " " + this->Makefile->GetSafeDefinition(configFlagsVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA", @@ -3075,7 +3075,7 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( Options& masmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG; + std::string configFlagsVar = "CMAKE_ASM_MASM_FLAGS_" + CONFIG; std::string flags = this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " + this->Makefile->GetSafeDefinition(configFlagsVar); @@ -3428,7 +3428,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string standardLibsVar = "CMAKE_"; standardLibsVar += linkLanguage; standardLibsVar += "_STANDARD_LIBRARIES"; - std::string const libs = this->Makefile->GetSafeDefinition(standardLibsVar); + std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar); cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec); linkOptions.AddFlag("AdditionalDependencies", libVec); -- cgit v0.12