浏览代码

cmTarget: add std::string overloads

Vitaly Stakhovsky 5 年之前
父节点
当前提交
c34b4497f8

+ 1 - 1
Source/cmExportInstallAndroidMKGenerator.cxx

@@ -49,7 +49,7 @@ void cmExportInstallAndroidMKGenerator::GenerateImportHeaderCode(
     if (te->ArchiveGenerator) {
       dest = te->ArchiveGenerator->GetDestination("");
     }
-    te->Target->Target->SetProperty("__dest", dest.c_str());
+    te->Target->Target->SetProperty("__dest", dest);
   }
 }
 

+ 1 - 1
Source/cmGhsMultiTargetGenerator.cxx

@@ -113,7 +113,7 @@ void cmGhsMultiTargetGenerator::Generate()
 
   // Tell the global generator the name of the project file
   this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
-                                             this->Name.c_str());
+                                             this->Name);
   this->GeneratorTarget->Target->SetProperty(
     "GENERATOR_FILE_NAME_EXT", GhsMultiGpj::GetGpjTag(this->TagType));
 

+ 1 - 1
Source/cmGlobalGenerator.cxx

@@ -2666,7 +2666,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti,
   cc.SetUsesTerminal(gti.UsesTerminal);
   target.AddPostBuildCommand(std::move(cc));
   if (!gti.Message.empty()) {
-    target.SetProperty("EchoString", gti.Message.c_str());
+    target.SetProperty("EchoString", gti.Message);
   }
   for (std::string const& d : gti.Depends) {
     target.AddUtility(d);

+ 6 - 7
Source/cmIncludeExternalMSProjectCommand.cxx

@@ -83,22 +83,21 @@ bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args,
     }
 
     // Create a target instance for this utility.
-    cmTarget* target =
-      mf.AddNewTarget(cmStateEnums::UTILITY, utility_name.c_str());
+    cmTarget* target = mf.AddNewTarget(cmStateEnums::UTILITY, utility_name);
     if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
       target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
     }
 
-    target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
-    target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
+    target->SetProperty("GENERATOR_FILE_NAME", utility_name);
+    target->SetProperty("EXTERNAL_MSPROJECT", path);
 
     if (!customType.empty())
-      target->SetProperty("VS_PROJECT_TYPE", customType.c_str());
+      target->SetProperty("VS_PROJECT_TYPE", customType);
     if (!platformMapping.empty())
-      target->SetProperty("VS_PLATFORM_MAPPING", platformMapping.c_str());
+      target->SetProperty("VS_PLATFORM_MAPPING", platformMapping);
 
     for (std::string const& d : depends) {
-      target->AddUtility(d.c_str());
+      target->AddUtility(d);
     }
   }
 #endif

+ 2 - 3
Source/cmLocalGenerator.cxx

@@ -2531,7 +2531,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
             }
 
             target->Target->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
-                                        target_compile_pdb_dir.c_str());
+                                        target_compile_pdb_dir);
           }
 
           std::string pchSourceObj =
@@ -2540,8 +2540,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
           // Link to the pch object file
           target->Target->AppendProperty(
             "LINK_FLAGS",
-            cmStrCat(" ", this->ConvertToOutputFormat(pchSourceObj, SHELL))
-              .c_str(),
+            cmStrCat(" ", this->ConvertToOutputFormat(pchSourceObj, SHELL)),
             true);
         }
       } else {

+ 1 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -194,7 +194,7 @@ void cmLocalVisualStudio7Generator::CreateSingleVCProj(
   }
 
   // add to the list of projects
-  target->Target->SetProperty("GENERATOR_FILE_NAME", lname.c_str());
+  target->Target->SetProperty("GENERATOR_FILE_NAME", lname);
   // create the dsp.cmake file
   std::string fname;
   fname = cmStrCat(this->GetCurrentBinaryDirectory(), '/', lname);

+ 4 - 4
Source/cmMakefile.cxx

@@ -1939,7 +1939,7 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target)
       target.AddLinkLibrary(*this, libraryName, libType);
       target.AppendProperty(
         "INTERFACE_LINK_LIBRARIES",
-        target.GetDebugGeneratorExpressions(libraryName, libType).c_str());
+        target.GetDebugGeneratorExpressions(libraryName, libType));
     }
   }
 }
@@ -2398,7 +2398,7 @@ void cmMakefile::ExpandVariablesCMP0019()
           << "  " << dirs << "\n";
         /* clang-format on */
       }
-      t.SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
+      t.SetProperty("INCLUDE_DIRECTORIES", dirs);
     }
   }
 
