cmSystemTools.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #ifndef cmSystemTools_h
  12. #define cmSystemTools_h
  13. #include "cmStandardIncludes.h"
  14. /** \class cmSystemTools
  15. * \brief A collection of useful functions for CMake.
  16. *
  17. * cmSystemTools is a class that provides helper functions
  18. * for the CMake build system.
  19. */
  20. class cmSystemTools
  21. {
  22. public:
  23. /**
  24. * Make a new directory if it is not there. This function
  25. * can make a full path even if none of the directories existed
  26. * prior to calling this function.
  27. */
  28. static bool MakeDirectory(const char* path);
  29. /**
  30. * Replace replace all occurances of the string in
  31. * the source string.
  32. */
  33. static void ReplaceString(std::string& source,
  34. const char* replace,
  35. const char* with);
  36. /**
  37. * Return a string equivalent to the input string, but with all " " replaced
  38. * with "\ " to escape the spaces.
  39. */
  40. static std::string EscapeSpaces(const char*);
  41. /**
  42. * Replace Windows file system slashes with Unix-style slashes.
  43. */
  44. static void ConvertToUnixSlashes(std::string& path);
  45. ///! Return true if a file exists in the current directory.
  46. static bool FileExists(const char* filename);
  47. /**
  48. * Return the number of times the given expression occurs in the file
  49. * specified by the concatenation of dir/file.
  50. */
  51. static int Grep(const char* dir, const char* file, const char* expression);
  52. /**
  53. * Convert a path containing a cygwin drive specifier to its natural
  54. * equivalent.
  55. */
  56. static void ConvertCygwinPath(std::string& pathname);
  57. /**
  58. * Read a CMake command (or function) from an input file. This
  59. * returns the name of the function and a list of its
  60. * arguments.
  61. */
  62. static bool ParseFunction(std::ifstream&,
  63. std::string& name,
  64. std::vector<std::string>& arguments);
  65. /**
  66. * Extract white-space separated arguments from a string.
  67. * Double quoted strings are accepted with spaces.
  68. * This is called by ParseFunction.
  69. */
  70. static void GetArguments(std::string& line,
  71. std::vector<std::string>& arguments);
  72. /**
  73. * Add the paths from the environment variable PATH to the
  74. * string vector passed in.
  75. */
  76. static void GetPath(std::vector<std::string>& path);
  77. /**
  78. * Get the file extension (including ".") needed for an executable
  79. * on the current platform ("" for unix, ".exe" for Windows).
  80. */
  81. static const char* GetExecutableExtension();
  82. /**
  83. * Display an error message.
  84. */
  85. static void Error(const char* m, const char* m2=0,
  86. const char* m3=0, const char* m4=0);
  87. ///! Return true if there was an error at any point.
  88. static bool GetErrorOccuredFlag()
  89. {
  90. return cmSystemTools::s_ErrorOccured;
  91. }
  92. /**
  93. * Copy the source file to the destination file only
  94. * if the two files differ.
  95. */
  96. static void CopyFileIfDifferent(const char* source,
  97. const char* destination);
  98. ///! Compare the contents of two files. Return true if different.
  99. static bool FilesDiffer(const char* source,
  100. const char* destination);
  101. ///! Copy a file.
  102. static void cmCopyFile(const char* source,
  103. const char* destination);
  104. ///! Remove a file.
  105. static void RemoveFile(const char* source);
  106. static long int ModifiedTime(const char* filename);
  107. private:
  108. static bool s_ErrorOccured;
  109. };
  110. #endif