[Cmake-commits] [cmake-commits] king committed cmCacheManager.cxx 1.105 1.106 cmCacheManager.h 1.50 1.51 cmGetPropertyCommand.cxx 1.11 1.12 cmGetPropertyCommand.h 1.8 1.9 cmSetPropertyCommand.cxx 1.9 1.10 cmSetPropertyCommand.h 1.4 1.5

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Mar 10 11:11:01 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv23956/Source

Modified Files:
	cmCacheManager.cxx cmCacheManager.h cmGetPropertyCommand.cxx 
	cmGetPropertyCommand.h cmSetPropertyCommand.cxx 
	cmSetPropertyCommand.h 
Log Message:
ENH: Teach set/get_property about CACHE properties

This adds the CACHE option to set_property and get_property commands.
This allows full control over cache entry information, so advanced users
can tweak their project cache as desired.  The set_property command
allows only pre-defined CACHE properties to be set since others would
not persist anyway.


Index: cmCacheManager.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCacheManager.cxx,v
retrieving revision 1.105
retrieving revision 1.106
diff -C 2 -d -r1.105 -r1.106
*** cmCacheManager.cxx	10 Mar 2009 15:10:41 -0000	1.105
--- cmCacheManager.cxx	10 Mar 2009 15:10:59 -0000	1.106
***************
*** 72,75 ****
--- 72,87 ----
  }
  
+ bool cmCacheManager::IsType(const char* s)
+ {
+   for(int i=0; cmCacheManagerTypes[i]; ++i)
+     {
+     if(strcmp(s, cmCacheManagerTypes[i]) == 0)
+       {
+       return true;
+       }
+     }
+   return false;
+ }
+ 
  bool cmCacheManager::LoadCache(cmMakefile* mf)
  {

Index: cmSetPropertyCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSetPropertyCommand.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -C 2 -d -r1.9 -r1.10
*** cmSetPropertyCommand.cxx	5 Jan 2009 20:00:57 -0000	1.9
--- cmSetPropertyCommand.cxx	10 Mar 2009 15:10:59 -0000	1.10
***************
*** 20,23 ****
--- 20,25 ----
  #include "cmSetSourceFilesPropertiesCommand.h"
  
+ #include "cmCacheManager.h"
+ 
  //----------------------------------------------------------------------------
  cmSetPropertyCommand::cmSetPropertyCommand()
***************
*** 60,68 ****
      scope = cmProperty::TEST;
      }
    else
      {
      cmOStringStream e;
      e << "given invalid scope " << *arg << ".  "
!       << "Valid scopes are GLOBAL, DIRECTORY, TARGET, SOURCE, TEST.";
      this->SetError(e.str().c_str());
      return false;
--- 62,74 ----
      scope = cmProperty::TEST;
      }
+   else if(*arg == "CACHE")
+     {
+     scope = cmProperty::CACHE;
+     }
    else
      {
      cmOStringStream e;
      e << "given invalid scope " << *arg << ".  "
!       << "Valid scopes are GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, CACHE.";
      this->SetError(e.str().c_str());
      return false;
***************
*** 124,127 ****
--- 130,134 ----
      case cmProperty::SOURCE_FILE: return this->HandleSourceMode();
      case cmProperty::TEST:        return this->HandleTestMode();
+     case cmProperty::CACHE:       return this->HandleCacheMode();
  
      case cmProperty::VARIABLE:
***************
*** 385,386 ****
--- 392,479 ----
    return true;
  }
+ 
+ //----------------------------------------------------------------------------
+ bool cmSetPropertyCommand::HandleCacheMode()
+ {
+   if(this->PropertyName == "ADVANCED")
+     {
+     if(!this->Remove &&
+        !cmSystemTools::IsOn(this->PropertyValue.c_str()) &&
+        !cmSystemTools::IsOff(this->PropertyValue.c_str()))
+       {
+       cmOStringStream e;
+       e << "given non-boolean value \"" << this->PropertyValue
+         << "\" for CACHE property \"ADVANCED\".  ";
+       this->SetError(e.str().c_str());
+       return false;
+       }
+     }
+   else if(this->PropertyName == "TYPE")
+     {
+     if(!cmCacheManager::IsType(this->PropertyValue.c_str()))
+       {
+       cmOStringStream e;
+       e << "given invalid CACHE entry TYPE \"" << this->PropertyValue << "\"";
+       this->SetError(e.str().c_str());
+       return false;
+       }
+     }
+   else if(this->PropertyName != "HELPSTRING" &&
+           this->PropertyName != "VALUE")
+     {
+     cmOStringStream e;
+     e << "given invalid CACHE property " << this->PropertyName << ".  "
+       << "Settable CACHE properties are: "
+       << "ADVANCED, HELPSTRING, TYPE, and VALUE.";
+     this->SetError(e.str().c_str());
+     return false;
+     }
+ 
+   for(std::set<cmStdString>::const_iterator ni = this->Names.begin();
+       ni != this->Names.end(); ++ni)
+     {
+     // Get the source file.
+     cmMakefile* mf = this->GetMakefile();
+     cmake* cm = mf->GetCMakeInstance();
+     cmCacheManager::CacheIterator it =
+       cm->GetCacheManager()->GetCacheIterator(ni->c_str());
+     if(!it.IsAtEnd())
+       {
+       if(!this->HandleCacheEntry(it))
+         {
+         return false;
+         }
+       }
+     else
+       {
+       cmOStringStream e;
+       e << "could not find CACHE variable " << *ni
+         << ".  Perhaps it has not yet been created.";
+       this->SetError(e.str().c_str());
+       return false;
+       }
+     }
+   return true;
+ }
+ 
+ //----------------------------------------------------------------------------
+ bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it)
+ {
+   // Set or append the property.
+   const char* name = this->PropertyName.c_str();
+   const char* value = this->PropertyValue.c_str();
+   if (this->Remove)
+     {
+     value = 0;
+     }
+   if(this->AppendMode)
+     {
+     it.AppendProperty(name, value);
+     }
+   else
+     {
+     it.SetProperty(name, value);
+     }
+ 
+   return true;
+ }

