cmIfCommand.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <vector>
  8. #include "cmCommand.h"
  9. #include "cmFunctionBlocker.h"
  10. #include "cmListFileCache.h"
  11. class cmExecutionStatus;
  12. class cmExpandedCommandArgument;
  13. class cmMakefile;
  14. class cmIfFunctionBlocker : public cmFunctionBlocker
  15. {
  16. public:
  17. cmIfFunctionBlocker()
  18. {
  19. this->HasRun = false;
  20. this->ElseSeen = false;
  21. this->ScopeDepth = 0;
  22. }
  23. ~cmIfFunctionBlocker() override {}
  24. bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
  25. cmExecutionStatus&) override;
  26. bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) override;
  27. std::vector<cmListFileArgument> Args;
  28. std::vector<cmListFileFunction> Functions;
  29. bool IsBlocking;
  30. bool HasRun;
  31. bool ElseSeen;
  32. unsigned int ScopeDepth;
  33. };
  34. /// Starts an if block
  35. class cmIfCommand : public cmCommand
  36. {
  37. public:
  38. /**
  39. * This is a virtual constructor for the command.
  40. */
  41. cmCommand* Clone() override { return new cmIfCommand; }
  42. /**
  43. * This overrides the default InvokeInitialPass implementation.
  44. * It records the arguments before expansion.
  45. */
  46. bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  47. cmExecutionStatus&) override;
  48. /**
  49. * This is called when the command is first encountered in
  50. * the CMakeLists.txt file.
  51. */
  52. bool InitialPass(std::vector<std::string> const&,
  53. cmExecutionStatus&) override
  54. {
  55. return false;
  56. }
  57. // Filter the given variable definition based on policy CMP0054.
  58. static const char* GetDefinitionIfUnquoted(
  59. const cmMakefile* mf, cmExpandedCommandArgument const& argument);
  60. };
  61. #endif