cmakemain.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. // include these first, otherwise there will be problems on Windows
  11. // with GetCurrentDirectory() being redefined
  12. #ifdef CMAKE_BUILD_WITH_CMAKE
  13. #include "cmDynamicLoader.h"
  14. #include "cmDocumentation.h"
  15. #endif
  16. #include "cmake.h"
  17. #include "cmCacheManager.h"
  18. #include "cmListFileCache.h"
  19. #include "cmakewizard.h"
  20. #include "cmSourceFile.h"
  21. #include "cmGlobalGenerator.h"
  22. #include "cmLocalGenerator.h"
  23. #include "cmMakefile.h"
  24. #ifdef CMAKE_BUILD_WITH_CMAKE
  25. //----------------------------------------------------------------------------
  26. static const char * cmDocumentationName[][3] =
  27. {
  28. {0,
  29. " cmake - Cross-Platform Makefile Generator.", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const char * cmDocumentationUsage[][3] =
  34. {
  35. {0,
  36. " cmake [options] <path-to-source>\n"
  37. " cmake [options] <path-to-existing-build>", 0},
  38. {0,0,0}
  39. };
  40. //----------------------------------------------------------------------------
  41. static const char * cmDocumentationDescription[][3] =
  42. {
  43. {0,
  44. "The \"cmake\" executable is the CMake command-line interface. It may "
  45. "be used to configure projects in scripts. Project configuration "
  46. "settings "
  47. "may be specified on the command line with the -D option. The -i option "
  48. "will cause cmake to interactively prompt for such settings.", 0},
  49. CMAKE_STANDARD_INTRODUCTION,
  50. {0,0,0}
  51. };
  52. #define CMAKE_BUILD_OPTIONS \
  53. " <dir> = Project binary directory to be built.\n" \
  54. " --target <tgt> = Build <tgt> instead of default targets.\n" \
  55. " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
  56. " --clean-first = Build target 'clean' first, then build.\n" \
  57. " (To clean only, use --target 'clean'.)\n" \
  58. " --use-stderr = Don't merge stdout/stderr.\n" \
  59. " -- = Pass remaining options to the native tool.\n"
  60. //----------------------------------------------------------------------------
  61. static const char * cmDocumentationOptions[][3] =
  62. {
  63. CMAKE_STANDARD_OPTIONS_TABLE,
  64. {"-E", "CMake command mode.",
  65. "For true platform independence, CMake provides a list of commands "
  66. "that can be used on all systems. Run with -E help for the usage "
  67. "information. Commands available are: build, chdir, compare_files, copy, "
  68. "copy_directory, copy_if_different, echo, echo_append, environment, "
  69. "make_directory, md5sum, remove, remove_directory, rename, tar, time, "
  70. "touch, touch_nocreate. In addition, some platform specific commands "
  71. "are available. "
  72. "On Windows: comspec, delete_regv, write_regv. "
  73. "On UNIX: create_symlink."},
  74. {"-i", "Run in wizard mode.",
  75. "Wizard mode runs cmake interactively without a GUI. The user is "
  76. "prompted to answer questions about the project configuration. "
  77. "The answers are used to set cmake cache values."},
  78. {"-L[A][H]", "List non-advanced cached variables.",
  79. "List cache variables will run CMake and list all the variables from the "
  80. "CMake cache that are not marked as INTERNAL or ADVANCED. This will "
  81. "effectively display current CMake settings, which can be then changed "
  82. "with -D option. Changing some of the variable may result in more "
  83. "variables being created. If A is specified, then it will display also "
  84. "advanced variables. If H is specified, it will also display help for "
  85. "each variable."},
  86. {"--build <dir>", "Build a CMake-generated project binary tree.",
  87. "This abstracts a native build tool's command-line interface with the "
  88. "following options:\n"
  89. CMAKE_BUILD_OPTIONS
  90. "Run cmake --build with no options for quick help."},
  91. {"-N", "View mode only.",
  92. "Only load the cache. Do not actually run configure and generate steps."},
  93. {"-P <file>", "Process script mode.",
  94. "Process the given cmake file as a script written in the CMake language. "
  95. "No configure or generate step is performed and the cache is not"
  96. " modified. If variables are defined using -D, this must be done "
  97. "before the -P argument."},
  98. {"--graphviz=[file]", "Generate graphviz of dependencies.",
  99. "Generate a graphviz input file that will contain all the library and "
  100. "executable dependencies in the project."},
  101. {"--system-information [file]", "Dump information about this system.",
  102. "Dump a wide range of information about the current system. If run "
  103. "from the top of a binary tree for a CMake project it will dump "
  104. "additional information such as the cache, log files etc."},
  105. {"--debug-trycompile", "Do not delete the try_compile build tree. Only "
  106. "useful on one try_compile at a time.",
  107. "Do not delete the files and directories created for try_compile calls. "
  108. "This is useful in debugging failed try_compiles. It may however "
  109. "change the results of the try-compiles as old junk from a previous "
  110. "try-compile may cause a different test to either pass or fail "
  111. "incorrectly. This option is best used for one try-compile at a time, "
  112. "and only when debugging." },
  113. {"--debug-output", "Put cmake in a debug mode.",
  114. "Print extra stuff during the cmake run like stack traces with "
  115. "message(send_error ) calls."},
  116. {"--trace", "Put cmake in trace mode.",
  117. "Print a trace of all calls made and from where with "
  118. "message(send_error ) calls."},
  119. {"--warn-uninitialized", "Warn about uninitialized values.",
  120. "Print a warning when an uninitialized variable is used."},
  121. {"--warn-unused-vars", "Warn about unused variables.",
  122. "Find variables that are declared or set, but not used."},
  123. {"--no-warn-unused-cli", "Don't warn about command line options.",
  124. "Don't find variables that are declared on the command line, but not "
  125. "used."},
  126. {"--check-system-vars", "Find problems with variable usage in system "
  127. "files.", "Normally, unused and uninitialized variables are searched for "
  128. "only in CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. This flag tells CMake to "
  129. "warn about other files as well."},
  130. {"--help-command cmd [file]", "Print help for a single command and exit.",
  131. "Full documentation specific to the given command is displayed. "
  132. "If a file is specified, the documentation is written into and the output "
  133. "format is determined depending on the filename suffix. Supported are man "
  134. "page, HTML, DocBook and plain text."},
  135. {"--help-command-list [file]", "List available listfile commands and exit.",
  136. "The list contains all commands for which help may be obtained by using "
  137. "the --help-command argument followed by a command name. "
  138. "If a file is specified, the documentation is written into and the output "
  139. "format is determined depending on the filename suffix. Supported are man "
  140. "page, HTML, DocBook and plain text."},
  141. {"--help-commands [file]", "Print help for all commands and exit.",
  142. "Full documentation specific for all current command is displayed."
  143. "If a file is specified, the documentation is written into and the output "
  144. "format is determined depending on the filename suffix. Supported are man "
  145. "page, HTML, DocBook and plain text."},
  146. {"--help-compatcommands [file]", "Print help for compatibility commands. ",
  147. "Full documentation specific for all compatibility commands is displayed."
  148. "If a file is specified, the documentation is written into and the output "
  149. "format is determined depending on the filename suffix. Supported are man "
  150. "page, HTML, DocBook and plain text."},
  151. {"--help-module module [file]", "Print help for a single module and exit.",
  152. "Full documentation specific to the given module is displayed."
  153. "If a file is specified, the documentation is written into and the output "
  154. "format is determined depending on the filename suffix. Supported are man "
  155. "page, HTML, DocBook and plain text."},
  156. {"--help-module-list [file]", "List available modules and exit.",
  157. "The list contains all modules for which help may be obtained by using "
  158. "the --help-module argument followed by a module name. "
  159. "If a file is specified, the documentation is written into and the output "
  160. "format is determined depending on the filename suffix. Supported are man "
  161. "page, HTML, DocBook and plain text."},
  162. {"--help-modules [file]", "Print help for all modules and exit.",
  163. "Full documentation for all modules is displayed. "
  164. "If a file is specified, the documentation is written into and the output "
  165. "format is determined depending on the filename suffix. Supported are man "
  166. "page, HTML, DocBook and plain text."},
  167. {"--help-custom-modules [file]" , "Print help for all custom modules and "
  168. "exit.",
  169. "Full documentation for all custom modules is displayed. "
  170. "If a file is specified, the documentation is written into and the output "
  171. "format is determined depending on the filename suffix. Supported are man "
  172. "page, HTML, DocBook and plain text."},
  173. {"--help-policy cmp [file]",
  174. "Print help for a single policy and exit.",
  175. "Full documentation specific to the given policy is displayed."
  176. "If a file is specified, the documentation is written into and the output "
  177. "format is determined depending on the filename suffix. Supported are man "
  178. "page, HTML, DocBook and plain text."},
  179. {"--help-policies [file]", "Print help for all policies and exit.",
  180. "Full documentation for all policies is displayed."
  181. "If a file is specified, the documentation is written into and the output "
  182. "format is determined depending on the filename suffix. Supported are man "
  183. "page, HTML, DocBook and plain text."},
  184. {"--help-property prop [file]",
  185. "Print help for a single property and exit.",
  186. "Full documentation specific to the given property is displayed."
  187. "If a file is specified, the documentation is written into and the output "
  188. "format is determined depending on the filename suffix. Supported are man "
  189. "page, HTML, DocBook and plain text."},
  190. {"--help-property-list [file]", "List available properties and exit.",
  191. "The list contains all properties for which help may be obtained by using "
  192. "the --help-property argument followed by a property name. If a file is "
  193. "specified, the help is written into it."
  194. "If a file is specified, the documentation is written into and the output "
  195. "format is determined depending on the filename suffix. Supported are man "
  196. "page, HTML, DocBook and plain text."},
  197. {"--help-properties [file]", "Print help for all properties and exit.",
  198. "Full documentation for all properties is displayed."
  199. "If a file is specified, the documentation is written into and the output "
  200. "format is determined depending on the filename suffix. Supported are man "
  201. "page, HTML, DocBook and plain text."},
  202. {"--help-variable var [file]",
  203. "Print help for a single variable and exit.",
  204. "Full documentation specific to the given variable is displayed."
  205. "If a file is specified, the documentation is written into and the output "
  206. "format is determined depending on the filename suffix. Supported are man "
  207. "page, HTML, DocBook and plain text."},
  208. {"--help-variable-list [file]", "List documented variables and exit.",
  209. "The list contains all variables for which help may be obtained by using "
  210. "the --help-variable argument followed by a variable name. If a file is "
  211. "specified, the help is written into it."
  212. "If a file is specified, the documentation is written into and the output "
  213. "format is determined depending on the filename suffix. Supported are man "
  214. "page, HTML, DocBook and plain text."},
  215. {"--help-variables [file]", "Print help for all variables and exit.",
  216. "Full documentation for all variables is displayed."
  217. "If a file is specified, the documentation is written into and the output "
  218. "format is determined depending on the filename suffix. Supported are man "
  219. "page, HTML, DocBook and plain text."},
  220. {0,0,0}
  221. };
  222. //----------------------------------------------------------------------------
  223. static const char * cmDocumentationSeeAlso[][3] =
  224. {
  225. {0, "ccmake", 0},
  226. {0, "cpack", 0},
  227. {0, "ctest", 0},
  228. {0, "cmakecommands", 0},
  229. {0, "cmakecompat", 0},
  230. {0, "cmakemodules", 0},
  231. {0, "cmakeprops", 0},
  232. {0, "cmakevars", 0},
  233. {0, 0, 0}
  234. };
  235. //----------------------------------------------------------------------------
  236. static const char * cmDocumentationNOTE[][3] =
  237. {
  238. {0,
  239. "CMake no longer configures a project when run with no arguments. "
  240. "In order to configure the project in the current directory, run\n"
  241. " cmake .", 0},
  242. {0,0,0}
  243. };
  244. #endif
  245. int do_cmake(int ac, char** av);
  246. static int do_build(int ac, char** av);
  247. static cmMakefile* cmakemainGetMakefile(void *clientdata)
  248. {
  249. cmake* cm = (cmake *)clientdata;
  250. if(cm && cm->GetDebugOutput())
  251. {
  252. cmGlobalGenerator* gg=cm->GetGlobalGenerator();
  253. if (gg)
  254. {
  255. cmLocalGenerator* lg=gg->GetCurrentLocalGenerator();
  256. if (lg)
  257. {
  258. cmMakefile* mf = lg->GetMakefile();
  259. return mf;
  260. }
  261. }
  262. }
  263. return 0;
  264. }
  265. static std::string cmakemainGetStack(void *clientdata)
  266. {
  267. std::string msg;
  268. cmMakefile* mf=cmakemainGetMakefile(clientdata);
  269. if (mf)
  270. {
  271. msg = mf->GetListFileStack();
  272. if (!msg.empty())
  273. {
  274. msg = "\n Called from: " + msg;
  275. }
  276. }
  277. return msg;
  278. }
  279. static void cmakemainErrorCallback(const char* m, const char*, bool&,
  280. void *clientdata)
  281. {
  282. std::cerr << m << cmakemainGetStack(clientdata) << std::endl << std::flush;
  283. }
  284. static void cmakemainProgressCallback(const char *m, float prog,
  285. void* clientdata)
  286. {
  287. cmMakefile* mf = cmakemainGetMakefile(clientdata);
  288. std::string dir;
  289. if ((mf) && (strstr(m, "Configuring")==m) && (prog<0))
  290. {
  291. dir = " ";
  292. dir += mf->GetCurrentDirectory();
  293. }
  294. else if ((mf) && (strstr(m, "Generating")==m))
  295. {
  296. dir = " ";
  297. dir += mf->GetCurrentOutputDirectory();
  298. }
  299. if ((prog < 0) || (!dir.empty()))
  300. {
  301. std::cout << "-- " << m << dir << cmakemainGetStack(clientdata)<<std::endl;
  302. }
  303. std::cout.flush();
  304. }
  305. int main(int ac, char** av)
  306. {
  307. cmSystemTools::EnableMSVCDebugHook();
  308. cmSystemTools::FindExecutableDirectory(av[0]);
  309. if(ac > 1 && strcmp(av[1], "--build") == 0)
  310. {
  311. return do_build(ac, av);
  312. }
  313. int ret = do_cmake(ac, av);
  314. #ifdef CMAKE_BUILD_WITH_CMAKE
  315. cmDynamicLoader::FlushCache();
  316. #endif
  317. return ret;
  318. }
  319. int do_cmake(int ac, char** av)
  320. {
  321. int nocwd = 0;
  322. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  323. {
  324. std::cerr << "Current working directory cannot be established."
  325. << std::endl;
  326. nocwd = 1;
  327. }
  328. #ifdef CMAKE_BUILD_WITH_CMAKE
  329. cmDocumentation doc;
  330. if(doc.CheckOptions(ac, av, "-E") || nocwd)
  331. {
  332. // Construct and print requested documentation.
  333. cmake hcm;
  334. hcm.AddCMakePaths();
  335. doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
  336. // the command line args are processed here so that you can do
  337. // -DCMAKE_MODULE_PATH=/some/path and have this value accessible here
  338. std::vector<std::string> args;
  339. for(int i =0; i < ac; ++i)
  340. {
  341. args.push_back(av[i]);
  342. }
  343. hcm.SetCacheArgs(args);
  344. const char* modulePath = hcm.GetCacheDefinition("CMAKE_MODULE_PATH");
  345. if (modulePath)
  346. {
  347. doc.SetCMakeModulePath(modulePath);
  348. }
  349. std::vector<cmDocumentationEntry> commands;
  350. std::vector<cmDocumentationEntry> policies;
  351. std::vector<cmDocumentationEntry> compatCommands;
  352. std::vector<cmDocumentationEntry> generators;
  353. std::map<std::string,cmDocumentationSection *> propDocs;
  354. hcm.GetPolicyDocumentation(policies);
  355. hcm.GetCommandDocumentation(commands, true, false);
  356. hcm.GetCommandDocumentation(compatCommands, false, true);
  357. hcm.GetPropertiesDocumentation(propDocs);
  358. hcm.GetGeneratorDocumentation(generators);
  359. doc.SetName("cmake");
  360. doc.SetSection("Name",cmDocumentationName);
  361. doc.SetSection("Usage",cmDocumentationUsage);
  362. doc.SetSection("Description",cmDocumentationDescription);
  363. doc.AppendSection("Generators",generators);
  364. doc.PrependSection("Options",cmDocumentationOptions);
  365. doc.SetSection("Commands",commands);
  366. doc.SetSection("Policies",policies);
  367. doc.AppendSection("Compatibility Commands",compatCommands);
  368. doc.SetSections(propDocs);
  369. cmDocumentationEntry e;
  370. e.Brief =
  371. "variables defined by cmake, that give information about the project, "
  372. "and cmake";
  373. doc.PrependSection("Variables that Provide Information",e);
  374. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  375. int result = doc.PrintRequestedDocumentation(std::cout)? 0:1;
  376. // If we were run with no arguments, but a CMakeLists.txt file
  377. // exists, the user may have been trying to use the old behavior
  378. // of cmake to build a project in-source. Print a message
  379. // explaining the change to standard error and return an error
  380. // condition in case the program is running from a script.
  381. if((ac == 1) && cmSystemTools::FileExists("CMakeLists.txt"))
  382. {
  383. doc.ClearSections();
  384. doc.SetSection("NOTE", cmDocumentationNOTE);
  385. doc.Print(cmDocumentation::UsageForm, std::cerr);
  386. return 1;
  387. }
  388. return result;
  389. }
  390. #else
  391. if ( nocwd || ac == 1 )
  392. {
  393. std::cout <<
  394. "Bootstrap CMake should not be used outside CMake build process."
  395. << std::endl;
  396. return 0;
  397. }
  398. #endif
  399. bool wiz = false;
  400. bool sysinfo = false;
  401. bool command = false;
  402. bool list_cached = false;
  403. bool list_all_cached = false;
  404. bool list_help = false;
  405. bool view_only = false;
  406. bool script_mode = false;
  407. std::vector<std::string> args;
  408. for(int i =0; i < ac; ++i)
  409. {
  410. if(!command && strcmp(av[i], "-i") == 0)
  411. {
  412. wiz = true;
  413. }
  414. else if(!command && strcmp(av[i], "--system-information") == 0)
  415. {
  416. sysinfo = true;
  417. }
  418. // if command has already been set, then
  419. // do not eat the -E
  420. else if (!command && strcmp(av[i], "-E") == 0)
  421. {
  422. command = true;
  423. }
  424. else if (!command && strcmp(av[i], "-N") == 0)
  425. {
  426. view_only = true;
  427. }
  428. else if (!command && strcmp(av[i], "-L") == 0)
  429. {
  430. list_cached = true;
  431. }
  432. else if (!command && strcmp(av[i], "-LA") == 0)
  433. {
  434. list_all_cached = true;
  435. }
  436. else if (!command && strcmp(av[i], "-LH") == 0)
  437. {
  438. list_cached = true;
  439. list_help = true;
  440. }
  441. else if (!command && strcmp(av[i], "-LAH") == 0)
  442. {
  443. list_all_cached = true;
  444. list_help = true;
  445. }
  446. else if (!command && strncmp(av[i], "-P", strlen("-P")) == 0)
  447. {
  448. if ( i == ac -1 )
  449. {
  450. cmSystemTools::Error("No script specified for argument -P");
  451. }
  452. else
  453. {
  454. script_mode = true;
  455. args.push_back(av[i]);
  456. i++;
  457. args.push_back(av[i]);
  458. }
  459. }
  460. else
  461. {
  462. args.push_back(av[i]);
  463. }
  464. }
  465. if(command)
  466. {
  467. int ret = cmake::ExecuteCMakeCommand(args);
  468. return ret;
  469. }
  470. if (wiz)
  471. {
  472. cmakewizard wizard;
  473. return wizard.RunWizard(args);
  474. }
  475. if (sysinfo)
  476. {
  477. cmake cm;
  478. int ret = cm.GetSystemInformation(args);
  479. return ret;
  480. }
  481. cmake cm;
  482. cmSystemTools::SetErrorCallback(cmakemainErrorCallback, (void *)&cm);
  483. cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm);
  484. cm.SetScriptMode(script_mode);
  485. int res = cm.Run(args, view_only);
  486. if ( list_cached || list_all_cached )
  487. {
  488. cmCacheManager::CacheIterator it =
  489. cm.GetCacheManager()->GetCacheIterator();
  490. std::cout << "-- Cache values" << std::endl;
  491. for ( it.Begin(); !it.IsAtEnd(); it.Next() )
  492. {
  493. cmCacheManager::CacheEntryType t = it.GetType();
  494. if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC &&
  495. t != cmCacheManager::UNINITIALIZED )
  496. {
  497. bool advanced = it.PropertyExists("ADVANCED");
  498. if ( list_all_cached || !advanced)
  499. {
  500. if ( list_help )
  501. {
  502. std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl;
  503. }
  504. std::cout << it.GetName() << ":" <<
  505. cmCacheManager::TypeToString(it.GetType())
  506. << "=" << it.GetValue() << std::endl;
  507. if ( list_help )
  508. {
  509. std::cout << std::endl;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. // Always return a non-negative value. Windows tools do not always
  516. // interpret negative return values as errors.
  517. if(res != 0)
  518. {
  519. return 1;
  520. }
  521. else
  522. {
  523. return 0;
  524. }
  525. }
  526. //----------------------------------------------------------------------------
  527. static int do_build(int ac, char** av)
  528. {
  529. #ifndef CMAKE_BUILD_WITH_CMAKE
  530. std::cerr << "This cmake does not support --build\n";
  531. return -1;
  532. #else
  533. std::string target;
  534. std::string config = "Debug";
  535. std::string dir;
  536. std::vector<std::string> nativeOptions;
  537. bool clean = false;
  538. cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_MERGE;
  539. enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
  540. Doing doing = DoingDir;
  541. for(int i=2; i < ac; ++i)
  542. {
  543. if(doing == DoingNative)
  544. {
  545. nativeOptions.push_back(av[i]);
  546. }
  547. else if(strcmp(av[i], "--target") == 0)
  548. {
  549. doing = DoingTarget;
  550. }
  551. else if(strcmp(av[i], "--config") == 0)
  552. {
  553. doing = DoingConfig;
  554. }
  555. else if(strcmp(av[i], "--clean-first") == 0)
  556. {
  557. clean = true;
  558. doing = DoingNone;
  559. }
  560. else if(strcmp(av[i], "--use-stderr") == 0)
  561. {
  562. outputflag = cmSystemTools::OUTPUT_NORMAL;
  563. }
  564. else if(strcmp(av[i], "--") == 0)
  565. {
  566. doing = DoingNative;
  567. }
  568. else
  569. {
  570. switch (doing)
  571. {
  572. case DoingDir:
  573. dir = av[i];
  574. doing = DoingNone;
  575. break;
  576. case DoingTarget:
  577. target = av[i];
  578. doing = DoingNone;
  579. break;
  580. case DoingConfig:
  581. config = av[i];
  582. doing = DoingNone;
  583. break;
  584. default:
  585. std::cerr << "Unknown argument " << av[i] << std::endl;
  586. dir = "";
  587. break;
  588. }
  589. }
  590. }
  591. if(dir.empty())
  592. {
  593. std::cerr <<
  594. "Usage: cmake --build <dir> [options] [-- [native-options]]\n"
  595. "Options:\n"
  596. CMAKE_BUILD_OPTIONS
  597. ;
  598. return 1;
  599. }
  600. // Hack for vs6 that passes ".\Debug" as "$(IntDir)" value:
  601. //
  602. if (cmSystemTools::StringStartsWith(config.c_str(), ".\\"))
  603. {
  604. config = config.substr(2);
  605. }
  606. cmake cm;
  607. return cm.Build(dir, target, config, nativeOptions, clean, outputflag);
  608. #endif
  609. }