cmakemain.cxx 7.1 KB

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