cmakemain.cxx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #include "cmakewizard.h"
  14. #include "cmake.h"
  15. #include "cmCacheManager.h"
  16. #include "cmDynamicLoader.h"
  17. #include "cmListFileCache.h"
  18. #include "cmDocumentation.h"
  19. //----------------------------------------------------------------------------
  20. static const cmDocumentationEntry cmDocumentationName[] =
  21. {
  22. {0,
  23. " cmake - Cross-Platform Makefile Generator.", 0},
  24. {0,0,0}
  25. };
  26. //----------------------------------------------------------------------------
  27. static const cmDocumentationEntry cmDocumentationUsage[] =
  28. {
  29. {0,
  30. " cmake [options] <path-to-source>", 0},
  31. {0,0,0}
  32. };
  33. //----------------------------------------------------------------------------
  34. static const cmDocumentationEntry cmDocumentationDescription[] =
  35. {
  36. {0,
  37. "The \"cmake\" executable is the CMake command-line interface. It may "
  38. "be used to configure projects in scripts. Project configuration settings "
  39. "may be specified on the command line with the -D option. The -i option "
  40. "will cause cmake to interactively prompt for such settings.", 0},
  41. CMAKE_STANDARD_INTRODUCTION,
  42. {0,0,0}
  43. };
  44. //----------------------------------------------------------------------------
  45. static const cmDocumentationEntry cmDocumentationOptions[] =
  46. {
  47. CMAKE_STANDARD_OPTIONS_TABLE,
  48. {"-E", "CMake command mode.",
  49. "For true platform independence, CMake provides a list of commands "
  50. "that can be used on all systems. Run with -E help for the usage "
  51. "information."},
  52. {"-i", "Run in wizard mode.",
  53. "Wizard mode runs cmake interactively without a GUI. The user is "
  54. "prompted to answer questions about the project configuration. "
  55. "The answers are used to set cmake cache values."},
  56. {"-L[A][H]", "List non-advanced cached variables.",
  57. "List cache variables will run CMake and list all the variables from the "
  58. "CMake cache that are not marked as INTERNAL or ADVANCED. This will "
  59. "effectively display current CMake settings, which can be then changed "
  60. "with -D option. Changing some of the variable may result in more "
  61. "variables being created. If A is specified, then it will display also "
  62. "advanced variables. If H is specified, it will also display help for "
  63. "each variable."},
  64. {"-N", "View mode only.",
  65. "Only load the cache. Do not actually run configure and generate steps."},
  66. {0,0,0}
  67. };
  68. //----------------------------------------------------------------------------
  69. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  70. {
  71. {0, "ccmake", 0},
  72. {0, "ctest", 0},
  73. {0, 0, 0}
  74. };
  75. //----------------------------------------------------------------------------
  76. static const cmDocumentationEntry cmDocumentationNOTE[] =
  77. {
  78. {0,
  79. "CMake no longer configures a project when run with no arguments. "
  80. "In order to configure the project in the current directory, run\n"
  81. " cmake .", 0},
  82. {0,0,0}
  83. };
  84. int do_cmake(int ac, char** av);
  85. void updateProgress(const char *msg, float prog, void *cd);
  86. int main(int ac, char** av)
  87. {
  88. cmSystemTools::EnableMSVCDebugHook();
  89. int ret = do_cmake(ac, av);
  90. #ifdef CMAKE_BUILD_WITH_CMAKE
  91. cmDynamicLoader::FlushCache();
  92. #endif
  93. cmListFileCache::GetInstance()->ClearCache();
  94. return ret;
  95. }
  96. int do_cmake(int ac, char** av)
  97. {
  98. cmDocumentation doc;
  99. if(doc.CheckOptions(ac, av))
  100. {
  101. // Construct and print requested documentation.
  102. cmake hcm;
  103. std::vector<cmDocumentationEntry> commands;
  104. std::vector<cmDocumentationEntry> generators;
  105. hcm.GetCommandDocumentation(commands);
  106. hcm.GetGeneratorDocumentation(generators);
  107. doc.SetName("cmake");
  108. doc.SetNameSection(cmDocumentationName);
  109. doc.SetUsageSection(cmDocumentationUsage);
  110. doc.SetDescriptionSection(cmDocumentationDescription);
  111. doc.SetGeneratorsSection(&generators[0]);
  112. doc.SetOptionsSection(cmDocumentationOptions);
  113. doc.SetCommandsSection(&commands[0]);
  114. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  115. int result = doc.PrintRequestedDocumentation(std::cout)? 0:1;
  116. // If we were run with no arguments, but a CMakeLists.txt file
  117. // exists, the user may have been trying to use the old behavior
  118. // of cmake to build a project in-source. Print a message
  119. // explaining the change to standard error and return an error
  120. // condition in case the program is running from a script.
  121. if((ac == 1) && cmSystemTools::FileExists("CMakeLists.txt"))
  122. {
  123. doc.ClearSections();
  124. doc.AddSection("NOTE", cmDocumentationNOTE);
  125. doc.Print(cmDocumentation::UsageForm, std::cerr);
  126. return 1;
  127. }
  128. return result;
  129. }
  130. bool wiz = false;
  131. bool command = false;
  132. bool list_cached = false;
  133. bool list_all_cached = false;
  134. bool list_help = false;
  135. bool view_only = false;
  136. std::vector<std::string> args;
  137. for(int i =0; i < ac; ++i)
  138. {
  139. if(strcmp(av[i], "-i") == 0)
  140. {
  141. wiz = true;
  142. }
  143. else if (strcmp(av[i], "-E") == 0)
  144. {
  145. command = true;
  146. }
  147. else if (strcmp(av[i], "-N") == 0)
  148. {
  149. view_only = true;
  150. }
  151. else if (strcmp(av[i], "-L") == 0)
  152. {
  153. list_cached = true;
  154. }
  155. else if (strcmp(av[i], "-LA") == 0)
  156. {
  157. list_all_cached = true;
  158. }
  159. else if (strcmp(av[i], "-LH") == 0)
  160. {
  161. list_cached = true;
  162. list_help = true;
  163. }
  164. else if (strcmp(av[i], "-LAH") == 0)
  165. {
  166. list_all_cached = true;
  167. list_help = true;
  168. }
  169. else
  170. {
  171. args.push_back(av[i]);
  172. }
  173. }
  174. if(command)
  175. {
  176. int ret = cmake::CMakeCommand(args);
  177. return ret;
  178. }
  179. if (wiz)
  180. {
  181. cmakewizard wizard;
  182. wizard.RunWizard(args);
  183. return 0;
  184. }
  185. cmake cm;
  186. cm.SetProgressCallback(updateProgress, 0);
  187. int res = cm.Run(args, view_only);
  188. if ( list_cached || list_all_cached )
  189. {
  190. cmCacheManager::CacheIterator it = cm.GetCacheManager()->GetCacheIterator();
  191. std::cout << "-- Cache values" << std::endl;
  192. for ( it.Begin(); !it.IsAtEnd(); it.Next() )
  193. {
  194. cmCacheManager::CacheEntryType t = it.GetType();
  195. if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC &&
  196. t != cmCacheManager::UNINITIALIZED )
  197. {
  198. bool advanced = it.PropertyExists("ADVANCED");
  199. if ( list_all_cached || !advanced)
  200. {
  201. if ( list_help )
  202. {
  203. std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl;
  204. }
  205. std::cout << it.GetName() << ":" << cmCacheManager::TypeToString(it.GetType())
  206. << "=" << it.GetValue() << std::endl;
  207. if ( list_help )
  208. {
  209. std::cout << std::endl;
  210. }
  211. }
  212. }
  213. }
  214. }
  215. return res;
  216. }
  217. void updateProgress(const char *msg, float prog, void*)
  218. {
  219. if ( prog < 0 )
  220. {
  221. std::cout << "-- " << msg << std::endl;
  222. }
  223. //else
  224. //{
  225. //std::cout << "-- " << msg << " " << prog << std::endl;
  226. //}
  227. }