소스 검색

Merge topic 'append-std-string'

1398517f31 AppendProperty: convert value param to std::string

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4282
Brad King 5 년 전
부모
커밋
e3be80f4fc

+ 3 - 3
Source/cmCacheManager.cxx

@@ -648,8 +648,8 @@ void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
                                                 bool asString)
 {
   if (prop == "TYPE") {
-    this->Type = cmState::StringToCacheEntryType(!value.empty() ? value.c_str()
-                                                                : "STRING");
+    this->Type =
+      cmState::StringToCacheEntryType(!value.empty() ? value : "STRING");
   } else if (prop == "VALUE") {
     if (!value.empty()) {
       if (!this->Value.empty() && !asString) {
@@ -658,7 +658,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
       this->Value += value;
     }
   } else {
-    this->Properties.AppendProperty(prop, value.c_str(), asString);
+    this->Properties.AppendProperty(prop, value, asString);
   }
 }
 

+ 3 - 1
Source/cmGlobalGenerator.cxx

@@ -1645,7 +1645,9 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
         for (std::string const& c : configs) {
           std::string defPropName =
             cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c));
-          t->AppendProperty(defPropName, mf->GetProperty(defPropName));
+          if (const char* val = mf->GetProperty(defPropName)) {
+            t->AppendProperty(defPropName, val);
+          }
         }
       }
     }

+ 1 - 1
Source/cmLinkLibrariesCommand.cxx

@@ -32,7 +32,7 @@ bool cmLinkLibrariesCommand(std::vector<std::string> const& args,
       }
       mf.AppendProperty("LINK_LIBRARIES", "optimized");
     }
-    mf.AppendProperty("LINK_LIBRARIES", i->c_str());
+    mf.AppendProperty("LINK_LIBRARIES", *i);
   }
 
   return true;

+ 1 - 1
Source/cmMacroCommand.cxx

@@ -167,7 +167,7 @@ bool cmMacroFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
                                     cmExecutionStatus& status)
 {
   cmMakefile& mf = status.GetMakefile();
-  mf.AppendProperty("MACROS", this->Args[0].c_str());
+  mf.AppendProperty("MACROS", this->Args[0]);
   // create a new command and add it to cmake
   cmMacroHelperCommand f;
   f.Args = this->Args;

+ 5 - 5
Source/cmMakefile.cxx

@@ -1288,17 +1288,17 @@ void cmMakefile::RemoveDefineFlag(std::string const& flag)
 
 void cmMakefile::AddCompileDefinition(std::string const& option)
 {
-  this->AppendProperty("COMPILE_DEFINITIONS", option.c_str());
+  this->AppendProperty("COMPILE_DEFINITIONS", option);
 }
 
 void cmMakefile::AddCompileOption(std::string const& option)
 {
-  this->AppendProperty("COMPILE_OPTIONS", option.c_str());
+  this->AppendProperty("COMPILE_OPTIONS", option);
 }
 
 void cmMakefile::AddLinkOption(std::string const& option)
 {
-  this->AppendProperty("LINK_OPTIONS", option.c_str());
+  this->AppendProperty("LINK_OPTIONS", option);
 }
 
 void cmMakefile::AddLinkDirectory(std::string const& directory, bool before)
@@ -4039,8 +4039,8 @@ void cmMakefile::SetProperty(const std::string& prop, const char* value)
   this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace);
 }
 
