cmOutputConverter.h 3.5 KB

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