cmakemain.cxx 6.5 KB

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