cmVariableRequiresCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmVariableRequiresCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmLibraryCommand
  16. bool cmVariableRequiresCommand::InitialPass(std::vector<std::string>const&
  17. args)
  18. {
  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(!m_Makefile->IsOn(testVariable.c_str()))
  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(!m_Makefile->IsOn(args[i].c_str()))
  36. {
  37. requirementsMet = false;
  38. notSet += args[i];
  39. notSet += "\n";
  40. cmCacheManager::CacheIterator it =
  41. m_Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str());
  42. if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
  43. {
  44. hasAdvanced = true;
  45. }
  46. }
  47. }
  48. const char* reqVar = m_Makefile->GetDefinition(resultVariable.c_str());
  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 && m_Makefile->IsOn(reqVar)))
  53. {
  54. m_Makefile->AddDefinition(resultVariable.c_str(), 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. }