cmSystemTools.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. * Replace Windows file system slashes with Unix-style slashes.
  38. */
  39. static void ConvertToUnixSlashes(std::string& path);
  40. ///! Return true if a file exists in the current directory.
  41. static bool FileExists(const char* filename);
  42. /**
  43. * Return the number of times the given expression occurs in the file
  44. * specified by the concatenation of dir/file.
  45. */
  46. static int Grep(const char* dir, const char* file, const char* expression);
  47. /**
  48. * Convert a path containing a cygwin drive specifier to its natural
  49. * equivalent.
  50. */
  51. static void ConvertCygwinPath(std::string& pathname);
  52. /**
  53. * Read a CMake command (or function) from an input file. This
  54. * returns the name of the function and a list of its
  55. * arguments.
  56. */
  57. static bool ParseFunction(std::ifstream&,
  58. std::string& name,
  59. std::vector<std::string>& arguments);
  60. /**
  61. * Extract white-space separated arguments from a string.
  62. * Double quoted strings are accepted with spaces.
  63. * This is called by ParseFunction.
  64. */
  65. static void GetArguments(std::string& line,
  66. std::vector<std::string>& arguments);
  67. /**
  68. * Add the paths from the environment variable PATH to the
  69. * string vector passed in.
  70. */
  71. static void GetPath(std::vector<std::string>& path);
  72. /**
  73. * Get the file extension (including ".") needed for an executable
  74. * on the current platform ("" for unix, ".exe" for Windows).
  75. */
  76. static const char* GetExecutableExtension();
  77. /**
  78. * Display an error message.
  79. */
  80. static void Error(const char* m, const char* m2=0,
  81. const char* m3=0, const char* m4=0);
  82. ///! Return true if there was an error at any point.
  83. static bool GetErrorOccuredFlag()
  84. {
  85. return cmSystemTools::s_ErrorOccured;
  86. }
  87. /**
  88. * Copy the source file to the destination file only
  89. * if the two files differ.
  90. */
  91. static void CopyFileIfDifferent(const char* source,
  92. const char* destination);
  93. ///! Compare the contents of two files. Return true if different.
  94. static bool FilesDiffer(const char* source,
  95. const char* destination);
  96. ///! Copy a file.
  97. static void cmCopyFile(const char* source,
  98. const char* destination);
  99. ///! Remove a file.
  100. static void RemoveFile(const char* source);
  101. static long int ModifiedTime(const char* filename);
  102. private:
  103. static bool s_ErrorOccured;
  104. };
  105. #endif