cmFileCommand.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmFileCommand_h
  14. #define cmFileCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmFileCommand
  17. * \brief Command for manipulation of files
  18. *
  19. */
  20. class cmFileCommand : public cmCommand
  21. {
  22. public:
  23. /**
  24. * This is a virtual constructor for the command.
  25. */
  26. virtual cmCommand* Clone()
  27. {
  28. return new cmFileCommand;
  29. }
  30. /**
  31. * This is called when the command is first encountered in
  32. * the CMakeLists.txt file.
  33. */
  34. virtual bool InitialPass(std::vector<std::string> const& args);
  35. /**
  36. * This determines if the command is invoked when in script mode.
  37. */
  38. virtual bool IsScriptable() { return true; }
  39. /**
  40. * The name of the command as specified in CMakeList.txt.
  41. */
  42. virtual const char* GetName() { return "FILE";}
  43. /**
  44. * Succinct documentation.
  45. */
  46. virtual const char* GetTerseDocumentation()
  47. {
  48. return "File manipulation command.";
  49. }
  50. /**
  51. * More documentation.
  52. */
  53. virtual const char* GetFullDocumentation()
  54. {
  55. return
  56. " FILE(WRITE filename \"message to write\"... )\n"
  57. " FILE(APPEND filename \"message to write\"... )\n"
  58. " FILE(READ filename variable)\n"
  59. " FILE(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
  60. " FILE(GLOB_RECURSE variable [RELATIVE path] [globbing expressions]...)\n"
  61. " FILE(REMOVE [directory]...)\n"
  62. " FILE(REMOVE_RECURSE [directory]...)\n"
  63. " FILE(MAKE_DIRECTORY [directory]...)\n"
  64. " FILE(RELATIVE_PATH variable directory file)\n"
  65. " FILE(TO_CMAKE_PATH path result)\n"
  66. " FILE(TO_NATIVE_PATH path result)\n"
  67. "WRITE will write a message into a file called 'filename'. It "
  68. "overwrites the file if it already exists, and creates the file "
  69. "if it does not exist.\n"
  70. "APPEND will write a message into a file same as WRITE, except "
  71. "it will append it to the end of the file\n"
  72. "NOTE: When using FILE WRITE and FILE APPEND, the produced file "
  73. "cannot be used as an input to CMake (CONFIGURE_FILE, source file ...) "
  74. "because it will lead to an infinite loop. Use CONFIGURE_FILE if you "
  75. "want to generate input files to CMake.\n"
  76. "READ will read the content of a file and store it into the "
  77. "variable.\n"
  78. "GLOB will generate a list of all files that match the globbing "
  79. "expressions and store it into the variable. Globbing expressions "
  80. "are similar to regular expressions, but much simpler. If RELATIVE "
  81. "flag is specified for an expression, the results will be returned "
  82. "as a relative path to the given path.\n"
  83. "Examples of globbing expressions include:\n"
  84. " *.cxx - match all files with extension cxx\n"
  85. " *.vt? - match all files with extension vta,...,vtz\n"
  86. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  87. "GLOB_RECURSE will generate similar list as the regular GLOB, except "
  88. "it will traverse all the subdirectories of the matched directory and "
  89. "match the files.\n"
  90. "Examples of recursive globbing include:\n"
  91. " /dir/*.py - match all python files in /dir and subdirectories\n"
  92. "MAKE_DIRECTORY will create a directory at the specified location\n"
  93. "RELATIVE_PATH will determine relative path from directory to the given"
  94. " file.\n"
  95. "TO_CMAKE_PATH will convert path into a cmake sytle path with unix /. "
  96. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  97. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  98. " one argument.\n"
  99. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  100. " a cmake style path into the native path style \\ for windows and / "
  101. "for UNIX.";
  102. }
  103. cmTypeMacro(cmFileCommand, cmCommand);
  104. protected:
  105. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  106. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  107. bool HandleReadCommand(std::vector<std::string> const& args);
  108. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  109. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  110. bool HandleInstallCommand(std::vector<std::string> const& args);
  111. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  112. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  113. bool nativePath);
  114. };
  115. #endif