cmIfCommand.cxx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmIfCommand.h"
  12. #include "cmCacheManager.h"
  13. bool cmIfFunctionBlocker::
  14. IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
  15. const cmMakefile &mf) const
  16. {
  17. if (strcmp(name,"ELSE") && strcmp(name,"ENDIF"))
  18. {
  19. return true;
  20. }
  21. if (strcmp(args[0].c_str(),m_Define.c_str()))
  22. {
  23. return true;
  24. }
  25. return false;
  26. }
  27. bool cmIfFunctionBlocker::
  28. ShouldRemove(const char *name, const std::vector<std::string> &args,
  29. const cmMakefile &mf) const
  30. {
  31. return !this->IsFunctionBlocked(name,args,mf);
  32. }
  33. bool cmIfCommand::Invoke(std::vector<std::string>& args)
  34. {
  35. if(args.size() < 1 )
  36. {
  37. this->SetError("called with incorrect number of arguments");
  38. return false;
  39. }
  40. // check to see if the argument is defined first
  41. const char *def = m_Makefile->GetDefinition(args[0].c_str());
  42. if(def && strcmp(def,"0") && strcmp(def,"false") && strcmp(def,"") &&
  43. strcmp(def,"NOTFOUND"))
  44. {
  45. // do nothing
  46. }
  47. else
  48. {
  49. // create a function blocker
  50. cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
  51. f->m_Define = args[0];
  52. m_Makefile->AddFunctionBlocker(f);
  53. }
  54. return true;
  55. }