@@ -4549,7 +4549,7 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
                                           std::string* error) const
 {
   if (cmGeneratorExpression::Find(feature) != std::string::npos) {
-    target->AppendProperty("COMPILE_FEATURES", feature.c_str());
+    target->AppendProperty("COMPILE_FEATURES", feature);
     return true;
   }
 
@@ -4580,7 +4580,7 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
     return false;
   }
 
-  target->AppendProperty("COMPILE_FEATURES", feature.c_str());
+  target->AppendProperty("COMPILE_FEATURES", feature);
 
   if (lang == "C" || lang == "OBJC") {
     return this->AddRequiredTargetCFeature(target, feature, lang, error);

+ 4 - 4
Source/cmQtAutoGenInitializer.cxx

@@ -1140,7 +1140,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
 
     // Set FOLDER property in autogen target
     if (!this->TargetsFolder.empty()) {
-      autogenTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
+      autogenTarget->SetProperty("FOLDER", this->TargetsFolder);
     }
 
     // Add autogen target to the origin target dependencies
@@ -1209,7 +1209,7 @@ bool cmQtAutoGenInitializer::InitRccTargets()
 
         // Set FOLDER property in autogen target
         if (!this->TargetsFolder.empty()) {
-          autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
+          autoRccTarget->SetProperty("FOLDER", this->TargetsFolder);
         }
         if (!this->Rcc.ExecutableTargetName.empty()) {
           autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName,
@@ -1521,8 +1521,8 @@ bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
 
 void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
 {
-  this->GenTarget->Target->AppendProperty("ADDITIONAL_CLEAN_FILES",
-                                          fileName.c_str(), false);
+  this->GenTarget->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName,
+                                          false);
 }
 
 void cmQtAutoGenInitializer::ConfigFileNames(ConfigString& configString,

+ 1 - 1
Source/cmSetTargetPropertiesCommand.cxx

@@ -70,7 +70,7 @@ static bool SetOneTarget(const std::string& tname,
     // now loop through all the props and set them
     unsigned int k;
     for (k = 0; k < propertyPairs.size(); k = k + 2) {
-      target->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
+      target->SetProperty(propertyPairs[k], propertyPairs[k + 1]);
       target->CheckProperty(propertyPairs[k], mf);
     }
   }

+ 5 - 6
Source/cmTarget.cxx

@@ -949,9 +949,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
       (isNonImportedTarget && llt != GENERAL_LibraryType)
       ? targetNameGenex(libRef)
       : libRef;
-    this->AppendProperty(
-      "LINK_LIBRARIES",
-      this->GetDebugGeneratorExpressions(libName, llt).c_str());
+    this->AppendProperty("LINK_LIBRARIES",
+                         this->GetDebugGeneratorExpressions(libName, llt));
   }
 
   if (cmGeneratorExpression::Find(lib) != std::string::npos || lib != libRef ||
@@ -1285,9 +1284,9 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
 
     impl->Properties.SetProperty(prop, reusedFrom.c_str());
 
-    reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom.c_str());
+    reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom);
     reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
-                              cmStrCat(reusedFrom, ".dir/").c_str());
+                              cmStrCat(reusedFrom, ".dir/"));
 
     this->SetProperty("COMPILE_PDB_NAME",
                       reusedTarget->GetProperty("COMPILE_PDB_NAME"));
@@ -1422,7 +1421,7 @@ void cmTarget::AppendBuildInterfaceIncludes()
     dirs += impl->Makefile->GetCurrentSourceDirectory();
     if (!dirs.empty()) {
       this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
-                           ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
+                           ("$<BUILD_INTERFACE:" + dirs + ">"));
     }
   }
 }

+ 9 - 0
Source/cmTarget.h

@@ -164,8 +164,17 @@ public:
 
   //! Set/Get a property of this target file
   void SetProperty(const std::string& prop, const char* value);
+  void SetProperty(const std::string& prop, const std::string& value)
+  {
+    SetProperty(prop, value.c_str());
+  }
   void AppendProperty(const std::string& prop, const char* value,
                       bool asString = false);
+  void AppendProperty(const std::string& prop, const std::string& value,
+                      bool asString = false)
+  {
+    AppendProperty(prop, value.c_str(), asString);
+  }
   //! Might return a nullptr if the property is not set or invalid
   const char* GetProperty(const std::string& prop) const;
   //! Always returns a valid pointer

+ 1 - 1
Source/cmTargetCompileDefinitionsCommand.cxx

@@ -28,7 +28,7 @@ private:
                            const std::vector<std::string>& content,
                            bool /*prepend*/, bool /*system*/) override
   {
-    tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
+    tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content));
     return true; // Successfully handled.
   }
 

+ 1 - 2
Source/cmTargetIncludeDirectoriesCommand.cxx

