[Cmake-commits] [cmake-commits] king committed cmCMakePolicyCommand.cxx 1.3 1.4 cmCMakePolicyCommand.h 1.5 1.6

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Aug 18 09:53:08 EDT 2008


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

Modified Files:
	cmCMakePolicyCommand.cxx cmCMakePolicyCommand.h 
Log Message:
ENH: Add cmake_policy(GET) command mode

It is likely that projects or CMake modules in the future will need to
check the value of a policy setting.  For example, if we add a policy
that affects the results of FindXYZ.cmake modules, the module code will
need to be able to check the policy.


Index: cmCMakePolicyCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCMakePolicyCommand.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -C 2 -d -r1.3 -r1.4
*** cmCMakePolicyCommand.cxx	24 Mar 2008 14:56:26 -0000	1.3
--- cmCMakePolicyCommand.cxx	18 Aug 2008 13:53:06 -0000	1.4
***************
*** 33,36 ****
--- 33,40 ----
      return this->HandleSetMode(args);
      }
+   else if(args[0] == "GET")
+     {
+     return this->HandleGetMode(args);
+     }
    else if(args[0] == "PUSH")
      {
***************
*** 105,108 ****
--- 109,169 ----
  
  //----------------------------------------------------------------------------
+ bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
+ {
+   if(args.size() != 3)
+     {
+     this->SetError("GET must be given exactly 2 additional arguments.");
+     return false;
+     }
+ 
+   // Get arguments.
+   std::string const& id = args[1];
+   std::string const& var = args[2];
+ 
+   // Lookup the policy number.
+   cmPolicies::PolicyID pid;
+   if(!this->Makefile->GetPolicies()->GetPolicyID(id.c_str(), pid))
+     {
+     cmOStringStream e;
+     e << "GET given policy \"" << id << "\" which is not known to this "
+       << "version of CMake.";
+     this->SetError(e.str().c_str());
+     return false;
+     }
+ 
+   // Lookup the policy setting.
+   cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
+   switch (status)
+     {
+     case cmPolicies::OLD:
+       // Report that the policy is set to OLD.
+       this->Makefile->AddDefinition(var.c_str(), "OLD");
+       break;
+     case cmPolicies::WARN:
+       // Report that the policy is not set.
+       this->Makefile->AddDefinition(var.c_str(), "");
+       break;
+     case cmPolicies::NEW:
+       // Report that the policy is set to NEW.
+       this->Makefile->AddDefinition(var.c_str(), "NEW");
+       break;
+     case cmPolicies::REQUIRED_IF_USED:
+     case cmPolicies::REQUIRED_ALWAYS:
+       // The policy is required to be set before anything needs it.
+       {
+       cmOStringStream e;
+       e << this->Makefile->GetPolicies()->GetRequiredPolicyError(pid)
+         << "\n"
+         << "The call to cmake_policy(GET " << id << " ...) at which this "
+         << "error appears requests the policy, and this version of CMake "
+         << "requires that the policy be set to NEW before it is checked.";
+       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+       }
+     }
+ 
+   return true;
+ }
+ 
+ //----------------------------------------------------------------------------
  bool
  cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)

Index: cmCMakePolicyCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCMakePolicyCommand.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C 2 -d -r1.5 -r1.6
*** cmCMakePolicyCommand.h	18 Mar 2008 00:30:47 -0000	1.5
--- cmCMakePolicyCommand.h	18 Aug 2008 13:53:06 -0000	1.6
***************
*** 109,112 ****
--- 109,117 ----
        "and set the policy state to NEW."
        "\n"
+       "  cmake_policy(GET CMP<NNNN> <variable>)\n"
+       "Check whether a given policy is set to OLD or NEW behavior.  "
+       "The output variable value will be \"OLD\" or \"NEW\" if the "
+       "policy is set, and empty otherwise."
+       "\n"
        "  cmake_policy(PUSH)\n"
        "  cmake_policy(POP)\n"
***************
*** 124,127 ****
--- 129,133 ----
  private:
    bool HandleSetMode(std::vector<std::string> const& args);
+   bool HandleGetMode(std::vector<std::string> const& args);
    bool HandleVersionMode(std::vector<std::string> const& args);
  };



More information about the Cmake-commits mailing list