cmIfCommand.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmIfCommand_h
  4. #define cmIfCommand_h
  5. #include "cmCommand.h"
  6. #include "cmFunctionBlocker.h"
  7. class cmIfFunctionBlocker : public cmFunctionBlocker
  8. {
  9. public:
  10. cmIfFunctionBlocker()
  11. {
  12. this->HasRun = false;
  13. this->ScopeDepth = 0;
  14. }
  15. ~cmIfFunctionBlocker() CM_OVERRIDE {}
  16. bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
  17. cmExecutionStatus&) CM_OVERRIDE;
  18. bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) CM_OVERRIDE;
  19. std::vector<cmListFileArgument> Args;
  20. std::vector<cmListFileFunction> Functions;
  21. bool IsBlocking;
  22. bool HasRun;
  23. unsigned int ScopeDepth;
  24. };
  25. /// Starts an if block
  26. class cmIfCommand : public cmCommand
  27. {
  28. public:
  29. /**
  30. * This is a virtual constructor for the command.
  31. */
  32. cmCommand* Clone() CM_OVERRIDE { return new cmIfCommand; }
  33. /**
  34. * This overrides the default InvokeInitialPass implementation.
  35. * It records the arguments before expansion.
  36. */
  37. bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  38. cmExecutionStatus&) CM_OVERRIDE;
  39. /**
  40. * This is called when the command is first encountered in
  41. * the CMakeLists.txt file.
  42. */
  43. bool InitialPass(std::vector<std::string> const&,
  44. cmExecutionStatus&) CM_OVERRIDE
  45. {
  46. return false;
  47. }
  48. /**
  49. * The name of the command as specified in CMakeList.txt.
  50. */
  51. std::string GetName() const CM_OVERRIDE { return "if"; }
  52. /**
  53. * This determines if the command is invoked when in script mode.
  54. */
  55. bool IsScriptable() const CM_OVERRIDE { return true; }
  56. // Filter the given variable definition based on policy CMP0054.
  57. static const char* GetDefinitionIfUnquoted(
  58. const cmMakefile* mf, cmExpandedCommandArgument const& argument);
  59. cmTypeMacro(cmIfCommand, cmCommand);
  60. };
  61. #endif