cmOutputConverter.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmOutputConverter_h
  11. #define cmOutputConverter_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmState.h"
  15. class cmOutputConverter
  16. {
  17. public:
  18. cmOutputConverter(cmState::Snapshot snapshot);
  19. /**
  20. * Convert something to something else. This is a centralized conversion
  21. * routine used by the generators to handle relative paths and the like.
  22. * The flags determine what is actually done.
  23. *
  24. * relative: treat the argument as a directory and convert it to make it
  25. * relative or full or unchanged. If relative (HOME, START etc) then that
  26. * specifies what it should be relative to.
  27. *
  28. * output: make the result suitable for output to a...
  29. *
  30. * optional: should any relative path operation be controlled by the rel
  31. * path setting
  32. */
  33. enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
  34. enum OutputFormat { UNCHANGED, MAKERULE, SHELL, WATCOMQUOTE, RESPONSE };
  35. std::string ConvertToOutputFormat(const std::string& source,
  36. OutputFormat output);
  37. std::string Convert(const std::string& remote, RelativeRoot local,
  38. OutputFormat output = UNCHANGED);
  39. std::string Convert(RelativeRoot remote, const std::string& local,
  40. OutputFormat output = UNCHANGED,
  41. bool optional = false);
  42. /**
  43. * Get path for the specified relative root.
  44. */
  45. const char* GetRelativeRootPath(RelativeRoot relroot);
  46. ///! for existing files convert to output path and short path if spaces
  47. std::string ConvertToOutputForExisting(const std::string& remote,
  48. RelativeRoot local = START_OUTPUT,
  49. OutputFormat format = SHELL);
  50. /** For existing path identified by RelativeRoot convert to output
  51. path and short path if spaces. */
  52. std::string ConvertToOutputForExisting(RelativeRoot remote,
  53. const std::string& local = "",
  54. OutputFormat format = SHELL);
  55. void SetLinkScriptShell(bool linkScriptShell);
  56. std::string EscapeForShell(const std::string& str,
  57. bool makeVars = false,
  58. bool forEcho = false,
  59. bool useWatcomQuote = false);
  60. static std::string EscapeForCMake(const std::string& str);
  61. enum FortranFormat
  62. {
  63. FortranFormatNone,
  64. FortranFormatFixed,
  65. FortranFormatFree
  66. };
  67. static FortranFormat GetFortranFormat(const char* value);
  68. /**
  69. * Convert the given remote path to a relative path with respect to
  70. * the given local path. The local path must be given in component
  71. * form (see SystemTools::SplitPath) without a trailing slash. The
  72. * remote path must use forward slashes and not already be escaped
  73. * or quoted.
  74. */
  75. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  76. const std::string& in_remote,
  77. bool force = false);
  78. private:
  79. cmState* GetState() const;
  80. std::string ConvertToOutputForExistingCommon(const std::string& remote,
  81. std::string const& result,
  82. OutputFormat format);
  83. private:
  84. cmState::Snapshot StateSnapshot;
  85. bool LinkScriptShell;
  86. };
  87. #endif