cmakemain.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. {0,0,0}
  49. };
  50. //----------------------------------------------------------------------------
  51. static const cmDocumentationEntry cmDocumentationNOTE[] =
  52. {
  53. {0,
  54. "CMake no longer configures a project when run with no arguments. "
  55. "In order to configure the project in the current directory, run\n"
  56. " cmake .", 0},
  57. {0,0,0}
  58. };
  59. int do_cmake(int ac, char** av);
  60. void updateProgress(const char *msg, float prog, void *cd);
  61. int main(int ac, char** av)
  62. {
  63. cmSystemTools::EnableMSVCDebugHook();
  64. int ret = do_cmake(ac, av);
  65. #ifdef CMAKE_BUILD_WITH_CMAKE
  66. cmDynamicLoader::FlushCache();
  67. #endif
  68. cmListFileCache::GetInstance()->ClearCache();
  69. return ret;
  70. }
  71. int do_cmake(int ac, char** av)
  72. {
  73. cmDocumentation doc;
  74. if(cmDocumentation::Type ht = doc.CheckOptions(ac, av))
  75. {
  76. // Construct and print requested documentation.
  77. cmake hcm;
  78. std::vector<cmDocumentationEntry> commands;
  79. hcm.GetCommandDocumentation(commands);
  80. doc.SetNameSection(cmDocumentationName);
  81. doc.SetUsageSection(cmDocumentationUsage);
  82. doc.SetDescriptionSection(cmDocumentationDescription);
  83. doc.SetOptionsSection(cmDocumentationOptions);
  84. doc.SetCommandsSection(&commands[0]);
  85. doc.PrintDocumentation(ht, std::cout);
  86. // If we were run with no arguments, but a CMakeLists.txt file
  87. // exists, the user may have been trying to use the old behavior
  88. // of cmake to build a project in-source. Print a message
  89. // explaining the change to standard error and return an error
  90. // condition in case the program is running from a script.
  91. if((ac == 1) && cmSystemTools::FileExists("CMakeLists.txt"))
  92. {
  93. doc.ClearSections();
  94. doc.AddSection("NOTE", cmDocumentationNOTE);
  95. doc.Print(cmDocumentation::UsageForm, std::cerr);
  96. return 1;
  97. }
  98. return 0;
  99. }
  100. bool wiz = false;
  101. bool command = false;
  102. std::vector<std::string> args;
  103. for(int i =0; i < ac; ++i)
  104. {
  105. if(strcmp(av[i], "-i") == 0)
  106. {
  107. wiz = true;
  108. }
  109. else if (strcmp(av[i], "-E") == 0)
  110. {
  111. command = true;
  112. }
  113. else
  114. {
  115. args.push_back(av[i]);
  116. }
  117. }
  118. if(command)
  119. {
  120. int ret = cmake::CMakeCommand(args);
  121. return ret;
  122. }
  123. if (wiz)
  124. {
  125. cmakewizard wizard;
  126. wizard.RunWizard(args);
  127. return 0;
  128. }
  129. cmake cm;
  130. cm.SetProgressCallback(updateProgress, 0);
  131. return cm.Run(args);
  132. }
  133. void updateProgress(const char *msg, float prog, void*)
  134. {
  135. if ( prog < 0 )
  136. {
  137. std::cout << "-- " << msg << std::endl;
  138. }
  139. //else
  140. //{
  141. //std::cout << "-- " << msg << " " << prog << std::endl;
  142. //}
  143. }