cmakemain.cxx 22 KB

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