cmVariableRequiresCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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& args)
  17. {
  18. if(args.size() < 3 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. cmSystemTools::ExpandListArguments(args, m_Arguments);
  24. return true;
  25. }
  26. void cmVariableRequiresCommand::FinalPass()
  27. {
  28. std::string testVarible = m_Arguments[0];
  29. if(!m_Makefile->IsOn(testVarible.c_str()))
  30. {
  31. return;
  32. }
  33. std::string resultVarible = m_Arguments[1];
  34. bool requirementsMet = true;
  35. std::string notSet;
  36. bool hasAdvanced = false;
  37. for(unsigned int i = 2; i < m_Arguments.size(); ++i)
  38. {
  39. if(!m_Makefile->IsOn(m_Arguments[i].c_str()))
  40. {
  41. requirementsMet = false;
  42. notSet += m_Arguments[i];
  43. notSet += "\n";
  44. if(cmCacheManager::GetInstance()->IsAdvanced(m_Arguments[i].c_str()))
  45. {
  46. hasAdvanced = true;
  47. }
  48. }
  49. }
  50. const char* reqVar = m_Makefile->GetDefinition(resultVarible.c_str());
  51. // if reqVar is unset, then set it to requirementsMet
  52. // if reqVar is set to true, but requirementsMet is false , then
  53. // set reqVar to false.
  54. if(!reqVar || (!requirementsMet && m_Makefile->IsOn(reqVar)))
  55. {
  56. m_Makefile->AddDefinition(resultVarible.c_str(), requirementsMet);
  57. }
  58. if(!requirementsMet)
  59. {
  60. std::string message = "Variable assertion failed:\n";
  61. message += testVarible + " Requires that the following unset varibles are set:\n";
  62. message += notSet;
  63. message += "\nPlease set them, or set ";
  64. message += testVarible + " to false, and re-configure.\n";
  65. if(hasAdvanced)
  66. {
  67. message += "One or more of the required variables is advanced. To set the variable, you must turn on advanced mode in cmake.";
  68. }
  69. cmSystemTools::Error(message.c_str());
  70. }
  71. }