Browse Source

ENH: implements SetProperties for TEST

Ken Martin 19 years ago
parent
commit
a00200e8d4

+ 17 - 0
Source/cmSetPropertiesCommand.cxx

@@ -16,6 +16,7 @@
 =========================================================================*/
 #include "cmSetPropertiesCommand.h"
 #include "cmSetTargetPropertiesCommand.h"
+#include "cmSetTestsPropertiesCommand.h"
 
 // cmSetPropertiesCommand
 bool cmSetPropertiesCommand::InitialPass(
@@ -87,6 +88,11 @@ bool cmSetPropertiesCommand::InitialPass(
     scope = cmProperty::TARGET;
     scopeName = args[1].c_str();
     }
+  else if (args[0] == "TEST" && numFiles == 2)
+    {
+    scope = cmProperty::TEST;
+    scopeName = args[1].c_str();
+    }
   else
     {
     this->SetError("called with illegal arguments.");
@@ -133,6 +139,17 @@ bool cmSetPropertiesCommand::InitialPass(
       }
       break;
     case cmProperty::TEST:
+      {
+      std::string errors;
+      bool ret = cmSetTestsPropertiesCommand::
+        SetOneTest(scopeName,propertyPairs, this->Makefile, errors);
+      if (!ret)
+        {
+        this->SetError(errors.c_str());
+        }
+      return ret;
+      }
+      break;
     case cmProperty::SOURCE_FILE:
       // not implemented yet
       break;

+ 1 - 1
Source/cmSetPropertiesCommand.h

@@ -56,7 +56,7 @@ public:
         "                 PROPERTIES prop1 value1\n"
         "                 prop2 value2 ...)\n"
         "Set properties on something. The scope_value is either GLOBAL "
-        "DIRECTORY dir_name> or TARGET tgt_name."
+        "DIRECTORY dir_name, TARGET tgt_name, or TEST test_name."
         ;
     }
   

+ 46 - 23
Source/cmSetTestsPropertiesCommand.cxx

@@ -74,38 +74,61 @@ bool cmSetTestsPropertiesCommand::InitialPass(
     return false;
     }
 
+
   std::vector<cmTest*> &tests = *this->Makefile->GetTests();
   // now loop over all the targets
   int i;
-  unsigned int k;
   for(i = 0; i < numFiles; ++i)
     {   
-    bool found = false;
-    // if the file is already in the makefile just set properites on it
-    std::vector<cmTest*>::iterator it;
-    for ( it = tests.begin(); it != tests.end(); ++ it )
+    std::string errors;
+    bool ret = 
+      cmSetTestsPropertiesCommand::SetOneTest(args[i].c_str(), 
+                                              propertyPairs,
+                                              this->Makefile, errors);
+    if (!ret)
       {
-      cmTest* test = *it;
-      if ( test->GetName() == args[i] )
-        {
-        // now loop through all the props and set them
-        for (k = 0; k < propertyPairs.size(); k = k + 2)
-          {
-          test->SetProperty(propertyPairs[k].c_str(),
-                            propertyPairs[k+1].c_str());
-          }
-        found = true;
-        break;
-        }
+      this->SetError(errors.c_str());
+      return ret;
       }
+    }
+
+  return true;
+}
+
 
-    // if file is not already in the makefile, then add it
-    if ( ! found )
-      { 
-      std::string message = "Can not find test to add properties to: ";
-      message += args[i];
-      this->SetError(message.c_str());
+bool cmSetTestsPropertiesCommand
+::SetOneTest(const char *tname, 
+             std::vector<std::string> &propertyPairs,
+             cmMakefile *mf, std::string &errors)
+{
+  std::vector<cmTest*> &tests = *mf->GetTests();
+  // now loop over all the targets
+  unsigned int k;
+  bool found = false;
+  // if the file is already in the makefile just set properites on it
+  std::vector<cmTest*>::iterator it;
+  for ( it = tests.begin(); it != tests.end(); ++ it )
+    {
+    cmTest* test = *it;
+    if ( test->GetName() == tname )
+      {
+      // now loop through all the props and set them
+      for (k = 0; k < propertyPairs.size(); k = k + 2)
+        {
+        test->SetProperty(propertyPairs[k].c_str(),
+                          propertyPairs[k+1].c_str());
+        }
+      found = true;
+      break;
       }
+    }
+  
+  // if file is not already in the makefile, then add it
+  if ( ! found )
+    { 
+    errors = "Can not find test to add properties to: ";
+    errors += tname;
+    return false;
     } 
 
   return true;

+ 5 - 0
Source/cmSetTestsPropertiesCommand.h

@@ -71,6 +71,11 @@ public:
     }
 
   cmTypeMacro(cmSetTestsPropertiesCommand, cmCommand);
+
+  static bool SetOneTest(const char *tname, 
+                         std::vector<std::string> &propertyPairs,
+                         cmMakefile *mf,
+                         std::string &errors);
 };