cmOutputConverter.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "cmStateSnapshot.h"
  7. #include "cm_string_view.hxx"
  8. #include <string>
  9. class cmState;
  10. class cmOutputConverter
  11. {
  12. public:
  13. cmOutputConverter(cmStateSnapshot const& snapshot);
  14. enum OutputFormat
  15. {
  16. SHELL,
  17. WATCOMQUOTE,
  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. };
  57. std::string EscapeForShell(cm::string_view str, bool makeVars = false,
  58. bool forEcho = false,
  59. bool useWatcomQuote = false) const;
  60. static std::string EscapeForCMake(cm::string_view str);
  61. /** Compute an escaped version of the given argument for use in a
  62. windows shell. */
  63. static std::string EscapeWindowsShellArgument(cm::string_view arg,
  64. int shell_flags);
  65. enum FortranFormat
  66. {
  67. FortranFormatNone,
  68. FortranFormatFixed,
  69. FortranFormatFree
  70. };
  71. static FortranFormat GetFortranFormat(cm::string_view value);
  72. static FortranFormat GetFortranFormat(const char* value);
  73. private:
  74. cmState* GetState() const;
  75. static bool Shell__CharNeedsQuotes(char c, int flags);
  76. static cm::string_view::iterator Shell__SkipMakeVariables(
  77. cm::string_view::iterator begin, cm::string_view::iterator end);
  78. static bool Shell__ArgumentNeedsQuotes(cm::string_view in, int flags);
  79. static std::string Shell__GetArgument(cm::string_view in, int flags);
  80. private:
  81. cmStateSnapshot StateSnapshot;
  82. bool LinkScriptShell;
  83. };
  84. #endif