cmIfCommand.h 1.8 KB

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