cmOutputConverter.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "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. RESPONSE
  18. };
  19. std::string ConvertToOutputFormat(const std::string& source,
  20. OutputFormat output) const;
  21. std::string ConvertDirectorySeparatorsForShell(
  22. const std::string& 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(const std::string& str, bool makeVars = false,
  58. bool forEcho = false,
  59. bool useWatcomQuote = false) const;
  60. static std::string EscapeForCMake(const std::string& str);
  61. /** Compute an escaped version of the given argument for use in a
  62. windows shell. */
  63. static std::string EscapeWindowsShellArgument(const char* arg,
  64. int shell_flags);
  65. enum FortranFormat
  66. {
  67. FortranFormatNone,
  68. FortranFormatFixed,
  69. FortranFormatFree
  70. };
  71. static FortranFormat GetFortranFormat(const char* value);
  72. private:
  73. cmState* GetState() const;
  74. static int Shell__CharNeedsQuotes(char c, int flags);
  75. static const char* Shell__SkipMakeVariables(const char* c);
  76. static int Shell__ArgumentNeedsQuotes(const char* in, int flags);
  77. static std::string Shell__GetArgument(const char* in, int flags);
  78. private:
  79. cmStateSnapshot StateSnapshot;
  80. bool LinkScriptShell;
  81. };
  82. #endif