cmVariableRequiresCommand.cxx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmVariableRequiresCommand.h"
  11. #include "cmCacheManager.h"
  12. // cmLibraryCommand
  13. bool cmVariableRequiresCommand
  14. ::InitialPass(std::vector<std::string>const& args, cmExecutionStatus &)
  15. {
  16. if(this->Disallowed(cmPolicies::CMP0035,
  17. "The variable_requires command should not be called; see CMP0035."))
  18. { return true; }
  19. if(args.size() < 3 )
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. std::string testVariable = args[0];
  25. if(!this->Makefile->IsOn(testVariable))
  26. {
  27. return true;
  28. }
  29. std::string resultVariable = args[1];
  30. bool requirementsMet = true;
  31. std::string notSet;
  32. bool hasAdvanced = false;
  33. for(unsigned int i = 2; i < args.size(); ++i)
  34. {
  35. if(!this->Makefile->IsOn(args[i]))
  36. {
  37. requirementsMet = false;
  38. notSet += args[i];
  39. notSet += "\n";
  40. cmCacheManager* manager = this->Makefile->GetCacheManager();
  41. if(manager->GetCacheEntryValue(args[i]) &&
  42. manager->GetCacheEntryPropertyAsBool(args[i], "ADVANCED"))
  43. {
  44. hasAdvanced = true;
  45. }
  46. }
  47. }
  48. const char* reqVar = this->Makefile->GetDefinition(resultVariable);
  49. // if reqVar is unset, then set it to requirementsMet
  50. // if reqVar is set to true, but requirementsMet is false , then
  51. // set reqVar to false.
  52. if(!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar)))
  53. {
  54. this->Makefile->AddDefinition(resultVariable, requirementsMet);
  55. }
  56. if(!requirementsMet)
  57. {
  58. std::string message = "Variable assertion failed:\n";
  59. message += testVariable +
  60. " Requires that the following unset variables are set:\n";
  61. message += notSet;
  62. message += "\nPlease set them, or set ";
  63. message += testVariable + " to false, and re-configure.\n";
  64. if(hasAdvanced)
  65. {
  66. message +=
  67. "One or more of the required variables is advanced."
  68. " To set the variable, you must turn on advanced mode in cmake.";
  69. }
  70. cmSystemTools::Error(message.c_str());
  71. }
  72. return true;
  73. }