[Cmake-commits] [cmake-commits] king committed cmCMakePolicyCommand.h 1.7 1.8 cmFunctionCommand.cxx 1.10 1.11 cmFunctionCommand.h 1.4 1.5 cmMacroCommand.cxx 1.40 1.41 cmMacroCommand.h 1.17 1.18 cmMakefile.cxx 1.500 1.501 cmMakefile.h 1.251 1.252

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Jan 22 13:16:49 EST 2009


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

Modified Files:
	cmCMakePolicyCommand.h cmFunctionCommand.cxx 
	cmFunctionCommand.h cmMacroCommand.cxx cmMacroCommand.h 
	cmMakefile.cxx cmMakefile.h 
Log Message:
ENH: Better policies for functions and macros

This teaches functions and macros to use policies recorded at creation
time when they are invoked.  It restores the policies as a weak policy
stack entry so that any policies set by a function escape to its caller
as before.


Index: cmFunctionCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFunctionCommand.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -d -r1.4 -r1.5
*** cmFunctionCommand.h	21 Jan 2009 14:48:20 -0000	1.4
--- cmFunctionCommand.h	22 Jan 2009 18:16:47 -0000	1.5
***************
*** 105,109 ****
        "facilitates creating functions with optional arguments. Additionally "
        "ARGV holds the list of all arguments given to the function and ARGN "
!       "holds the list of argument pass the last expected argument.";
      }
  
--- 105,113 ----
        "facilitates creating functions with optional arguments. Additionally "
        "ARGV holds the list of all arguments given to the function and ARGN "
!       "holds the list of argument pass the last expected argument."
!       "\n"
!       "See the cmake_policy() command documentation for the behavior of "
!       "policies inside functions."
!       ;
      }
  

Index: cmMacroCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMacroCommand.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C 2 -d -r1.17 -r1.18
*** cmMacroCommand.h	21 Jan 2009 14:48:20 -0000	1.17
--- cmMacroCommand.h	22 Jan 2009 18:16:47 -0000	1.18
***************
*** 112,116 ****
        "replacements much like the c preprocessor would do with a "
        "macro. If you want true CMake variables you should look at "
!       "the function command.";
      }
  
--- 112,120 ----
        "replacements much like the c preprocessor would do with a "
        "macro. If you want true CMake variables you should look at "
!       "the function command."
!       "\n"
!       "See the cmake_policy() command documentation for the behavior of "
!       "policies inside macros."
!       ;
      }
  

Index: cmMacroCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMacroCommand.cxx,v
retrieving revision 1.40
retrieving revision 1.41
diff -C 2 -d -r1.40 -r1.41
*** cmMacroCommand.cxx	21 Jan 2009 14:49:31 -0000	1.40
--- cmMacroCommand.cxx	22 Jan 2009 18:16:47 -0000	1.41
***************
*** 37,40 ****
--- 37,41 ----
      newC->Args = this->Args;
      newC->Functions = this->Functions;
+     newC->Policies = this->Policies;
      return newC;
    }
***************
*** 82,85 ****
--- 83,87 ----
    std::vector<std::string> Args;
    std::vector<cmListFileFunction> Functions;
+   cmPolicies::PolicyMap Policies;
  };
  
***************
*** 111,114 ****
--- 113,120 ----
    cmMakefile::LexicalPushPop lexScope(this->Makefile);
  
+   // Push a weak policy scope which restores the policies recorded at
+   // macro creation.
+   cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies);
+ 
    // set the value of argc
    cmOStringStream argcDefStream;
***************
*** 220,223 ****
--- 226,230 ----
        // so we do not need to report an error here.
        lexScope.Quiet();
+       polScope.Quiet();
        inStatus.SetNestedError(true);
        return false;
***************
*** 265,268 ****
--- 272,276 ----
        f->Args = this->Args;
        f->Functions = this->Functions;
+       mf.RecordPolicies(f->Policies);
        std::string newName = "_" + this->Args[0];
        mf.GetCMakeInstance()->RenameCommand(this->Args[0].c_str(), 

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.251
retrieving revision 1.252
diff -C 2 -d -r1.251 -r1.252
*** cmMakefile.h	22 Jan 2009 18:16:27 -0000	1.251
--- cmMakefile.h	22 Jan 2009 18:16:47 -0000	1.252
***************
*** 344,347 ****
--- 344,348 ----
    cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
    bool SetPolicyVersion(const char *version);
+   void RecordPolicies(cmPolicies::PolicyMap& pm);
    //@}
  

Index: cmFunctionCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFunctionCommand.cxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -C 2 -d -r1.10 -r1.11
*** cmFunctionCommand.cxx	21 Jan 2009 14:49:31 -0000	1.10
--- cmFunctionCommand.cxx	22 Jan 2009 18:16:47 -0000	1.11
***************
*** 37,40 ****
--- 37,41 ----
      newC->Args = this->Args;
      newC->Functions = this->Functions;
+     newC->Policies = this->Policies;
      return newC;
    }
***************
*** 82,85 ****
--- 83,87 ----
    std::vector<std::string> Args;
    std::vector<cmListFileFunction> Functions;
+   cmPolicies::PolicyMap Policies;
  };
  
***************
*** 109,112 ****
--- 111,118 ----
    static_cast<void>(varScope);
  
+   // Push a weak policy scope which restores the policies recorded at
+   // function creation.
+   cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies);
+ 
    // set the value of argc
    cmOStringStream strStream;
***************
*** 166,169 ****
--- 172,176 ----
        // so we do not need to report an error here.
        lexScope.Quiet();
+       polScope.Quiet();
        inStatus.SetNestedError(true);
        return false;
***************
*** 207,210 ****
--- 214,218 ----
        f->Args = this->Args;
        f->Functions = this->Functions;
+       mf.RecordPolicies(f->Policies);
        
        // Set the FilePath on the arguments to match the function since it is

Index: cmCMakePolicyCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCMakePolicyCommand.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** cmCMakePolicyCommand.h	22 Jan 2009 18:16:33 -0000	1.7
--- cmCMakePolicyCommand.h	22 Jan 2009 18:16:47 -0000	1.8
***************
*** 124,127 ****
--- 124,133 ----
        "Each PUSH must have a matching POP to erase any changes.  "
        "This is useful to make temporary changes to policy settings."
+       "\n"
+       "Functions and macros record policy settings when they are created "
+       "and use the pre-record policies when they are invoked.  "
+       "If the function or macro implementation sets policies, the changes "
+       "automatically propagate up through callers until they reach the "
+       "closest nested policy stack entry."
        ;
      }

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.500
retrieving revision 1.501
diff -C 2 -d -r1.500 -r1.501
*** cmMakefile.cxx	22 Jan 2009 18:16:27 -0000	1.500
--- cmMakefile.cxx	22 Jan 2009 18:16:47 -0000	1.501
***************
*** 3775,3776 ****
--- 3775,3788 ----
    return this->GetCMakeInstance()->GetPolicies();
  }
+ 
+ //----------------------------------------------------------------------------
+ void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
+ {
+   /* Record the setting of every policy.  */
+   typedef cmPolicies::PolicyID PolicyID;
+   for(PolicyID pid = cmPolicies::CMP0000;
+       pid != cmPolicies::CMPCOUNT; pid = PolicyID(pid+1))
+     {
+     pm[pid] = this->GetPolicyStatus(pid);
+     }
+ }



More information about the Cmake-commits mailing list