cmOutputConverter.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <string>
  6. #include <cm/string_view>
  7. #include "cmStateSnapshot.h"
  8. class cmState;
  9. class cmOutputConverter
  10. {
  11. public:
  12. cmOutputConverter(cmStateSnapshot const& snapshot);
  13. enum OutputFormat
  14. {
  15. SHELL,
  16. WATCOMQUOTE,
  17. NINJAMULTI,
  18. RESPONSE
  19. };
  20. std::string ConvertToOutputFormat(cm::string_view source,
  21. OutputFormat output) const;
  22. std::string ConvertDirectorySeparatorsForShell(cm::string_view source) const;
  23. //! for existing files convert to output path and short path if spaces
  24. std::string ConvertToOutputForExisting(const std::string& remote,
  25. OutputFormat format = SHELL) const;
  26. void SetLinkScriptShell(bool linkScriptShell);
  27. /**
  28. * Flags to pass to Shell_GetArgument. These modify the generated
  29. * quoting and escape sequences to work under alternative
  30. * environments.
  31. */
  32. enum Shell_Flag_e
  33. {
  34. /** The target shell is in a makefile. */
  35. Shell_Flag_Make = (1 << 0),
  36. /** The target shell is in a VS project file. Do not use with
  37. Shell_Flag_Make. */
  38. Shell_Flag_VSIDE = (1 << 1),
  39. /** In a windows shell the argument is being passed to "echo". */
  40. Shell_Flag_EchoWindows = (1 << 2),
  41. /** The target shell is in a Watcom WMake makefile. */
  42. Shell_Flag_WatcomWMake = (1 << 3),
  43. /** The target shell is in a MinGW Make makefile. */
  44. Shell_Flag_MinGWMake = (1 << 4),
  45. /** The target shell is in a NMake makefile. */
  46. Shell_Flag_NMake = (1 << 5),
  47. /** Make variable reference syntax $(MAKEVAR) should not be escaped
  48. to allow a build tool to replace it. Replacement values
  49. containing spaces, quotes, backslashes, or other
  50. non-alphanumeric characters that have significance to some makes
  51. or shells produce undefined behavior. */
  52. Shell_Flag_AllowMakeVariables = (1 << 6),
  53. /** The target shell quoting uses extra single Quotes for Watcom tools. */
  54. Shell_Flag_WatcomQuote = (1 << 7),
  55. Shell_Flag_IsUnix = (1 << 8),
  56. Shell_Flag_UnescapeNinjaConfiguration = (1 << 9),
  57. };
  58. std::string EscapeForShell(cm::string_view str, bool makeVars = false,
  59. bool forEcho = false, bool useWatcomQuote = false,
  60. bool unescapeNinjaConfiguration = false) const;
  61. static std::string EscapeForCMake(cm::string_view str);
  62. /** Compute an escaped version of the given argument for use in a
  63. windows shell. */
  64. static std::string EscapeWindowsShellArgument(cm::string_view arg,
  65. int shell_flags);
  66. enum FortranFormat
  67. {
  68. FortranFormatNone,
  69. FortranFormatFixed,
  70. FortranFormatFree
  71. };
  72. static FortranFormat GetFortranFormat(cm::string_view value);
  73. enum class FortranPreprocess
  74. {
  75. Unset,
  76. NotNeeded,
  77. Needed
  78. };
  79. static FortranPreprocess GetFortranPreprocess(cm::string_view value);
  80. private:
  81. cmState* GetState() const;
  82. static bool Shell_CharNeedsQuotes(char c, int flags);
  83. static cm::string_view::iterator Shell_SkipMakeVariables(
  84. cm::string_view::iterator begin, cm::string_view::iterator end);
  85. static bool Shell_ArgumentNeedsQuotes(cm::string_view in, int flags);
  86. static std::string Shell_GetArgument(cm::string_view in, int flags);
  87. private:
  88. cmStateSnapshot StateSnapshot;
  89. bool LinkScriptShell;
  90. };