cmInstallCommand.cxx 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmInstallCommand.h"
  14. #include "cmInstallDirectoryGenerator.h"
  15. #include "cmInstallFilesGenerator.h"
  16. #include "cmInstallScriptGenerator.h"
  17. #include "cmInstallTargetGenerator.h"
  18. #include "cmInstallExportGenerator.h"
  19. #include "cmInstallCommandArguments.h"
  20. #include <cmsys/Glob.hxx>
  21. static cmInstallTargetGenerator* CreateInstallTargetGenerator(cmTarget& target,
  22. const cmInstallCommandArguments& args, bool impLib, bool forceOpt = false)
  23. {
  24. return new cmInstallTargetGenerator(target, args.GetDestination().c_str(),
  25. impLib, args.GetPermissions().c_str(),
  26. args.GetConfigurations(), args.GetComponent().c_str(),
  27. args.GetOptional() || forceOpt);
  28. }
  29. static cmInstallFilesGenerator* CreateInstallFilesGenerator(
  30. const std::vector<std::string>& absFiles,
  31. const cmInstallCommandArguments& args, bool programs)
  32. {
  33. return new cmInstallFilesGenerator(absFiles, args.GetDestination().c_str(),
  34. programs, args.GetPermissions().c_str(),
  35. args.GetConfigurations(), args.GetComponent().c_str(),
  36. args.GetRename().c_str(), args.GetOptional());
  37. }
  38. // cmInstallCommand
  39. bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
  40. {
  41. // Allow calling with no arguments so that arguments may be built up
  42. // using a variable that may be left empty.
  43. if(args.empty())
  44. {
  45. return true;
  46. }
  47. // Enable the install target.
  48. this->Makefile->GetLocalGenerator()
  49. ->GetGlobalGenerator()->EnableInstallTarget();
  50. // Switch among the command modes.
  51. if(args[0] == "SCRIPT")
  52. {
  53. return this->HandleScriptMode(args);
  54. }
  55. else if(args[0] == "CODE")
  56. {
  57. return this->HandleScriptMode(args);
  58. }
  59. else if(args[0] == "TARGETS")
  60. {
  61. return this->HandleTargetsMode(args);
  62. }
  63. else if(args[0] == "FILES")
  64. {
  65. return this->HandleFilesMode(args);
  66. }
  67. else if(args[0] == "PROGRAMS")
  68. {
  69. return this->HandleFilesMode(args);
  70. }
  71. else if(args[0] == "DIRECTORY")
  72. {
  73. return this->HandleDirectoryMode(args);
  74. }
  75. else if(args[0] == "EXPORT")
  76. {
  77. return this->HandleExportMode(args);
  78. }
  79. // Unknown mode.
  80. cmStdString e = "called with unknown mode ";
  81. e += args[0];
  82. this->SetError(e.c_str());
  83. return false;
  84. }
  85. //----------------------------------------------------------------------------
  86. bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
  87. {
  88. bool doing_script = false;
  89. bool doing_code = false;
  90. for(size_t i=0; i < args.size(); ++i)
  91. {
  92. if(args[i] == "SCRIPT")
  93. {
  94. doing_script = true;
  95. doing_code = false;
  96. }
  97. else if(args[i] == "CODE")
  98. {
  99. doing_script = false;
  100. doing_code = true;
  101. }
  102. else if(doing_script)
  103. {
  104. doing_script = false;
  105. std::string script = args[i];
  106. if(!cmSystemTools::FileIsFullPath(script.c_str()))
  107. {
  108. script = this->Makefile->GetCurrentDirectory();
  109. script += "/";
  110. script += args[i];
  111. }
  112. if(cmSystemTools::FileIsDirectory(script.c_str()))
  113. {
  114. this->SetError("given a directory as value of SCRIPT argument.");
  115. return false;
  116. }
  117. this->Makefile->AddInstallGenerator(
  118. new cmInstallScriptGenerator(script.c_str()));
  119. }
  120. else if(doing_code)
  121. {
  122. doing_code = false;
  123. std::string code = args[i];
  124. this->Makefile->AddInstallGenerator(
  125. new cmInstallScriptGenerator(code.c_str(), true));
  126. }
  127. }
  128. if(doing_script)
  129. {
  130. this->SetError("given no value for SCRIPT argument.");
  131. return false;
  132. }
  133. if(doing_code)
  134. {
  135. this->SetError("given no value for CODE argument.");
  136. return false;
  137. }
  138. return true;
  139. }
  140. //----------------------------------------------------------------------------
  141. bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
  142. {
  143. // This is the TARGETS mode.
  144. std::vector<cmTarget*> targets;
  145. cmCommandArgumentsHelper argHelper;
  146. cmCommandArgumentGroup group;
  147. cmCAStringVector genericArgVector (&argHelper, 0);
  148. cmCAStringVector archiveArgVector (&argHelper, "ARCHIVE", &group);
  149. cmCAStringVector libraryArgVector (&argHelper, "LIBRARY", &group);
  150. cmCAStringVector runtimeArgVector (&argHelper, "RUNTIME", &group);
  151. cmCAStringVector frameworkArgVector (&argHelper, "FRAMEWORK", &group);
  152. cmCAStringVector bundleArgVector (&argHelper, "BUNDLE", &group);
  153. cmCAStringVector resourcesArgVector (&argHelper, "RESOURCE", &group);
  154. cmCAStringVector publicHeaderArgVector(&argHelper, "PUBLIC_HEADER ", &group);
  155. cmCAStringVector privateHeaderArgVector(&argHelper,"PRIVATE_HEADER", &group);
  156. genericArgVector.Follows(0);
  157. group.Follows(&genericArgVector);
  158. argHelper.Parse(&args, 0);
  159. std::vector<std::string> unknownArgs;
  160. cmInstallCommandArguments genericArgs;
  161. cmCAStringVector targetList(&genericArgs, "TARGETS");
  162. cmCAString exports(&genericArgs, "EXPORT", &genericArgs.ArgumentGroup);
  163. targetList.Follows(0);
  164. genericArgs.ArgumentGroup.Follows(&targetList);
  165. genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
  166. bool success = genericArgs.Finalize();
  167. cmInstallCommandArguments archiveArgs;
  168. cmInstallCommandArguments libraryArgs;
  169. cmInstallCommandArguments runtimeArgs;
  170. cmInstallCommandArguments frameworkArgs;
  171. cmInstallCommandArguments bundleArgs;
  172. cmInstallCommandArguments resourcesArgs;
  173. cmInstallCommandArguments publicHeaderArgs;
  174. cmInstallCommandArguments privateHeaderArgs;
  175. archiveArgs.Parse (&archiveArgVector.GetVector(), &unknownArgs);
  176. libraryArgs.Parse (&libraryArgVector.GetVector(), &unknownArgs);
  177. runtimeArgs.Parse (&runtimeArgVector.GetVector(), &unknownArgs);
  178. frameworkArgs.Parse (&frameworkArgVector.GetVector(), &unknownArgs);
  179. bundleArgs.Parse (&bundleArgVector.GetVector(), &unknownArgs);
  180. resourcesArgs.Parse (&resourcesArgVector.GetVector(), &unknownArgs);
  181. publicHeaderArgs.Parse (&publicHeaderArgVector.GetVector(), &unknownArgs);
  182. privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
  183. if(!unknownArgs.empty())
  184. {
  185. // Unknown argument.
  186. cmOStringStream e;
  187. e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
  188. this->SetError(e.str().c_str());
  189. return false;
  190. }
  191. // apply generic args
  192. archiveArgs.SetGenericArguments(&genericArgs);
  193. libraryArgs.SetGenericArguments(&genericArgs);
  194. runtimeArgs.SetGenericArguments(&genericArgs);
  195. frameworkArgs.SetGenericArguments(&genericArgs);
  196. bundleArgs.SetGenericArguments(&genericArgs);
  197. resourcesArgs.SetGenericArguments(&genericArgs);
  198. publicHeaderArgs.SetGenericArguments(&genericArgs);
  199. privateHeaderArgs.SetGenericArguments(&genericArgs);
  200. success = success && archiveArgs.Finalize();
  201. success = success && libraryArgs.Finalize();
  202. success = success && runtimeArgs.Finalize();
  203. success = success && frameworkArgs.Finalize();
  204. success = success && bundleArgs.Finalize();
  205. success = success && resourcesArgs.Finalize();
  206. success = success && publicHeaderArgs.Finalize();
  207. success = success && privateHeaderArgs.Finalize();
  208. if(!success)
  209. {
  210. return false;
  211. }
  212. // Check if there is something to do.
  213. if(targetList.GetVector().empty())
  214. {
  215. return true;
  216. }
  217. // Check whether this is a DLL platform.
  218. bool dll_platform = (this->Makefile->IsOn("WIN32") ||
  219. this->Makefile->IsOn("CYGWIN") ||
  220. this->Makefile->IsOn("MINGW"));
  221. for(std::vector<std::string>::const_iterator
  222. targetIt=targetList.GetVector().begin();
  223. targetIt!=targetList.GetVector().end();
  224. ++targetIt)
  225. {
  226. // Lookup this target in the current directory.
  227. if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str(), false))
  228. {
  229. // Found the target. Check its type.
  230. if(target->GetType() != cmTarget::EXECUTABLE &&
  231. target->GetType() != cmTarget::STATIC_LIBRARY &&
  232. target->GetType() != cmTarget::SHARED_LIBRARY &&
  233. target->GetType() != cmTarget::MODULE_LIBRARY)
  234. {
  235. cmOStringStream e;
  236. e << "TARGETS given target \"" << (*targetIt)
  237. << "\" which is not an executable, library, or module.";
  238. this->SetError(e.str().c_str());
  239. return false;
  240. }
  241. // Store the target in the list to be installed.
  242. targets.push_back(target);
  243. }
  244. else
  245. {
  246. // Did not find the target.
  247. cmOStringStream e;
  248. e << "TARGETS given target \"" << (*targetIt)
  249. << "\" which does not exist in this directory.";
  250. this->SetError(e.str().c_str());
  251. return false;
  252. }
  253. }
  254. // Generate install script code to install the given targets.
  255. for(std::vector<cmTarget*>::iterator ti = targets.begin();
  256. ti != targets.end(); ++ti)
  257. {
  258. // Handle each target type.
  259. cmTarget& target = *(*ti);
  260. cmInstallTargetGenerator* archiveGenerator = 0;
  261. cmInstallTargetGenerator* libraryGenerator = 0;
  262. cmInstallTargetGenerator* runtimeGenerator = 0;
  263. cmInstallTargetGenerator* frameworkGenerator = 0;
  264. cmInstallTargetGenerator* bundleGenerator = 0;
  265. cmInstallTargetGenerator* resourcesGenerator = 0;
  266. cmInstallTargetGenerator* publicHeaderGenerator = 0;
  267. cmInstallTargetGenerator* privateHeaderGenerator = 0;
  268. switch(target.GetType())
  269. {
  270. case cmTarget::SHARED_LIBRARY:
  271. {
  272. // Shared libraries are handled differently on DLL and non-DLL
  273. // platforms. All windows platforms are DLL platforms including
  274. // cygwin. Currently no other platform is a DLL platform.
  275. if(dll_platform)
  276. {
  277. // This is a DLL platform.
  278. if(!archiveArgs.GetDestination().empty())
  279. {
  280. // The import library uses the ARCHIVE properties.
  281. archiveGenerator = CreateInstallTargetGenerator(target,
  282. archiveArgs, true);
  283. }
  284. if(!runtimeArgs.GetDestination().empty())
  285. {
  286. // The DLL uses the RUNTIME properties.
  287. runtimeGenerator = CreateInstallTargetGenerator(target,
  288. runtimeArgs, false);
  289. }
  290. if ((archiveGenerator==0) && (runtimeGenerator==0))
  291. {
  292. this->SetError("Library TARGETS given no DESTINATION!");
  293. return false;
  294. }
  295. }
  296. else
  297. {
  298. // This is a non-DLL platform.
  299. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  300. // INSTALL properties. Otherwise, use the LIBRARY properties.
  301. if(target.GetPropertyAsBool("FRAMEWORK"))
  302. {
  303. // Use the FRAMEWORK properties.
  304. if (!frameworkArgs.GetDestination().empty())
  305. {
  306. frameworkGenerator = CreateInstallTargetGenerator(target,
  307. frameworkArgs, false);
  308. }
  309. else
  310. {
  311. cmOStringStream e;
  312. e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
  313. "FRAMEWORK target \"" << target.GetName() << "\".";
  314. this->SetError(e.str().c_str());
  315. return false;
  316. }
  317. }
  318. else
  319. {
  320. // The shared library uses the LIBRARY properties.
  321. if (!libraryArgs.GetDestination().empty())
  322. {
  323. libraryGenerator = CreateInstallTargetGenerator(target,
  324. libraryArgs, false);
  325. }
  326. else
  327. {
  328. cmOStringStream e;
  329. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  330. "target \"" << target.GetName() << "\".";
  331. this->SetError(e.str().c_str());
  332. return false;
  333. }
  334. }
  335. }
  336. /* if(target.GetPropertyAsBool("FRAMEWORK"))
  337. {
  338. // Create the files install generator.
  339. this->Makefile->AddInstallGenerator(CreateInstallFilesGenerator(
  340. absFiles, publicHeaderArgs, false);
  341. }*/
  342. }
  343. break;
  344. case cmTarget::STATIC_LIBRARY:
  345. {
  346. // Static libraries use ARCHIVE properties.
  347. if (!archiveArgs.GetDestination().empty())
  348. {
  349. archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
  350. false);
  351. }
  352. else
  353. {
  354. cmOStringStream e;
  355. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  356. "target \"" << target.GetName() << "\".";
  357. this->SetError(e.str().c_str());
  358. return false;
  359. }
  360. }
  361. break;
  362. case cmTarget::MODULE_LIBRARY:
  363. {
  364. // Modules use LIBRARY properties.
  365. if (!libraryArgs.GetDestination().empty())
  366. {
  367. libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
  368. false);
  369. }
  370. else
  371. {
  372. cmOStringStream e;
  373. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  374. << target.GetName() << "\".";
  375. this->SetError(e.str().c_str());
  376. return false;
  377. }
  378. }
  379. break;
  380. case cmTarget::EXECUTABLE:
  381. {
  382. // Executables use the RUNTIME properties.
  383. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  384. {
  385. if (!bundleArgs.GetDestination().empty())
  386. {
  387. bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
  388. false);
  389. }
  390. else
  391. {
  392. cmOStringStream e;
  393. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  394. "executable target \"" << target.GetName() << "\".";
  395. this->SetError(e.str().c_str());
  396. return false;
  397. }
  398. }
  399. else
  400. {
  401. if (!runtimeArgs.GetDestination().empty())
  402. {
  403. runtimeGenerator = CreateInstallTargetGenerator(target,
  404. runtimeArgs, false);
  405. }
  406. else
  407. {
  408. cmOStringStream e;
  409. e << "TARGETS given no RUNTIME DESTINATION for executable "
  410. "target \"" << target.GetName() << "\".";
  411. this->SetError(e.str().c_str());
  412. return false;
  413. }
  414. }
  415. // On DLL platforms an executable may also have an import
  416. // library. Install it to the archive destination if it
  417. // exists.
  418. if(dll_platform && !archiveArgs.GetDestination().empty() &&
  419. target.GetPropertyAsBool("ENABLE_EXPORTS"))
  420. {
  421. // The import library uses the ARCHIVE properties.
  422. archiveGenerator = CreateInstallTargetGenerator(target,
  423. archiveArgs, true, true);
  424. }
  425. }
  426. break;
  427. default:
  428. // This should never happen due to the above type check.
  429. // Ignore the case.
  430. break;
  431. }
  432. this->Makefile->AddInstallGenerator(archiveGenerator);
  433. this->Makefile->AddInstallGenerator(libraryGenerator);
  434. this->Makefile->AddInstallGenerator(runtimeGenerator);
  435. this->Makefile->AddInstallGenerator(frameworkGenerator);
  436. this->Makefile->AddInstallGenerator(bundleGenerator);
  437. this->Makefile->AddInstallGenerator(resourcesGenerator);
  438. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  439. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  440. if (!exports.GetString().empty())
  441. {
  442. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  443. ->AddTargetToExports(exports.GetCString(),
  444. &target,
  445. archiveGenerator,
  446. runtimeGenerator,
  447. libraryGenerator,
  448. frameworkGenerator,
  449. bundleGenerator);
  450. }
  451. }
  452. // Tell the global generator about any installation component names specified
  453. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  454. ->AddInstallComponent(archiveArgs.GetComponent().c_str());
  455. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  456. ->AddInstallComponent(libraryArgs.GetComponent().c_str());
  457. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  458. ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
  459. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  460. ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
  461. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  462. ->AddInstallComponent(bundleArgs.GetComponent().c_str());
  463. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  464. ->AddInstallComponent(resourcesArgs.GetComponent().c_str());
  465. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  466. ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
  467. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  468. ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
  469. return true;
  470. }
  471. //----------------------------------------------------------------------------
  472. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  473. {
  474. // This is the FILES mode.
  475. bool programs = (args[0] == "PROGRAMS");
  476. cmInstallCommandArguments ica;
  477. cmCAStringVector files(&ica, programs ? "PROGRAMS" : "FILES");
  478. files.Follows(0);
  479. ica.ArgumentGroup.Follows(&files);
  480. std::vector<std::string> unknownArgs;
  481. ica.Parse(&args, &unknownArgs);
  482. if(!unknownArgs.empty())
  483. {
  484. // Unknown argument.
  485. cmOStringStream e;
  486. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  487. this->SetError(e.str().c_str());
  488. return false;
  489. }
  490. // Check if there is something to do.
  491. if(files.GetVector().empty())
  492. {
  493. return true;
  494. }
  495. if(!ica.GetRename().empty() && files.GetVector().size() > 1)
  496. {
  497. // The rename option works only with one file.
  498. cmOStringStream e;
  499. e << args[0] << " given RENAME option with more than one file.";
  500. this->SetError(e.str().c_str());
  501. return false;
  502. }
  503. std::vector<std::string> absFiles;
  504. for(std::vector<std::string>::const_iterator
  505. fileIt = files.GetVector().begin(); fileIt != files.GetVector().end();
  506. ++fileIt)
  507. {
  508. // Convert this file to a full path.
  509. std::string file = *fileIt;
  510. if(!cmSystemTools::FileIsFullPath(file.c_str()))
  511. {
  512. file = this->Makefile->GetCurrentDirectory();
  513. file += "/";
  514. file += *fileIt;
  515. }
  516. // Make sure the file is not a directory.
  517. if(cmSystemTools::FileIsDirectory(file.c_str()))
  518. {
  519. cmOStringStream e;
  520. e << args[0] << " given directory \"" << (*fileIt) << "\" to install.";
  521. this->SetError(e.str().c_str());
  522. return false;
  523. }
  524. // Store the file for installation.
  525. absFiles.push_back(file);
  526. }
  527. if (!ica.Finalize())
  528. {
  529. return false;
  530. }
  531. if(ica.GetDestination().empty())
  532. {
  533. // A destination is required.
  534. cmOStringStream e;
  535. e << args[0] << " given no DESTINATION!";
  536. this->SetError(e.str().c_str());
  537. return false;
  538. }
  539. // Create the files install generator.
  540. this->Makefile->AddInstallGenerator(
  541. CreateInstallFilesGenerator(absFiles, ica, programs));
  542. // Tell the global generator about any installation component names specified.
  543. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  544. ->AddInstallComponent(ica.GetComponent().c_str());
  545. return true;
  546. }
  547. //----------------------------------------------------------------------------
  548. bool
  549. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  550. {
  551. bool doing_dirs = true;
  552. bool doing_destination = false;
  553. bool doing_pattern = false;
  554. bool doing_regex = false;
  555. bool doing_permissions_file = false;
  556. bool doing_permissions_dir = false;
  557. bool doing_permissions_match = false;
  558. bool doing_configurations = false;
  559. bool doing_component = false;
  560. bool in_match_mode = false;
  561. std::vector<std::string> dirs;
  562. const char* destination = 0;
  563. std::string permissions_file;
  564. std::string permissions_dir;
  565. std::vector<std::string> configurations;
  566. std::string component = "Unspecified";
  567. std::string literal_args;
  568. for(unsigned int i=1; i < args.size(); ++i)
  569. {
  570. if(args[i] == "DESTINATION")
  571. {
  572. if(in_match_mode)
  573. {
  574. cmOStringStream e;
  575. e << args[0] << " does not allow \""
  576. << args[i] << "\" after PATTERN or REGEX.";
  577. this->SetError(e.str().c_str());
  578. return false;
  579. }
  580. // Switch to setting the destination property.
  581. doing_dirs = false;
  582. doing_destination = true;
  583. doing_pattern = false;
  584. doing_regex = false;
  585. doing_permissions_file = false;
  586. doing_permissions_dir = false;
  587. doing_configurations = false;
  588. doing_component = false;
  589. }
  590. else if(args[i] == "PATTERN")
  591. {
  592. // Switch to a new pattern match rule.
  593. doing_dirs = false;
  594. doing_destination = false;
  595. doing_pattern = true;
  596. doing_regex = false;
  597. doing_permissions_file = false;
  598. doing_permissions_dir = false;
  599. doing_permissions_match = false;
  600. doing_configurations = false;
  601. doing_component = false;
  602. in_match_mode = true;
  603. }
  604. else if(args[i] == "REGEX")
  605. {
  606. // Switch to a new regex match rule.
  607. doing_dirs = false;
  608. doing_destination = false;
  609. doing_pattern = false;
  610. doing_regex = true;
  611. doing_permissions_file = false;
  612. doing_permissions_dir = false;
  613. doing_permissions_match = false;
  614. doing_configurations = false;
  615. doing_component = false;
  616. in_match_mode = true;
  617. }
  618. else if(args[i] == "EXCLUDE")
  619. {
  620. // Add this property to the current match rule.
  621. if(!in_match_mode || doing_pattern || doing_regex)
  622. {
  623. cmOStringStream e;
  624. e << args[0] << " does not allow \""
  625. << args[i] << "\" before a PATTERN or REGEX is given.";
  626. this->SetError(e.str().c_str());
  627. return false;
  628. }
  629. literal_args += " EXCLUDE";
  630. doing_permissions_match = false;
  631. }
  632. else if(args[i] == "PERMISSIONS")
  633. {
  634. if(!in_match_mode)
  635. {
  636. cmOStringStream e;
  637. e << args[0] << " does not allow \""
  638. << args[i] << "\" before a PATTERN or REGEX is given.";
  639. this->SetError(e.str().c_str());
  640. return false;
  641. }
  642. // Switch to setting the current match permissions property.
  643. literal_args += " PERMISSIONS";
  644. doing_permissions_match = true;
  645. }
  646. else if(args[i] == "FILE_PERMISSIONS")
  647. {
  648. if(in_match_mode)
  649. {
  650. cmOStringStream e;
  651. e << args[0] << " does not allow \""
  652. << args[i] << "\" after PATTERN or REGEX.";
  653. this->SetError(e.str().c_str());
  654. return false;
  655. }
  656. // Switch to setting the file permissions property.
  657. doing_dirs = false;
  658. doing_destination = false;
  659. doing_pattern = false;
  660. doing_regex = false;
  661. doing_permissions_file = true;
  662. doing_permissions_dir = false;
  663. doing_configurations = false;
  664. doing_component = false;
  665. }
  666. else if(args[i] == "DIRECTORY_PERMISSIONS")
  667. {
  668. if(in_match_mode)
  669. {
  670. cmOStringStream e;
  671. e << args[0] << " does not allow \""
  672. << args[i] << "\" after PATTERN or REGEX.";
  673. this->SetError(e.str().c_str());
  674. return false;
  675. }
  676. // Switch to setting the directory permissions property.
  677. doing_dirs = false;
  678. doing_destination = false;
  679. doing_pattern = false;
  680. doing_regex = false;
  681. doing_permissions_file = false;
  682. doing_permissions_dir = true;
  683. doing_configurations = false;
  684. doing_component = false;
  685. }
  686. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  687. {
  688. if(in_match_mode)
  689. {
  690. cmOStringStream e;
  691. e << args[0] << " does not allow \""
  692. << args[i] << "\" after PATTERN or REGEX.";
  693. this->SetError(e.str().c_str());
  694. return false;
  695. }
  696. // Add this option literally.
  697. doing_dirs = false;
  698. doing_destination = false;
  699. doing_pattern = false;
  700. doing_regex = false;
  701. doing_permissions_file = false;
  702. doing_permissions_dir = false;
  703. doing_configurations = false;
  704. doing_component = false;
  705. literal_args += " USE_SOURCE_PERMISSIONS";
  706. }
  707. else if(args[i] == "CONFIGURATIONS")
  708. {
  709. if(in_match_mode)
  710. {
  711. cmOStringStream e;
  712. e << args[0] << " does not allow \""
  713. << args[i] << "\" after PATTERN or REGEX.";
  714. this->SetError(e.str().c_str());
  715. return false;
  716. }
  717. // Switch to setting the configurations property.
  718. doing_dirs = false;
  719. doing_destination = false;
  720. doing_pattern = false;
  721. doing_regex = false;
  722. doing_permissions_file = false;
  723. doing_permissions_dir = false;
  724. doing_configurations = true;
  725. doing_component = false;
  726. }
  727. else if(args[i] == "COMPONENT")
  728. {
  729. if(in_match_mode)
  730. {
  731. cmOStringStream e;
  732. e << args[0] << " does not allow \""
  733. << args[i] << "\" after PATTERN or REGEX.";
  734. this->SetError(e.str().c_str());
  735. return false;
  736. }
  737. // Switch to setting the component property.
  738. doing_dirs = false;
  739. doing_destination = false;
  740. doing_pattern = false;
  741. doing_regex = false;
  742. doing_permissions_file = false;
  743. doing_permissions_dir = false;
  744. doing_configurations = false;
  745. doing_component = true;
  746. }
  747. else if(doing_dirs)
  748. {
  749. // Convert this directory to a full path.
  750. std::string dir = args[i];
  751. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  752. {
  753. dir = this->Makefile->GetCurrentDirectory();
  754. dir += "/";
  755. dir += args[i];
  756. }
  757. // Make sure the name is a directory.
  758. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  759. {
  760. cmOStringStream e;
  761. e << args[0] << " given non-directory \""
  762. << args[i] << "\" to install.";
  763. this->SetError(e.str().c_str());
  764. return false;
  765. }
  766. // Store the directory for installation.
  767. dirs.push_back(dir);
  768. }
  769. else if(doing_configurations)
  770. {
  771. configurations.push_back(args[i]);
  772. }
  773. else if(doing_destination)
  774. {
  775. destination = args[i].c_str();
  776. doing_destination = false;
  777. }
  778. else if(doing_pattern)
  779. {
  780. // Convert the pattern to a regular expression. Require a
  781. // leading slash and trailing end-of-string in the matched
  782. // string to make sure the pattern matches only whole file
  783. // names.
  784. literal_args += " REGEX \"/";
  785. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  786. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  787. literal_args += regex;
  788. literal_args += "$\"";
  789. doing_pattern = false;
  790. }
  791. else if(doing_regex)
  792. {
  793. literal_args += " REGEX \"";
  794. // Match rules are case-insensitive on some platforms.
  795. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  796. std::string regex = cmSystemTools::LowerCase(args[i]);
  797. #else
  798. std::string regex = args[i];
  799. #endif
  800. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  801. literal_args += regex;
  802. literal_args += "\"";
  803. doing_regex = false;
  804. }
  805. else if(doing_component)
  806. {
  807. component = args[i];
  808. doing_component = false;
  809. }
  810. else if(doing_permissions_file)
  811. {
  812. // Check the requested permission.
  813. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
  814. {
  815. cmOStringStream e;
  816. e << args[0] << " given invalid file permission \""
  817. << args[i] << "\".";
  818. this->SetError(e.str().c_str());
  819. return false;
  820. }
  821. }
  822. else if(doing_permissions_dir)
  823. {
  824. // Check the requested permission.
  825. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
  826. {
  827. cmOStringStream e;
  828. e << args[0] << " given invalid directory permission \""
  829. << args[i] << "\".";
  830. this->SetError(e.str().c_str());
  831. return false;
  832. }
  833. }
  834. else if(doing_permissions_match)
  835. {
  836. // Check the requested permission.
  837. if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
  838. {
  839. cmOStringStream e;
  840. e << args[0] << " given invalid permission \""
  841. << args[i] << "\".";
  842. this->SetError(e.str().c_str());
  843. return false;
  844. }
  845. }
  846. else
  847. {
  848. // Unknown argument.
  849. cmOStringStream e;
  850. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  851. this->SetError(e.str().c_str());
  852. return false;
  853. }
  854. }
  855. // Support installing an empty directory.
  856. if(dirs.empty() && destination)
  857. {
  858. dirs.push_back("");
  859. }
  860. // Check if there is something to do.
  861. if(dirs.empty())
  862. {
  863. return true;
  864. }
  865. if(!destination)
  866. {
  867. // A destination is required.
  868. cmOStringStream e;
  869. e << args[0] << " given no DESTINATION!";
  870. this->SetError(e.str().c_str());
  871. return false;
  872. }
  873. // Compute destination path.
  874. std::string dest;
  875. cmInstallCommandArguments::ComputeDestination(destination, dest);
  876. // Create the directory install generator.
  877. this->Makefile->AddInstallGenerator(
  878. new cmInstallDirectoryGenerator(dirs, dest.c_str(),
  879. permissions_file.c_str(),
  880. permissions_dir.c_str(),
  881. configurations,
  882. component.c_str(),
  883. literal_args.c_str()));
  884. // Tell the global generator about any installation component names
  885. // specified.
  886. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  887. ->AddInstallComponent(component.c_str());
  888. return true;
  889. }
  890. //----------------------------------------------------------------------------
  891. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  892. {
  893. // This is the EXPORT mode.
  894. cmInstallCommandArguments ica;
  895. cmCAStringVector exports(&ica, "EXPORT");
  896. cmCAString prefix(&ica, "PREFIX", &ica.ArgumentGroup);
  897. cmCAString filename(&ica, "FILENAME", &ica.ArgumentGroup);
  898. exports.Follows(0);
  899. ica.ArgumentGroup.Follows(&exports);
  900. std::vector<std::string> unknownArgs;
  901. ica.Parse(&args, &unknownArgs);
  902. if (!unknownArgs.empty())
  903. {
  904. // Unknown argument.
  905. cmOStringStream e;
  906. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  907. this->SetError(e.str().c_str());
  908. return false;
  909. }
  910. if (!ica.Finalize())
  911. {
  912. return false;
  913. }
  914. std::string cmakeDir = this->Makefile->GetHomeOutputDirectory();
  915. cmakeDir += cmake::GetCMakeFilesDirectory();
  916. for(std::vector<std::string>::const_iterator
  917. exportIt = exports.GetVector().begin();
  918. exportIt != exports.GetVector().end();
  919. ++exportIt)
  920. {
  921. const std::vector<cmTargetExport*>* exportSet = this->
  922. Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  923. GetExportSet(exportIt->c_str());
  924. if (exportSet == 0)
  925. {
  926. return false;
  927. }
  928. // Create the export install generator.
  929. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  930. ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  931. ica.GetConfigurations(),0 , filename.GetCString(),
  932. prefix.GetCString(), cmakeDir.c_str());
  933. if (exportGenerator->SetExportSet(exportIt->c_str(),exportSet))
  934. {
  935. this->Makefile->AddInstallGenerator(exportGenerator);
  936. }
  937. else
  938. {
  939. delete exportGenerator;
  940. return false;
  941. }
  942. }
  943. return true;
  944. }