Răsfoiți Sursa

ENH: Define target and source property LABELS

This creates a new LABELS property for targets and source files.  We
write the labels of each target and its source files in target-specific
locations in the build tree for future use.
Brad King 17 ani în urmă
părinte
comite
13f9bb646d
4 a modificat fișierele cu 105 adăugiri și 0 ștergeri
  1. 90 0
      Source/cmGlobalGenerator.cxx
  2. 3 0
      Source/cmGlobalGenerator.h
  3. 7 0
      Source/cmSourceFile.cxx
  4. 5 0
      Source/cmTarget.cxx

+ 90 - 0
Source/cmGlobalGenerator.cxx

@@ -897,6 +897,8 @@ void cmGlobalGenerator::Generate()
   // Update rule hashes.
   // Update rule hashes.
   this->CheckRuleHashes();
   this->CheckRuleHashes();
 
 
+  this->WriteTargetLabels();
+
   if (this->ExtraGenerator != 0)
   if (this->ExtraGenerator != 0)
     {
     {
     this->ExtraGenerator->Generate();
     this->ExtraGenerator->Generate();
@@ -2120,3 +2122,91 @@ void cmGlobalGenerator::CheckRuleHashes()
     }
     }
 #endif
 #endif
 }
 }
+
+//----------------------------------------------------------------------------
+void cmGlobalGenerator::WriteTargetLabels()
+{
+  cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
+
+  // Record generated per-target label files in a central location.
+  std::string fname = mf->GetHomeOutputDirectory();
+  fname += cmake::GetCMakeFilesDirectory();
+  fname += "/LabelFiles.txt";
+  bool opened = false;
+  cmGeneratedFileStream fout;
+
+  // Generate a label file for each target.
+  std::string file;
+  for(std::map<cmStdString,cmTarget *>::const_iterator ti =
+        this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
+    {
+    if(this->WriteTargetLabels(ti->second, file))
+      {
+      if(!opened)
+        {
+        fout.Open(fname.c_str());
+        }
+      fout << file << "\n";
+      }
+    }
+  if(!opened)
+    {
+    cmSystemTools::RemoveFile(fname.c_str());
+    }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalGenerator::WriteTargetLabels(cmTarget* target, std::string& file)
+{
+  // Place the labels file in a per-target support directory.
+  std::string dir = target->GetSupportDirectory();
+  file = dir;
+  file += "/Labels.txt";
+
+  // Check whether labels are enabled for this target.
+  if(const char* value = target->GetProperty("LABELS"))
+    {
+    cmSystemTools::MakeDirectory(dir.c_str());
+    cmGeneratedFileStream fout(file.c_str());
+
+    // List the target-wide labels.  All sources in the target get
+    // these labels.
+    std::vector<std::string> labels;
+    cmSystemTools::ExpandListArgument(value, labels);
+    if(!labels.empty())
+      {
+      fout << "# Target labels\n";
+      for(std::vector<std::string>::const_iterator li = labels.begin();
+          li != labels.end(); ++li)
+        {
+        fout << " " << *li << "\n";
+        }
+      }
+
+    // List the source files with any per-source labels.
+    fout << "# Source files and their labels\n";
+    std::vector<cmSourceFile*> const& sources = target->GetSourceFiles();
+    for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
+        si != sources.end(); ++si)
+      {
+      cmSourceFile* sf = *si;
+      fout << sf->GetFullPath() << "\n";
+      if(const char* svalue = sf->GetProperty("LABELS"))
+        {
+        labels.clear();
+        cmSystemTools::ExpandListArgument(svalue, labels);
+        for(std::vector<std::string>::const_iterator li = labels.begin();
+            li != labels.end(); ++li)
+          {
+          fout << " " << *li << "\n";
+          }
+        }
+      }
+    return true;
+    }
+  else
+    {
+    cmSystemTools::RemoveFile(file.c_str());
+    return false;
+    }
+}

+ 3 - 0
Source/cmGlobalGenerator.h

@@ -328,6 +328,9 @@ private:
   std::map<cmStdString, RuleHash> RuleHashes;
   std::map<cmStdString, RuleHash> RuleHashes;
   void CheckRuleHashes();
   void CheckRuleHashes();
 
 
+  void WriteTargetLabels();
+  bool WriteTargetLabels(cmTarget* target, std::string& file);
+
   cmExternalMakefileProjectGenerator* ExtraGenerator;
   cmExternalMakefileProjectGenerator* ExtraGenerator;
 
 
   // track files replaced during a Generate
   // track files replaced during a Generate

+ 7 - 0
Source/cmSourceFile.cxx

@@ -476,6 +476,13 @@ void cmSourceFile::DefineProperties(cmake *cm)
      "the output file extension is computed based on the language "
      "the output file extension is computed based on the language "
      "of the source file, for example .cxx will go to a .o extension.");
      "of the source file, for example .cxx will go to a .o extension.");
 
 
+  cm->DefineProperty
+    ("LABELS", cmProperty::SOURCE_FILE,
+     "Specify a list of text labels associated with a source file.",
+     "This property has meaning only when the source file is listed in "
+     "a target whose LABELS property is also set.  "
+     "No other semantics are currently specified.");
+
   cm->DefineProperty
   cm->DefineProperty
     ("LANGUAGE", cmProperty::SOURCE_FILE, 
     ("LANGUAGE", cmProperty::SOURCE_FILE, 
      "What programming language is the file.",
      "What programming language is the file.",

+ 5 - 0
Source/cmTarget.cxx

@@ -350,6 +350,11 @@ void cmTarget::DefineProperties(cmake *cm)
      "append directories in the linker search path and outside the "
      "append directories in the linker search path and outside the "
      "project to the INSTALL_RPATH. ");
      "project to the INSTALL_RPATH. ");
 
 
+  cm->DefineProperty
+    ("LABELS", cmProperty::TARGET,
+     "Specify a list of text labels associated with a target.",
+     "Target label semantics are currently unspecified.");
+
   cm->DefineProperty
   cm->DefineProperty
     ("LINK_FLAGS", cmProperty::TARGET,
     ("LINK_FLAGS", cmProperty::TARGET,
      "Additional flags to use when linking this target.",
      "Additional flags to use when linking this target.",