diff options
author | Brad King <brad.king@kitware.com> | 2008-03-05 23:21:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-03-05 23:21:10 (GMT) |
commit | 49549560b2ecdb4cf1c3aa155c3dccd4688a8de7 (patch) | |
tree | 333c732f9058d19ab6389b558f418ad16a592592 /Source/cmCMakePolicyCommand.cxx | |
parent | 7c01167666077453b01846f47227e27be165b659 (diff) | |
download | CMake-49549560b2ecdb4cf1c3aa155c3dccd4688a8de7.zip CMake-49549560b2ecdb4cf1c3aa155c3dccd4688a8de7.tar.gz CMake-49549560b2ecdb4cf1c3aa155c3dccd4688a8de7.tar.bz2 |
ENH: Improve cmake_policy command signature
- Replace NEW and OLD modes with a SET mode for clarity
- Enforce VERSION argument validity (major.minor[.patch])
Diffstat (limited to 'Source/cmCMakePolicyCommand.cxx')
-rw-r--r-- | Source/cmCMakePolicyCommand.cxx | 131 |
1 files changed, 101 insertions, 30 deletions
diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx index fddd97f..f29938d 100644 --- a/Source/cmCMakePolicyCommand.cxx +++ b/Source/cmCMakePolicyCommand.cxx @@ -22,37 +22,108 @@ bool cmCMakePolicyCommand ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) { - if (args.size() < 1) - { - this->SetError("cmake_policy requires at least one argument."); + if(args.size() < 1) + { + this->SetError("requires at least one argument."); return false; - } - - if (args[0] == "OLD" && args.size() == 2) - { - return this->Makefile->SetPolicy(args[1].c_str(),cmPolicies::OLD); - } - - if (args[0] == "NEW" && args.size() == 2) - { - return this->Makefile->SetPolicy(args[1].c_str(),cmPolicies::NEW); - } - - if (args[0] == "VERSION" && args.size() == 2) - { - return this->Makefile->SetPolicyVersion(args[1].c_str()); - } - - if (args[0] == "PUSH" && args.size() == 1) - { + } + + if(args[0] == "SET") + { + return this->HandleSetMode(args); + } + else if(args[0] == "PUSH") + { + if(args.size() > 1) + { + this->SetError("PUSH may not be given additional arguments."); + return false; + } return this->Makefile->PushPolicy(); - } - - if (args[0] == "POP" && args.size() == 1) - { - return this->Makefile->PopPolicy(); - } - - this->SetError("incorrect arguments for cmake_policy."); + } + else if(args[0] == "POP") + { + if(args.size() > 1) + { + this->SetError("POP may not be given additional arguments."); + return false; + } + if(this->Makefile->PopPolicy(false)) + { + return true; + } + else + { + this->SetError("POP without matching PUSH"); + return false; + } + } + else if(args[0] == "VERSION") + { + return this->HandleVersionMode(args); + } + + cmOStringStream e; + e << "given unknown first argument \"" << args[0] << "\""; + this->SetError(e.str().c_str()); return false; } + +//---------------------------------------------------------------------------- +bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args) +{ + if(args.size() != 3) + { + this->SetError("SET must be given exactly 2 additional arguments."); + return false; + } + + cmPolicies::PolicyStatus status; + if(args[2] == "OLD") + { + status = cmPolicies::OLD; + } + else if(args[2] == "NEW") + { + status = cmPolicies::NEW; + } + else + { + cmOStringStream e; + e << "SET given unrecognized policy status \"" << args[2] << "\""; + this->SetError(e.str().c_str()); + return false; + } + + if(!this->Makefile->SetPolicy(args[1].c_str(), status)) + { + this->SetError("SET failed to set policy."); + return false; + } + return true; +} + +//---------------------------------------------------------------------------- +bool +cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args) +{ + if(args.size() <= 1) + { + this->SetError("VERSION not given an argument"); + return false; + } + else if(args.size() >= 3) + { + this->SetError("VERSION given too many arguments"); + return false; + } + if(!this->Makefile->SetPolicyVersion(args[1].c_str())) + { + cmOStringStream e; + e << "VERSION given invalid value \"" << args[1] << "\". " + << "A numeric major.minor[.patch] must be given."; + this->SetError(e.str().c_str()); + return false; + } + return true; +} |