-void cmMakefile::AppendProperty(const std::string& prop, const char* value,
-                                bool asString)
+void cmMakefile::AppendProperty(const std::string& prop,
+                                const std::string& value, bool asString)
 {
   this->StateSnapshot.GetDirectory().AppendProperty(prop, value, asString,
                                                     this->Backtrace);

+ 1 - 1
Source/cmMakefile.h

@@ -784,7 +784,7 @@ public:
 
   //! Set/Get a property of this directory
   void SetProperty(const std::string& prop, const char* value);
-  void AppendProperty(const std::string& prop, const char* value,
+  void AppendProperty(const std::string& prop, const std::string& value,
                       bool asString = false);
   const char* GetProperty(const std::string& prop) const;
   const char* GetProperty(const std::string& prop, bool chain) const;

+ 3 - 3
Source/cmPropertyMap.cxx

@@ -20,11 +20,11 @@ void cmPropertyMap::SetProperty(const std::string& name, const char* value)
   Map_[name] = value;
 }
 
-void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
-                                   bool asString)
+void cmPropertyMap::AppendProperty(const std::string& name,
+                                   const std::string& value, bool asString)
 {
   // Skip if nothing to append.
-  if (!value || !*value) {
+  if (value.empty()) {
     return;
   }
 

+ 1 - 1
Source/cmPropertyMap.h

@@ -27,7 +27,7 @@ public:
   void SetProperty(const std::string& name, const char* value);
 
   //! Append to the property value
-  void AppendProperty(const std::string& name, const char* value,
+  void AppendProperty(const std::string& name, const std::string& value,
                       bool asString = false);
 
   //! Get the property value

+ 54 - 63
Source/cmSetPropertyCommand.cxx

@@ -194,9 +194,8 @@ namespace {
 bool HandleGlobalMode(cmExecutionStatus& status,
                       const std::set<std::string>& names,
                       const std::string& propertyName,
-                      const std::string& propertyValue,
-                      const bool appendAsString, const bool appendMode,
-                      const bool remove)
+                      const std::string& propertyValue, bool appendAsString,
+                      bool appendMode, bool remove)
 {
   if (!names.empty()) {
     status.SetError("given names for GLOBAL scope.");
@@ -205,14 +204,14 @@ bool HandleGlobalMode(cmExecutionStatus& status,
 
   // Set or append the property.
   cmake* cm = status.GetMakefile().GetCMakeInstance();
-  const char* value = propertyValue.c_str();
-  if (remove) {
-    value = nullptr;
-  }
   if (appendMode) {
-    cm->AppendProperty(propertyName, value ? value : "", appendAsString);
+    cm->AppendProperty(propertyName, propertyValue, appendAsString);
   } else {
-    cm->SetProperty(propertyName, value);
+    if (remove) {
+      cm->SetProperty(propertyName, nullptr);
+    } else {
+      cm->SetProperty(propertyName, propertyValue.c_str());
+    }
   }
 
   return true;
@@ -221,9 +220,8 @@ bool HandleGlobalMode(cmExecutionStatus& status,
 bool HandleDirectoryMode(cmExecutionStatus& status,
                          const std::set<std::string>& names,
                          const std::string& propertyName,
-                         const std::string& propertyValue,
-                         const bool appendAsString, const bool appendMode,
-                         const bool remove)
+                         const std::string& propertyValue, bool appendAsString,
+                         bool appendMode, bool remove)
 {
   if (names.size() > 1) {
     status.SetError("allows at most one name for DIRECTORY scope.");
@@ -258,14 +256,14 @@ bool HandleDirectoryMode(cmExecutionStatus& status,
   }
 
   // Set or append the property.
-  const char* value = propertyValue.c_str();
-  if (remove) {
-    value = nullptr;
-  }
   if (appendMode) {
-    mf->AppendProperty(propertyName, value ? value : "", appendAsString);
+    mf->AppendProperty(propertyName, propertyValue, appendAsString);
   } else {
-    mf->SetProperty(propertyName, value);
+    if (remove) {
+      mf->SetProperty(propertyName, nullptr);
+    } else {
+      mf->SetProperty(propertyName, propertyValue.c_str());
+    }
   }
 
   return true;
@@ -274,9 +272,8 @@ bool HandleDirectoryMode(cmExecutionStatus& status,
 bool HandleTargetMode(cmExecutionStatus& status,
                       const std::set<std::string>& names,
                       const std::string& propertyName,
-                      const std::string& propertyValue,
-                      const bool appendAsString, const bool appendMode,
-                      const bool remove)
+                      const std::string& propertyValue, bool appendAsString,
+                      bool appendMode, bool remove)
 {
   for (std::string const& name : names) {
     if (status.GetMakefile().IsAlias(name)) {
@@ -300,18 +297,18 @@ bool HandleTargetMode(cmExecutionStatus& status,
 
 bool HandleTarget(cmTarget* target, cmMakefile& makefile,
                   const std::string& propertyName,
-                  const std::string& propertyValue, const bool appendAsString,
-                  const bool appendMode, const bool remove)
+                  const std::string& propertyValue, bool appendAsString,
+                  bool appendMode, bool remove)
 {
   // Set or append the property.
-  const char* value = propertyValue.c_str();
-  if (remove) {
-    value = nullptr;
-  }
   if (appendMode) {
-    target->AppendProperty(propertyName, value, appendAsString);
+    target->AppendProperty(propertyName, propertyValue, appendAsString);
   } else {
-    target->SetProperty(propertyName, value);
+    if (remove) {
+      target->SetProperty(propertyName, nullptr);
+    } else {
+      target->SetProperty(propertyName, propertyValue.c_str());
+    }
   }
 
   // Check the resulting value.
@@ -323,9 +320,8 @@ bool HandleTarget(cmTarget* target, cmMakefile& makefile,
 bool HandleSourceMode(cmExecutionStatus& status,
                       const std::set<std::string>& names,
                       const std::string& propertyName,
-                      const std::string& propertyValue,
-                      const bool appendAsString, const bool appendMode,
-                      const bool remove)
+                      const std::string& propertyValue, bool appendAsString,
+                      bool appendMode, bool remove)
 {
   for (std::string const& name : names) {
     // Get the source file.
@@ -344,28 +340,26 @@ bool HandleSourceMode(cmExecutionStatus& status,
 }
 
 bool HandleSource(cmSourceFile* sf, const std::string& propertyName,
-                  const std::string& propertyValue, const bool appendAsString,
-                  const bool appendMode, const bool remove)
+                  const std::string& propertyValue, bool appendAsString,
+                  bool appendMode, bool remove)
 {
   // Set or append the property.
-  const char* value = propertyValue.c_str();
-  if (remove) {
-    value = nullptr;
-  }
-
   if (appendMode) {
-    sf->AppendProperty(propertyName, value, appendAsString);
+    sf->AppendProperty(propertyName, propertyValue, appendAsString);
   } else {
-    sf->SetProperty(propertyName, value);
+    if (remove) {
+      sf->SetProperty(propertyName, nullptr);
+    } else {
+      sf->SetProperty(propertyName, propertyValue.c_str());
+    }
   }
   return true;
 }
 
 bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names,
                     const std::string& propertyName,
-                    const std::string& propertyValue,
-                    const bool appendAsString, const bool appendMode,
-                    const bool remove)
+                    const std::string& propertyValue, bool appendAsString,
+                    bool appendMode, bool remove)
 {
   // Look for tests with all names given.
   std::set<std::string>::iterator next;
@@ -396,18 +390,18 @@ bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names,
 }
 
 bool HandleTest(cmTest* test, const std::string& propertyName,
-                const std::string& propertyValue, const bool appendAsString,
-                const bool appendMode, const bool remove)
+                const std::string& propertyValue, bool appendAsString,
+                bool appendMode, bool remove)
 {
   // Set or append the property.
-  const char* value = propertyValue.c_str();
-  if (remove) {
-    value = nullptr;
-  }
   if (appendMode) {
-    test->AppendProperty(propertyName, value, appendAsString);
+    test->AppendProperty(propertyName, propertyValue, appendAsString);
   } else {
-    test->SetProperty(propertyName, value);
+    if (remove) {
+      test->SetProperty(propertyName, nullptr);
+    } else {
+      test->SetProperty(propertyName, propertyValue.c_str());
+    }
   }
 
   return true;
@@ -416,9 +410,8 @@ bool HandleTest(cmTest* test, const std::string& propertyName,
 bool HandleCacheMode(cmExecutionStatus& status,
                      const std::set<std::string>& names,
                      const std::string& propertyName,
-                     const std::string& propertyValue,
-                     const bool appendAsString, const bool appendMode,
-                     const bool remove)
+                     const std::string& propertyValue, bool appendAsString,
+                     bool appendMode, bool remove)
 {
   if (propertyName == "ADVANCED") {
     if (!remove && !cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
@@ -463,9 +456,8 @@ bool HandleCacheMode(cmExecutionStatus& status,
 
 bool HandleCacheEntry(std::string const& cacheKey, const cmMakefile& makefile,
                       const std::string& propertyName,
-                      const std::string& propertyValue,
-                      const bool appendAsString, const bool appendMode,
-                      const bool remove)
+                      const std::string& propertyValue, bool appendAsString,
+                      bool appendMode, bool remove)
 {
   // Set or append the property.
   const char* value = propertyValue.c_str();
@@ -486,9 +478,8 @@ bool HandleCacheEntry(std::string const& cacheKey, const cmMakefile& makefile,
 bool HandleInstallMode(cmExecutionStatus& status,
                        const std::set<std::string>& names,
                        const std::string& propertyName,
-                       const std::string& propertyValue,
-                       const bool appendAsString, const bool appendMode,
-                       const bool remove)
+                       const std::string& propertyValue, bool appendAsString,
+                       bool appendMode, bool remove)
 {
   cmake* cm = status.GetMakefile().GetCMakeInstance();
 
@@ -510,8 +501,8 @@ bool HandleInstallMode(cmExecutionStatus& status,
 
 bool HandleInstall(cmInstalledFile* file, cmMakefile& makefile,
                    const std::string& propertyName,
-                   const std::string& propertyValue, const bool appendAsString,
-                   const bool appendMode, const bool remove)
+                   const std::string& propertyValue, bool appendAsString,
+                   bool appendMode, bool remove)
 {
   // Set or append the property.
   const char* value = propertyValue.c_str();

+ 5 - 5
Source/cmSourceFile.cxx

@@ -260,21 +260,21 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
   }
 }
 
-void cmSourceFile::AppendProperty(const std::string& prop, const char* value,
-                                  bool asString)
+void cmSourceFile::AppendProperty(const std::string& prop,
+                                  const std::string& value, bool asString)
 {
   if (prop == propINCLUDE_DIRECTORIES) {
-    if (value && *value) {
+    if (!value.empty()) {
       cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
       this->IncludeDirectories.emplace_back(value, lfbt);
     }
   } else if (prop == propCOMPILE_OPTIONS) {
-    if (value && *value) {
+    if (!value.empty()) {
       cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
       this->CompileOptions.emplace_back(value, lfbt);
     }
   } else if (prop == propCOMPILE_DEFINITIONS) {
-    if (value && *value) {
+    if (!value.empty()) {
       cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace();
       this->CompileDefinitions.emplace_back(value, lfbt);
     }

+ 1 - 1
Source/cmSourceFile.h

@@ -42,7 +42,7 @@ public:
 
   //! Set/Get a property of this source file
   void SetProperty(const std::string& prop, const char* value);
-  void AppendProperty(const std::string& prop, const char* value,
+  void AppendProperty(const std::string& prop, const std::string& value,
                       bool asString = false);
   //! Might return a nullptr if the property is not set or invalid
   const char* GetProperty(const std::string& prop) const;

+ 2 - 2
Source/cmState.cxx

@@ -557,8 +557,8 @@ void cmState::SetGlobalProperty(const std::string& prop, const char* value)
   this->GlobalProperties.SetProperty(prop, value);
 }
 
-void cmState::AppendGlobalProperty(const std::string& prop, const char* value,
-                                   bool asString)
+void cmState::AppendGlobalProperty(const std::string& prop,
+                                   const std::string& value, bool asString)
 {
   this->GlobalProperties.AppendProperty(prop, value, asString);
 }

+ 1 - 1
Source/cmState.h

@@ -168,7 +168,7 @@ public:
   std::vector<std::string> GetCommandNames() const;
 
   void SetGlobalProperty(const std::string& prop, const char* value);
-  void AppendGlobalProperty(const std::string& prop, const char* value,
+  void AppendGlobalProperty(const std::string& prop, const std::string& value,
                             bool asString = false);
   const char* GetGlobalProperty(const std::string& prop);
   bool GetGlobalPropertyAsBool(const std::string& prop);

+ 1 - 1
Source/cmStateDirectory.cxx

@@ -521,7 +521,7 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
 }
 
 void cmStateDirectory::AppendProperty(const std::string& prop,
-                                      const char* value, bool asString,
+                                      const std::string& value, bool asString,
                                       cmListFileBacktrace const& lfbt)
 {
   if (prop == "INCLUDE_DIRECTORIES") {

+ 1 - 1
Source/cmStateDirectory.h

@@ -84,7 +84,7 @@ public:
 
   void SetProperty(const std::string& prop, const char* value,
                    cmListFileBacktrace const& lfbt);
-  void AppendProperty(const std::string& prop, const char* value,
+  void AppendProperty(const std::string& prop, const std::string& value,
                       bool asString, cmListFileBacktrace const& lfbt);
   const char* GetProperty(const std::string& prop) const;
   const char* GetProperty(const std::string& prop, bool chain) const;

+ 10 - 10
Source/cmTarget.cxx

@@ -1298,8 +1298,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
   }
 }
 
-void cmTarget::AppendProperty(const std::string& prop, const char* value,
-                              bool asString)
+void cmTarget::AppendProperty(const std::string& prop,
+                              const std::string& value, bool asString)
 {
   if (!cmTargetPropertyComputer::PassesWhitelist(
         this->GetType(), prop, impl->Makefile->GetMessenger(),
@@ -1334,37 +1334,37 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
     return;
   }
   if (prop == "INCLUDE_DIRECTORIES") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->IncludeDirectoriesEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->IncludeDirectoriesBacktraces.push_back(lfbt);
     }
   } else if (prop == "COMPILE_OPTIONS") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->CompileOptionsEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->CompileOptionsBacktraces.push_back(lfbt);
     }
   } else if (prop == "COMPILE_FEATURES") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->CompileFeaturesEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->CompileFeaturesBacktraces.push_back(lfbt);
     }
   } else if (prop == "COMPILE_DEFINITIONS") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->CompileDefinitionsEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->CompileDefinitionsBacktraces.push_back(lfbt);
     }
   } else if (prop == "LINK_OPTIONS") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->LinkOptionsEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->LinkOptionsBacktraces.push_back(lfbt);
     }
   } else if (prop == "LINK_DIRECTORIES") {
-    if (value && *value) {
+    if (!value.empty()) {
       impl->LinkDirectoriesEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->LinkDirectoriesBacktraces.push_back(lfbt);
@@ -1378,13 +1378,13 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
       impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
       return;
     }
-    if (value && *value) {
+    if (!value.empty()) {
       impl->PrecompileHeadersEntries.emplace_back(value);
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->PrecompileHeadersBacktraces.push_back(lfbt);
     }
   } else if (prop == "LINK_LIBRARIES") {
-    if (value && *value) {
+    if (!value.empty()) {
       cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
       impl->LinkImplementationPropertyEntries.emplace_back(value);
       impl->LinkImplementationPropertyBacktraces.push_back(lfbt);

+ 1 - 6
Source/cmTarget.h

@@ -166,13 +166,8 @@ public:
   {
     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);
-  }
+                      bool asString = false);
   //! 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/cmTest.cxx

@@ -55,7 +55,7 @@ void cmTest::SetProperty(const std::string& prop, const char* value)
   this->Properties.SetProperty(prop, value);
 }
 
-void cmTest::AppendProperty(const std::string& prop, const char* value,
+void cmTest::AppendProperty(const std::string& prop, const std::string& value,
                             bool asString)
 {
   this->Properties.AppendProperty(prop, value, asString);

+ 1 - 1
Source/cmTest.h

@@ -35,7 +35,7 @@ public:
 
   //! Set/Get a property of this source file
   void SetProperty(const std::string& prop, const char* value);
-  void AppendProperty(const std::string& prop, const char* value,
+  void AppendProperty(const std::string& prop, const std::string& value,
                       bool asString = false);
   const char* GetProperty(const std::string& prop) const;
   bool GetPropertyAsBool(const std::string& prop) const;

+ 1 - 1
Source/cmake.cxx

@@ -2374,7 +2374,7 @@ void cmake::SetProperty(const std::string& prop, const char* value)
   this->State->SetGlobalProperty(prop, value);
 }
 
-void cmake::AppendProperty(const std::string& prop, const char* value,
+void cmake::AppendProperty(const std::string& prop, const std::string& value,
                            bool asString)
 {
   this->State->AppendGlobalProperty(prop, value, asString);

+ 1 - 1
Source/cmake.h

@@ -359,7 +359,7 @@ public:
 
   //! Set/Get a property of this target file
   void SetProperty(const std::string& prop, const char* value);
-  void AppendProperty(const std::string& prop, const char* value,
+  void AppendProperty(const std::string& prop, const std::string& value,
                       bool asString = false);
   const char* GetProperty(const std::string& prop);
   bool GetPropertyAsBool(const std::string& prop);