cmakemain.cxx 22 KB

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