cmake.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. // This class represents a cmake invocation. It is the top level class when
  14. // running cmake. Most cmake based GUIS should primarily create an instance
  15. // of this class and communicate with it.
  16. #include "cmStandardIncludes.h"
  17. #include "cmSystemTools.h"
  18. class cmGlobalGenerator;
  19. class cmLocalGenerator;
  20. class cmCacheManager;
  21. class cmMakefile;
  22. class cmCommand;
  23. class cmake
  24. {
  25. public:
  26. ///! construct an instance of cmake
  27. cmake();
  28. ///! destruct an instance of cmake
  29. ~cmake();
  30. /**
  31. * Return major and minor version numbers for cmake.
  32. */
  33. static unsigned int GetMajorVersion();
  34. static unsigned int GetMinorVersion();
  35. static const char *GetReleaseVersion();
  36. //@{
  37. /**
  38. * Set/Get the home directory (or output directory) in the project. The
  39. * home directory is the top directory of the project. It is where
  40. * cmake was run. Remember that CMake processes
  41. * CMakeLists files by recursing up the tree starting at the StartDirectory
  42. * and going up until it reaches the HomeDirectory.
  43. */
  44. void SetHomeDirectory(const char* dir);
  45. const char* GetHomeDirectory() const
  46. {
  47. return m_cmHomeDirectory.c_str();
  48. }
  49. void SetHomeOutputDirectory(const char* lib);
  50. const char* GetHomeOutputDirectory() const
  51. {
  52. return m_HomeOutputDirectory.c_str();
  53. }
  54. //@}
  55. //@{
  56. /**
  57. * Set/Get the start directory (or output directory). The start directory
  58. * is the directory of the CMakeLists.txt file that started the current
  59. * round of processing. Remember that CMake processes CMakeLists files by
  60. * recursing up the tree starting at the StartDirectory and going up until
  61. * it reaches the HomeDirectory.
  62. */
  63. void SetStartDirectory(const char* dir)
  64. {
  65. m_cmStartDirectory = dir;
  66. cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
  67. }
  68. const char* GetStartDirectory() const
  69. {
  70. return m_cmStartDirectory.c_str();
  71. }
  72. void SetStartOutputDirectory(const char* lib)
  73. {
  74. m_StartOutputDirectory = lib;
  75. cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
  76. }
  77. const char* GetStartOutputDirectory() const
  78. {
  79. return m_StartOutputDirectory.c_str();
  80. }
  81. //@}
  82. /**
  83. * Dump documentation to a file. If 0 is returned, the
  84. * operation failed.
  85. */
  86. int DumpDocumentationToFile(std::ostream&);
  87. /**
  88. * Handle a command line invocation of cmake.
  89. */
  90. int Run(const std::vector<std::string>&args);
  91. /**
  92. * Generate the SourceFilesList from the SourceLists. This should only be
  93. * done once to be safe. The argument is a list of command line
  94. * arguments. The first argument should be the name or full path
  95. * to the command line version of cmake. For building a GUI,
  96. * you would pass in the following arguments:
  97. * /path/to/cmake -H/path/to/source -B/path/to/build
  98. * If you only want to parse the CMakeLists.txt files,
  99. * but not actually generate the makefiles, use buildMakefiles = false.
  100. */
  101. int Generate();
  102. /**
  103. * Configure the cmMakefiles. This routine will create a GlobalGenerator if
  104. * one has not already been set. It will then Call Configure on the
  105. * GlobalGenerator. This in turn will read in an process all the CMakeList
  106. * files for the tree. It will not produce any actual Makefiles, or
  107. * workspaces. Generate does that. */
  108. int Configure(const char *cmakeexec, const std::vector<std::string> *args = 0);
  109. ///! Create a GlobalGenerator
  110. cmGlobalGenerator* CreateGlobalGenerator(const char* name);
  111. ///! Return the global generator assigned to this instance of cmake
  112. cmGlobalGenerator* GetGlobalGenerator() { return m_GlobalGenerator; };
  113. ///! Return the global generator assigned to this instance of cmake
  114. void SetGlobalGenerator(cmGlobalGenerator *);
  115. ///! Get the names of the current registered generators
  116. void GetRegisteredGenerators(std::vector<std::string>& names);
  117. ///! get the cmCachemManager used by this invocation of cmake
  118. cmCacheManager *GetCacheManager() { return m_CacheManager; }
  119. /**
  120. * Given a variable name, return its value (as a string).
  121. */
  122. const char* GetCacheDefinition(const char*) const;
  123. /**
  124. * Execute commands during the build process. Supports options such
  125. * as echo, remove file etc.
  126. */
  127. static int CMakeCommand(std::vector<std::string>&);
  128. /**
  129. * Add a command to this cmake instance
  130. */
  131. void AddCommand(cmCommand* );
  132. /**
  133. * Get a command by its name
  134. */
  135. cmCommand *GetCommand(const char *name);
  136. /** Check if a command exists. */
  137. bool CommandExists(const char* name) const;
  138. /**
  139. * Is cmake in the process of a local cmake invocation. If so, we know the
  140. * cache is already configured and ready to go.
  141. */
  142. bool GetLocal()
  143. {
  144. return m_Local;
  145. }
  146. ///! Display command line useage
  147. void Usage(const char *program);
  148. ///! Parse command line arguments
  149. void SetArgs(const std::vector<std::string>&);
  150. ///! Is this cmake running as a result of a TRY_COMPILE command
  151. bool GetIsInTryCompile() { return m_InTryCompile; }
  152. ///! Is this cmake running as a result of a TRY_COMPILE command
  153. void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
  154. /**
  155. * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
  156. */
  157. int AddCMakePaths(const char *arg0);
  158. protected:
  159. typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
  160. RegisteredCommandsMap m_Commands;
  161. void AddDefaultCommands();
  162. cmGlobalGenerator *m_GlobalGenerator;
  163. cmCacheManager *m_CacheManager;
  164. std::string m_cmHomeDirectory;
  165. std::string m_HomeOutputDirectory;
  166. std::string m_cmStartDirectory;
  167. std::string m_StartOutputDirectory;
  168. ///! Parse command line arguments that might set cache values
  169. void SetCacheArgs(const std::vector<std::string>&);
  170. ///! read in a cmake list file to initialize the cache
  171. void ReadListFile(const char *path);
  172. ///! used by Run
  173. int LocalGenerate();
  174. private:
  175. bool m_Verbose;
  176. bool m_Local;
  177. bool m_InTryCompile;
  178. };