cmVariableRequiresCommand.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(args.size() < 3 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. std::string testVariable = args[0];
  22. if(!this->Makefile->IsOn(testVariable.c_str()))
  23. {
  24. return true;
  25. }
  26. std::string resultVariable = args[1];
  27. bool requirementsMet = true;
  28. std::string notSet;
  29. bool hasAdvanced = false;
  30. for(unsigned int i = 2; i < args.size(); ++i)
  31. {
  32. if(!this->Makefile->IsOn(args[i].c_str()))
  33. {
  34. requirementsMet = false;
  35. notSet += args[i];
  36. notSet += "\n";
  37. cmCacheManager::CacheIterator it =
  38. this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str());
  39. if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
  40. {
  41. hasAdvanced = true;
  42. }
  43. }
  44. }
  45. const char* reqVar = this->Makefile->GetDefinition(resultVariable.c_str());
  46. // if reqVar is unset, then set it to requirementsMet
  47. // if reqVar is set to true, but requirementsMet is false , then
  48. // set reqVar to false.
  49. if(!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar)))
  50. {
  51. this->Makefile->AddDefinition(resultVariable.c_str(), requirementsMet);
  52. }
  53. if(!requirementsMet)
  54. {
  55. std::string message = "Variable assertion failed:\n";
  56. message += testVariable +
  57. " Requires that the following unset variables are set:\n";
  58. message += notSet;
  59. message += "\nPlease set them, or set ";
  60. message += testVariable + " to false, and re-configure.\n";
  61. if(hasAdvanced)
  62. {
  63. message +=
  64. "One or more of the required variables is advanced."
  65. " To set the variable, you must turn on advanced mode in cmake.";
  66. }
  67. cmSystemTools::Error(message.c_str());
  68. }
  69. return true;
  70. }