cmakemain.cxx 7.6 KB

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