@@ -88,8 +88,7 @@ void TargetIncludeDirectoriesImpl::HandleInterfaceContent(
                                                   system);
   if (system) {
     std::string joined = this->Join(content);
-    tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
-                        joined.c_str());
+    tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined);
   }
 }
 

+ 5 - 6
Source/cmTargetLinkLibrariesCommand.cxx

@@ -480,7 +480,7 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target,
           cmGeneratorExpression::Find(lib) != std::string::npos) {
         configLib = "$<LINK_ONLY:" + configLib + ">";
       }
-      target->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib.c_str());
+      target->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib);
     }
     return true;
   }
@@ -488,9 +488,8 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target,
   // Handle general case where the command was called with another keyword than
   // PRIVATE / LINK_PRIVATE or none at all. (The "INTERFACE_LINK_LIBRARIES"
   // property of the target on the LHS shall be populated.)
-  target->AppendProperty(
-    "INTERFACE_LINK_LIBRARIES",
-    target->GetDebugGeneratorExpressions(libRef, llt).c_str());
+  target->AppendProperty("INTERFACE_LINK_LIBRARIES",
+                         target->GetDebugGeneratorExpressions(libRef, llt));
 
   // Stop processing if called without any keyword.
   if (currentProcessingState == ProcessingLinkLibraries) {
@@ -522,12 +521,12 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target,
       // Put in the DEBUG configuration interfaces.
       for (std::string const& dc : debugConfigs) {
         prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc);
-        target->AppendProperty(prop, libRef.c_str());
+        target->AppendProperty(prop, libRef);
       }
     }
     if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) {
       // Put in the non-DEBUG configuration interfaces.
-      target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef.c_str());
+      target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef);
 
       // Make sure the DEBUG configuration interfaces exist so that the
       // general one will not be used as a fall-back.

+ 2 - 3
Source/cmTargetPrecompileHeadersCommand.cxx

@@ -47,9 +47,8 @@ private:
                            bool /*prepend*/, bool /*system*/) override
   {
     std::string const& base = this->Makefile->GetCurrentSourceDirectory();
-    tgt->AppendProperty(
-      "PRECOMPILE_HEADERS",
-      this->Join(ConvertToAbsoluteContent(content, base)).c_str());
+    tgt->AppendProperty("PRECOMPILE_HEADERS",
+                        this->Join(ConvertToAbsoluteContent(content, base)));
     return true;
   }
 

+ 3 - 6
Source/cmTargetPropCommandBase.cxx

@@ -84,9 +84,7 @@ bool cmTargetPropCommandBase::HandleArguments(
     }
     ++argIndex;
 
-    this->Target->SetProperty("PRECOMPILE_HEADERS_REUSE_FROM",
-                              args[argIndex].c_str());
-
+    this->Target->SetProperty("PRECOMPILE_HEADERS_REUSE_FROM", args[argIndex]);
     ++argIndex;
   }
 
@@ -162,9 +160,8 @@ void cmTargetPropCommandBase::HandleInterfaceContent(
     const char* propValue = tgt->GetProperty(propName);
     const std::string totalContent = this->Join(content) +
       (propValue ? std::string(";") + propValue : std::string());
-    tgt->SetProperty(propName, totalContent.c_str());
+    tgt->SetProperty(propName, totalContent);
   } else {
-    tgt->AppendProperty("INTERFACE_" + this->Property,
-                        this->Join(content).c_str());
+    tgt->AppendProperty("INTERFACE_" + this->Property, this->Join(content));
   }
 }

+ 1 - 2
Source/cmTargetSourcesCommand.cxx

@@ -43,8 +43,7 @@ private:
                            bool /*prepend*/, bool /*system*/) override
   {
     tgt->AppendProperty(
-      "SOURCES",
-      this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
+      "SOURCES", this->Join(ConvertToAbsoluteContent(tgt, content, false)));
     return true; // Successfully handled.
   }
 

+ 2 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -334,9 +334,9 @@ void cmVisualStudio10TargetGenerator::Generate()
   }
   // Tell the global generator the name of the project file
   this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
-                                             this->Name.c_str());
+                                             this->Name);
   this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
-                                             ProjectFileExtension.c_str());
+                                             ProjectFileExtension);
   this->DotNetHintReferences.clear();
   this->AdditionalUsingDirectories.clear();
   if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {

+ 1 - 1
Source/cmake.cxx

@@ -548,7 +548,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
     const char* targetName = "dummy";
     std::vector<std::string> srcs;
     cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
-    tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
+    tgt->SetProperty("LINKER_LANGUAGE", language);
 
     std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
     std::vector<std::string> libList = cmExpandedList(libs);