cmElseCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "cmElseCommand.h"
  14. #include "cmCacheManager.h"
  15. bool cmElseCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // create a function blocker
  23. cmIfFunctionBlocker *f = NULL;
  24. // check for the different signatures
  25. const char *def;
  26. const char *def2;
  27. if (args.size() == 1)
  28. {
  29. def = m_Makefile->GetDefinition(args[0].c_str());
  30. if(!cmSystemTools::IsOff(def))
  31. {
  32. f = new cmIfFunctionBlocker();
  33. }
  34. }
  35. if (args.size() == 2 && (args[0] == "COMMAND"))
  36. {
  37. if(m_Makefile->CommandExists(args[1].c_str()))
  38. {
  39. f = new cmIfFunctionBlocker();
  40. }
  41. }
  42. if (args.size() == 2 && (args[0] == "EXISTS"))
  43. {
  44. std::string tmp = args[1];
  45. m_Makefile->ExpandVariablesInString(tmp);
  46. if(cmSystemTools::FileExists(tmp.c_str()))
  47. {
  48. f = new cmIfFunctionBlocker();
  49. }
  50. }
  51. if (args.size() == 2 && (args[0] == "NOT"))
  52. {
  53. def = m_Makefile->GetDefinition(args[1].c_str());
  54. if(cmSystemTools::IsOff(def))
  55. {
  56. f = new cmIfFunctionBlocker();
  57. }
  58. }
  59. if (args.size() == 3 && (args[1] == "AND"))
  60. {
  61. def = m_Makefile->GetDefinition(args[0].c_str());
  62. def2 = m_Makefile->GetDefinition(args[2].c_str());
  63. if(!cmSystemTools::IsOff(def) && !cmSystemTools::IsOff(def2))
  64. {
  65. f = new cmIfFunctionBlocker();
  66. }
  67. }
  68. if (args.size() == 3 && (args[1] == "OR"))
  69. {
  70. def = m_Makefile->GetDefinition(args[0].c_str());
  71. def2 = m_Makefile->GetDefinition(args[2].c_str());
  72. if(!cmSystemTools::IsOff(def) || !cmSystemTools::IsOff(def2))
  73. {
  74. f = new cmIfFunctionBlocker();
  75. }
  76. }
  77. if (args.size() == 3 && (args[1] == "MATCHES"))
  78. {
  79. def = m_Makefile->GetDefinition(args[0].c_str());
  80. cmRegularExpression regEntry(args[2].c_str());
  81. // check for black line or comment
  82. if (def && regEntry.find(def))
  83. {
  84. f = new cmIfFunctionBlocker();
  85. }
  86. }
  87. // if we created a function blocker then set its args
  88. if (f)
  89. {
  90. for(std::vector<std::string>::const_iterator j = args.begin();
  91. j != args.end(); ++j)
  92. {
  93. f->m_Args.push_back(*j);
  94. }
  95. m_Makefile->AddFunctionBlocker(f);
  96. }
  97. else
  98. {
  99. // remove any function blockers for this define
  100. m_Makefile->RemoveFunctionBlocker("ENDIF",args);
  101. }
  102. return true;
  103. }