cmakemain.cxx 23 KB

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