Index: cmCacheManager.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCacheManager.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -C 2 -d -r1.50 -r1.51
*** cmCacheManager.h	10 Mar 2009 15:10:42 -0000	1.50
--- cmCacheManager.h	10 Mar 2009 15:10:59 -0000	1.51
***************
*** 106,109 ****
--- 106,110 ----
    static CacheEntryType StringToType(const char*);
    static const char* TypeToString(CacheEntryType);
+   static bool IsType(const char*);
    
    ///! Load a cache for given makefile.  Loads from ouput home.

Index: cmGetPropertyCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGetPropertyCommand.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -C 2 -d -r1.11 -r1.12
*** cmGetPropertyCommand.cxx	9 Mar 2009 21:57:12 -0000	1.11
--- cmGetPropertyCommand.cxx	10 Mar 2009 15:10:59 -0000	1.12
***************
*** 66,69 ****
--- 66,73 ----
      scope = cmProperty::VARIABLE;
      }
+   else if(args[1] == "CACHE")
+     {
+     scope = cmProperty::CACHE;
+     }
    else
      {
***************
*** 71,75 ****
      e << "given invalid scope " << args[1] << ".  "
        << "Valid scopes are "
!       << "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE.";
      this->SetError(e.str().c_str());
      return false;
--- 75,79 ----
      e << "given invalid scope " << args[1] << ".  "
        << "Valid scopes are "
!       << "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE.";
      this->SetError(e.str().c_str());
      return false;
***************
*** 188,191 ****
--- 192,196 ----
        case cmProperty::TEST:        return this->HandleTestMode();
        case cmProperty::VARIABLE:    return this->HandleVariableMode();
+       case cmProperty::CACHE:       return this->HandleCacheMode();
  
        case cmProperty::CACHED_VARIABLE:
***************
*** 360,361 ****
--- 365,386 ----
      (this->Makefile->GetDefinition(this->PropertyName.c_str()));
  }
+ 
+ //----------------------------------------------------------------------------
+ bool cmGetPropertyCommand::HandleCacheMode()
+ {
+   if(this->Name.empty())
+     {
+     this->SetError("not given name for CACHE scope.");
+     return false;
+     }
+ 
+   const char* value = 0;
+   cmCacheManager::CacheIterator it =
+     this->Makefile->GetCacheManager()->GetCacheIterator(this->Name.c_str());
+   if(!it.IsAtEnd())
+     {
+     value = it.GetProperty(this->PropertyName.c_str());
+     }
+   this->StoreResult(value);
+   return true;
+ }

Index: cmSetPropertyCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSetPropertyCommand.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -d -r1.4 -r1.5
*** cmSetPropertyCommand.h	1 Apr 2008 18:22:07 -0000	1.4
--- cmSetPropertyCommand.h	10 Mar 2009 15:10:59 -0000	1.5
***************
*** 60,64 ****
          "                TARGET    [target1 [target2 ...]] |\n"
          "                SOURCE    [src1 [src2 ...]]       |\n"
!         "                TEST      [test1 [test2 ...]]>\n"
          "               [APPEND]\n"
          "               PROPERTY <name> [value1 [value2 ...]])\n"
--- 60,65 ----
          "                TARGET    [target1 [target2 ...]] |\n"
          "                SOURCE    [src1 [src2 ...]]       |\n"
!         "                TEST      [test1 [test2 ...]]     |\n"
!         "                CACHE     [entry1 [entry2 ...]]>\n"
          "               [APPEND]\n"
          "               PROPERTY <name> [value1 [value2 ...]])\n"
***************
*** 73,76 ****
--- 74,78 ----
          "SOURCE scope may name zero or more source files.\n"
          "TEST scope may name zero or more existing tests.\n"
+         "CACHE scope must name zero or more cache existing entries.\n"
          "The required PROPERTY option is immediately followed by the name "
          "of the property to set.  Remaining arguments are used to "
***************
*** 105,108 ****
--- 107,112 ----
    bool HandleTestMode();
    bool HandleTest(cmTest* test);
+   bool HandleCacheMode();
+   bool HandleCacheEntry(cmCacheManager::CacheIterator&);
  };
  

Index: cmGetPropertyCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGetPropertyCommand.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C 2 -d -r1.8 -r1.9
*** cmGetPropertyCommand.h	4 Sep 2008 17:15:18 -0000	1.8
--- cmGetPropertyCommand.h	10 Mar 2009 15:10:59 -0000	1.9
***************
*** 67,70 ****
--- 67,71 ----
          "                SOURCE    <source> |\n"
          "                TEST      <test>   |\n"
+         "                CACHE     <entry>  |\n"
          "                VARIABLE>\n"
          "               PROPERTY <name>\n"
***************
*** 82,85 ****
--- 83,87 ----
          "SOURCE scope must name one source file.\n"
          "TEST scope must name one existing test.\n"
+         "CACHE scope must name one cache entry.\n"
          "VARIABLE scope is unique and does not accept a name.\n"
          "The required PROPERTY option is immediately followed by the name "
***************
*** 115,118 ****
--- 117,121 ----
    bool HandleTestMode();
    bool HandleVariableMode();
+   bool HandleCacheMode();
  };
  



More information about the Cmake-commits mailing list