From 6100bdff38580d297c098127e9bc0105b7a33e06 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 20 Apr 2016 23:11:17 +0200 Subject: [PATCH 1/4] cmGlobalXCodeGenerator: directly call CreateString() with std::string This function already takes a const std::string&, no need to convert the input to a char* before passing it in. --- Source/cmGlobalXCodeGenerator.cxx | 66 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 7c852816f..0050bf4d1 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -109,7 +109,7 @@ public: } else { - return this->Generator->CreateString(this->String.c_str()); + return this->Generator->CreateString(this->String); } } }; @@ -804,7 +804,7 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); - settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str())); + settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags)); // Is this a resource file in this target? Add it to the resources group... // @@ -1011,8 +1011,8 @@ cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( std::string name = cmSystemTools::GetFilenameName(path.c_str()); const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())? "" : "SOURCE_ROOT"); - fileRef->AddAttribute("name", this->CreateString(name.c_str())); - fileRef->AddAttribute("path", this->CreateString(path.c_str())); + fileRef->AddAttribute("name", this->CreateString(name)); + fileRef->AddAttribute("path", this->CreateString(path)); fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree)); if(this->XcodeVersion == 15) { @@ -1326,7 +1326,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, ostr << "../" << mit->first.c_str(); } copyFilesBuildPhase->AddAttribute("dstPath", - this->CreateString(ostr.str().c_str())); + this->CreateString(ostr.str())); copyFilesBuildPhase->AddAttribute( "runOnlyForDeploymentPostprocessing", this->CreateString("0")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); @@ -1752,7 +1752,7 @@ cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase, (makefile+"$CONFIGURATION").c_str()); makecmd += " all"; buildphase->AddAttribute("shellScript", - this->CreateString(makecmd.c_str())); + this->CreateString(makecmd)); buildphase->AddAttribute("showEnvVarsInLog", this->CreateString("0")); } @@ -2021,7 +2021,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, if(archs.size() == 1) { buildSettings->AddAttribute("ARCHS", - this->CreateString(archs[0].c_str())); + this->CreateString(archs[0])); } else { @@ -2030,7 +2030,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, for(std::vector::iterator i = archs.begin(); i != archs.end(); i++) { - archObjects->AddObject(this->CreateString((*i).c_str())); + archObjects->AddObject(this->CreateString(*i)); } buildSettings->AddAttribute("ARCHS", archObjects); } @@ -2081,13 +2081,13 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { std::string pncdir = gtgt->GetDirectory(configName); buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", - this->CreateString(pncdir.c_str())); + this->CreateString(pncdir)); } } else { buildSettings->AddAttribute("OBJROOT", - this->CreateString(pndir.c_str())); + this->CreateString(pndir)); pndir = gtgt->GetDirectory(configName); } @@ -2097,9 +2097,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } buildSettings->AddAttribute("EXECUTABLE_PREFIX", - this->CreateString(pnprefix.c_str())); + this->CreateString(pnprefix)); buildSettings->AddAttribute("EXECUTABLE_SUFFIX", - this->CreateString(pnsuffix.c_str())); + this->CreateString(pnsuffix)); } else if(gtgt->GetType() == cmState::OBJECT_LIBRARY) { @@ -2112,12 +2112,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::string pncdir = this->GetObjectsNormalDirectory( this->CurrentProject, configName, gtgt); buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", - this->CreateString(pncdir.c_str())); + this->CreateString(pncdir)); } else { buildSettings->AddAttribute("OBJROOT", - this->CreateString(pndir.c_str())); + this->CreateString(pndir)); pndir = this->GetObjectsNormalDirectory( this->CurrentProject, configName, gtgt); } @@ -2125,9 +2125,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Store the product name for all target types. buildSettings->AddAttribute("PRODUCT_NAME", - this->CreateString(realName.c_str())); + this->CreateString(realName)); buildSettings->AddAttribute("SYMROOT", - this->CreateString(pndir.c_str())); + this->CreateString(pndir)); // Handle settings for each target type. switch(gtgt->GetType()) @@ -2203,7 +2203,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { std::string fw_version = gtgt->GetFrameworkVersion(); buildSettings->AddAttribute("FRAMEWORK_VERSION", - this->CreateString(fw_version.c_str())); + this->CreateString(fw_version)); std::string plist = this->ComputeInfoPListLocation(gtgt); // Xcode will create the final version of Info.plist at build time, @@ -2390,17 +2390,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, if (*li == "CXX") { buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS", - this->CreateString(flags.c_str())); + this->CreateString(flags)); } else if (*li == "Fortran") { buildSettings->AddAttribute("IFORT_OTHER_FLAGS", - this->CreateString(flags.c_str())); + this->CreateString(flags)); } else if (*li == "C") { buildSettings->AddAttribute("OTHER_CFLAGS", - this->CreateString(flags.c_str())); + this->CreateString(flags)); } } @@ -2448,7 +2448,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } } buildSettings->AddAttribute("INSTALL_PATH", - this->CreateString(install_name_dir.c_str())); + this->CreateString(install_name_dir)); // Create the LD_RUNPATH_SEARCH_PATHS cmComputeLinkInformation* pcli = gtgt->GetLinkInformation(configName); @@ -2479,12 +2479,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, if(!search_paths.empty()) { buildSettings->AddAttribute("LD_RUNPATH_SEARCH_PATHS", - this->CreateString(search_paths.c_str())); + this->CreateString(search_paths)); } } buildSettings->AddAttribute(this->GetTargetLinkFlagsVar(gtgt), - this->CreateString(extraLinkOptions.c_str())); + this->CreateString(extraLinkOptions)); buildSettings->AddAttribute("OTHER_REZFLAGS", this->CreateString("")); buildSettings->AddAttribute("SECTORDER_FLAGS", @@ -2525,7 +2525,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, v << major << "." << minor << "." << patch; } buildSettings->AddAttribute("DYLIB_CURRENT_VERSION", - this->CreateString(v.str().c_str())); + this->CreateString(v.str())); // SOVERSION -> compatibility_version gtgt->GetTargetVersion(true, major, minor, patch); @@ -2537,7 +2537,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, vso << major << "." << minor << "." << patch; } buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION", - this->CreateString(vso.str().c_str())); + this->CreateString(vso.str())); } // put this last so it can override existing settings // Convert "XCODE_ATTRIBUTE_*" properties directly. @@ -2674,14 +2674,14 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target, this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); this->CreateBuildSettings(gtgt, buildSettings, configVector[i].c_str()); - config->AddAttribute("name", this->CreateString(configVector[i].c_str())); + config->AddAttribute("name", this->CreateString(configVector[i])); config->SetComment(configVector[i].c_str()); config->AddAttribute("buildSettings", buildSettings); } if(!configVector.empty()) { configlist->AddAttribute("defaultConfigurationName", - this->CreateString(configVector[0].c_str())); + this->CreateString(configVector[0])); configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0")); return configVector[0]; @@ -2813,7 +2813,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmGeneratorTarget* gtgt, { fullName = gtgt->GetFullName(defConfig.c_str()); } - fileRef->AddAttribute("path", this->CreateString(fullName.c_str())); + fileRef->AddAttribute("path", this->CreateString(fullName)); if(this->XcodeVersion == 15) { fileRef->AddAttribute("refType", this->CreateString("0")); @@ -3200,7 +3200,7 @@ cmXCodeObject *cmGlobalXCodeGenerator cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup); cmXCodeObject* groupChildren = this->CreateObject(cmXCodeObject::OBJECT_LIST); - group->AddAttribute("name", this->CreateString(name.c_str())); + group->AddAttribute("name", this->CreateString(name)); group->AddAttribute("children", groupChildren); if(this->XcodeVersion == 15) { @@ -3447,7 +3447,7 @@ bool cmGlobalXCodeGenerator std::string pdir = this->RelativeToBinary(root->GetCurrentSourceDirectory()); this->RootObject->AddAttribute("projectDirPath", - this->CreateString(pdir.c_str())); + this->CreateString(pdir)); this->RootObject->AddAttribute("projectRoot", this->CreateString("")); } cmXCodeObject* configlist = @@ -3528,7 +3528,7 @@ bool cmGlobalXCodeGenerator else { // Tell Xcode to use ARCHS (ONLY_ACTIVE_ARCH defaults to NO). - buildSettings->AddAttribute("ARCHS", this->CreateString(archs.c_str())); + buildSettings->AddAttribute("ARCHS", this->CreateString(archs)); } if(deploymentTarget && *deploymentTarget) { @@ -3538,12 +3538,12 @@ bool cmGlobalXCodeGenerator if(!this->GeneratorToolset.empty()) { buildSettings->AddAttribute("GCC_VERSION", - this->CreateString(this->GeneratorToolset.c_str())); + this->CreateString(this->GeneratorToolset)); } std::string symroot = root->GetCurrentBinaryDirectory(); symroot += "/build"; - buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot.c_str())); + buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot)); for(Configs::iterator i = configs.begin(); i != configs.end(); ++i) { From ffedf3527d7e714b6885b822ee85889016418ebb Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 20 Apr 2016 23:14:52 +0200 Subject: [PATCH 2/4] make cmGlobalXCodeGenerator::BuildObjectListOrString::Add() take a string& All callers already have these objects, and it is only passed to other methods taking such, so avoid all conversions in between. --- Source/cmGlobalXCodeGenerator.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0050bf4d1..5e6834547 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -84,7 +84,7 @@ public: bool IsEmpty() const { return this->Empty; } - void Add(const char *newString) + void Add(const std::string& newString) { this->Empty = false; @@ -2285,14 +2285,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str()); if(emitted.insert(frameworkDir).second) { - fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str()).c_str()); + fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str())); } } else { std::string incpath = this->XCodeEscapePath(i->c_str()); - dirs.Add(incpath.c_str()); + dirs.Add(incpath); } } // Add framework search paths needed for linking. @@ -2304,7 +2304,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { if(emitted.insert(*fdi).second) { - fdirs.Add(this->XCodeEscapePath(fdi->c_str()).c_str()); + fdirs.Add(this->XCodeEscapePath(fdi->c_str())); } } } @@ -4025,7 +4025,7 @@ cmGlobalXCodeGenerator::AppendDefines(BuildObjectListOrString& defs, // Append the flag with needed escapes. std::string tmp; this->AppendFlag(tmp, def); - defs.Add(tmp.c_str()); + defs.Add(tmp); } } From 2b25ce30ca825765a5c249e455c466802af95116 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 20 Apr 2016 23:19:48 +0200 Subject: [PATCH 3/4] make cmGlobalXCodeGenerator::XCodeEscapePath() take a std::string& All callers already have one, and it was immediately converted to one internally. Just keep the old one around, and only modify it when needed. --- Source/cmGlobalXCodeGenerator.cxx | 33 +++++++++++++++---------------- Source/cmGlobalXCodeGenerator.h | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 5e6834547..8eb5e11f9 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2285,13 +2285,13 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str()); if(emitted.insert(frameworkDir).second) { - fdirs.Add(this->XCodeEscapePath(frameworkDir.c_str())); + fdirs.Add(this->XCodeEscapePath(frameworkDir)); } } else { std::string incpath = - this->XCodeEscapePath(i->c_str()); + this->XCodeEscapePath(*i); dirs.Add(incpath); } } @@ -2304,7 +2304,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { if(emitted.insert(*fdi).second) { - fdirs.Add(this->XCodeEscapePath(fdi->c_str())); + fdirs.Add(this->XCodeEscapePath(*fdi)); } } } @@ -2444,7 +2444,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { install_name_dir = ""; extraLinkOptions += " -install_name "; - extraLinkOptions += XCodeEscapePath(install_name.c_str()); + extraLinkOptions += XCodeEscapePath(install_name); } } buildSettings->AddAttribute("INSTALL_PATH", @@ -2473,7 +2473,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { search_paths += " "; } - search_paths += this->XCodeEscapePath(runpath.c_str()); + search_paths += this->XCodeEscapePath(runpath); } } if(!search_paths.empty()) @@ -3021,7 +3021,7 @@ void cmGlobalXCodeGenerator { linkObjs += sep; sep = " "; - linkObjs += this->XCodeEscapePath(oi->c_str()); + linkObjs += this->XCodeEscapePath(*oi); } this->AppendBuildSettingAttribute( target, this->GetTargetLinkFlagsVar(gt), @@ -3068,10 +3068,10 @@ void cmGlobalXCodeGenerator // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it: linkDirs += " "; linkDirs += this->XCodeEscapePath( - (*libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)").c_str()); + *libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"); } linkDirs += " "; - linkDirs += this->XCodeEscapePath(libDir->c_str()); + linkDirs += this->XCodeEscapePath(*libDir); } } this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS", @@ -3091,7 +3091,7 @@ void cmGlobalXCodeGenerator sep = " "; if(li->IsPath) { - linkLibs += this->XCodeEscapePath(li->Value.c_str()); + linkLibs += this->XCodeEscapePath(li->Value); } else if (!li->Target || li->Target->GetType() != cmState::INTERFACE_LIBRARY) @@ -3932,17 +3932,16 @@ std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p) } //---------------------------------------------------------------------------- -std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p) +std::string cmGlobalXCodeGenerator::XCodeEscapePath(const std::string& p) { - std::string ret = p; - if(ret.find(' ') != ret.npos) + if(p.find(' ') != p.npos) { - std::string t = ret; - ret = "\""; - ret += t; - ret += "\""; + std::string t = "\""; + t += p; + t += "\""; + return t; } - return ret; + return p; } //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 862746f21..f7bfb26c4 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -96,7 +96,7 @@ private: bool CreateGroups(cmLocalGenerator* root, std::vector& generators); - std::string XCodeEscapePath(const char* p); + std::string XCodeEscapePath(const std::string& p); std::string RelativeToSource(const char* p); std::string RelativeToBinary(const char* p); std::string ConvertToRelativeForMake(const char* p); From 2263949b7817fad0b2560cb5dd8e102d1f547b47 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 20 Apr 2016 23:23:26 +0200 Subject: [PATCH 4/4] cmGlobalXCodeGenerator: do not pass char* to cmSystemTools::CollapseFullPath() This takes a std::string&, so directly pass the object to it instead of converting back and forth. --- Source/cmGlobalXCodeGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 8eb5e11f9..755c8a68c 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2282,7 +2282,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, { std::string frameworkDir = *i; frameworkDir += "/../"; - frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str()); + frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); if(emitted.insert(frameworkDir).second) { fdirs.Add(this->XCodeEscapePath(frameworkDir));