cmInstallCommand.cxx 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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. /*struct InstallPart
  141. {
  142. InstallPart(cmCommandArgumentsHelper* helper, const char* key,
  143. cmCommandArgumentGroup* group);
  144. cmCAStringVector argVector;
  145. cmInstallCommandArguments args;
  146. };*/
  147. //----------------------------------------------------------------------------
  148. bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
  149. {
  150. // This is the TARGETS mode.
  151. std::vector<cmTarget*> targets;
  152. cmCommandArgumentsHelper argHelper;
  153. cmCommandArgumentGroup group;
  154. cmCAStringVector genericArgVector (&argHelper, 0);
  155. cmCAStringVector archiveArgVector (&argHelper, "ARCHIVE", &group);
  156. cmCAStringVector libraryArgVector (&argHelper, "LIBRARY", &group);
  157. cmCAStringVector runtimeArgVector (&argHelper, "RUNTIME", &group);
  158. cmCAStringVector frameworkArgVector (&argHelper, "FRAMEWORK", &group);
  159. cmCAStringVector bundleArgVector (&argHelper, "BUNDLE", &group);
  160. cmCAStringVector resourcesArgVector (&argHelper, "RESOURCE", &group);
  161. cmCAStringVector publicHeaderArgVector(&argHelper, "PUBLIC_HEADER", &group);
  162. cmCAStringVector privateHeaderArgVector(&argHelper,"PRIVATE_HEADER", &group);
  163. genericArgVector.Follows(0);
  164. group.Follows(&genericArgVector);
  165. argHelper.Parse(&args, 0);
  166. std::vector<std::string> unknownArgs;
  167. cmInstallCommandArguments genericArgs;
  168. cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
  169. cmCAString exports(&genericArgs.Parser,"EXPORT", &genericArgs.ArgumentGroup);
  170. targetList.Follows(0);
  171. genericArgs.ArgumentGroup.Follows(&targetList);
  172. genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
  173. bool success = genericArgs.Finalize();
  174. cmInstallCommandArguments archiveArgs;
  175. cmInstallCommandArguments libraryArgs;
  176. cmInstallCommandArguments runtimeArgs;
  177. cmInstallCommandArguments frameworkArgs;
  178. cmInstallCommandArguments bundleArgs;
  179. cmInstallCommandArguments resourcesArgs;
  180. cmInstallCommandArguments publicHeaderArgs;
  181. cmInstallCommandArguments privateHeaderArgs;
  182. archiveArgs.Parse (&archiveArgVector.GetVector(), &unknownArgs);
  183. libraryArgs.Parse (&libraryArgVector.GetVector(), &unknownArgs);
  184. runtimeArgs.Parse (&runtimeArgVector.GetVector(), &unknownArgs);
  185. frameworkArgs.Parse (&frameworkArgVector.GetVector(), &unknownArgs);
  186. bundleArgs.Parse (&bundleArgVector.GetVector(), &unknownArgs);
  187. resourcesArgs.Parse (&resourcesArgVector.GetVector(), &unknownArgs);
  188. publicHeaderArgs.Parse (&publicHeaderArgVector.GetVector(), &unknownArgs);
  189. privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
  190. if(!unknownArgs.empty())
  191. {
  192. // Unknown argument.
  193. cmOStringStream e;
  194. e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
  195. this->SetError(e.str().c_str());
  196. return false;
  197. }
  198. // apply generic args
  199. archiveArgs.SetGenericArguments(&genericArgs);
  200. libraryArgs.SetGenericArguments(&genericArgs);
  201. runtimeArgs.SetGenericArguments(&genericArgs);
  202. frameworkArgs.SetGenericArguments(&genericArgs);
  203. bundleArgs.SetGenericArguments(&genericArgs);
  204. resourcesArgs.SetGenericArguments(&genericArgs);
  205. publicHeaderArgs.SetGenericArguments(&genericArgs);
  206. privateHeaderArgs.SetGenericArguments(&genericArgs);
  207. success = success && archiveArgs.Finalize();
  208. success = success && libraryArgs.Finalize();
  209. success = success && runtimeArgs.Finalize();
  210. success = success && frameworkArgs.Finalize();
  211. success = success && bundleArgs.Finalize();
  212. success = success && resourcesArgs.Finalize();
  213. success = success && publicHeaderArgs.Finalize();
  214. success = success && privateHeaderArgs.Finalize();
  215. if(!success)
  216. {
  217. return false;
  218. }
  219. // Check if there is something to do.
  220. if(targetList.GetVector().empty())
  221. {
  222. return true;
  223. }
  224. // Check whether this is a DLL platform.
  225. bool dll_platform = (this->Makefile->IsOn("WIN32") ||
  226. this->Makefile->IsOn("CYGWIN") ||
  227. this->Makefile->IsOn("MINGW"));
  228. for(std::vector<std::string>::const_iterator
  229. targetIt=targetList.GetVector().begin();
  230. targetIt!=targetList.GetVector().end();
  231. ++targetIt)
  232. {
  233. // Lookup this target in the current directory.
  234. if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str(), false))
  235. {
  236. // Found the target. Check its type.
  237. if(target->GetType() != cmTarget::EXECUTABLE &&
  238. target->GetType() != cmTarget::STATIC_LIBRARY &&
  239. target->GetType() != cmTarget::SHARED_LIBRARY &&
  240. target->GetType() != cmTarget::MODULE_LIBRARY)
  241. {
  242. cmOStringStream e;
  243. e << "TARGETS given target \"" << (*targetIt)
  244. << "\" which is not an executable, library, or module.";
  245. this->SetError(e.str().c_str());
  246. return false;
  247. }
  248. // Store the target in the list to be installed.
  249. targets.push_back(target);
  250. }
  251. else
  252. {
  253. // Did not find the target.
  254. cmOStringStream e;
  255. e << "TARGETS given target \"" << (*targetIt)
  256. << "\" which does not exist in this directory.";
  257. this->SetError(e.str().c_str());
  258. return false;
  259. }
  260. }
  261. // Generate install script code to install the given targets.
  262. for(std::vector<cmTarget*>::iterator ti = targets.begin();
  263. ti != targets.end(); ++ti)
  264. {
  265. // Handle each target type.
  266. cmTarget& target = *(*ti);
  267. cmInstallTargetGenerator* archiveGenerator = 0;
  268. cmInstallTargetGenerator* libraryGenerator = 0;
  269. cmInstallTargetGenerator* runtimeGenerator = 0;
  270. cmInstallTargetGenerator* frameworkGenerator = 0;
  271. cmInstallTargetGenerator* bundleGenerator = 0;
  272. cmInstallFilesGenerator* resourcesGenerator = 0;
  273. cmInstallFilesGenerator* publicHeaderGenerator = 0;
  274. cmInstallFilesGenerator* privateHeaderGenerator = 0;
  275. switch(target.GetType())
  276. {
  277. case cmTarget::SHARED_LIBRARY:
  278. {
  279. // Shared libraries are handled differently on DLL and non-DLL
  280. // platforms. All windows platforms are DLL platforms including
  281. // cygwin. Currently no other platform is a DLL platform.
  282. if(dll_platform)
  283. {
  284. // This is a DLL platform.
  285. if(!archiveArgs.GetDestination().empty())
  286. {
  287. // The import library uses the ARCHIVE properties.
  288. archiveGenerator = CreateInstallTargetGenerator(target,
  289. archiveArgs, true);
  290. }
  291. if(!runtimeArgs.GetDestination().empty())
  292. {
  293. // The DLL uses the RUNTIME properties.
  294. runtimeGenerator = CreateInstallTargetGenerator(target,
  295. runtimeArgs, false);
  296. }
  297. if ((archiveGenerator==0) && (runtimeGenerator==0))
  298. {
  299. this->SetError("Library TARGETS given no DESTINATION!");
  300. return false;
  301. }
  302. }
  303. else
  304. {
  305. // This is a non-DLL platform.
  306. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  307. // INSTALL properties. Otherwise, use the LIBRARY properties.
  308. if(target.GetPropertyAsBool("FRAMEWORK"))
  309. {
  310. // Use the FRAMEWORK properties.
  311. if (!frameworkArgs.GetDestination().empty())
  312. {
  313. frameworkGenerator = CreateInstallTargetGenerator(target,
  314. frameworkArgs, false);
  315. }
  316. else
  317. {
  318. cmOStringStream e;
  319. e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
  320. "FRAMEWORK target \"" << target.GetName() << "\".";
  321. this->SetError(e.str().c_str());
  322. return false;
  323. }
  324. }
  325. else
  326. {
  327. // The shared library uses the LIBRARY properties.
  328. if (!libraryArgs.GetDestination().empty())
  329. {
  330. libraryGenerator = CreateInstallTargetGenerator(target,
  331. libraryArgs, false);
  332. }
  333. else
  334. {
  335. cmOStringStream e;
  336. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  337. "target \"" << target.GetName() << "\".";
  338. this->SetError(e.str().c_str());
  339. return false;
  340. }
  341. }
  342. }
  343. }
  344. break;
  345. case cmTarget::STATIC_LIBRARY:
  346. {
  347. // Static libraries use ARCHIVE properties.
  348. if (!archiveArgs.GetDestination().empty())
  349. {
  350. archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
  351. false);
  352. }
  353. else
  354. {
  355. cmOStringStream e;
  356. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  357. "target \"" << target.GetName() << "\".";
  358. this->SetError(e.str().c_str());
  359. return false;
  360. }
  361. }
  362. break;
  363. case cmTarget::MODULE_LIBRARY:
  364. {
  365. // Modules use LIBRARY properties.
  366. if (!libraryArgs.GetDestination().empty())
  367. {
  368. libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
  369. false);
  370. }
  371. else
  372. {
  373. cmOStringStream e;
  374. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  375. << target.GetName() << "\".";
  376. this->SetError(e.str().c_str());
  377. return false;
  378. }
  379. }
  380. break;
  381. case cmTarget::EXECUTABLE:
  382. {
  383. // Executables use the RUNTIME properties.
  384. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  385. {
  386. if (!bundleArgs.GetDestination().empty())
  387. {
  388. bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
  389. false);
  390. }
  391. else
  392. {
  393. cmOStringStream e;
  394. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  395. "executable target \"" << target.GetName() << "\".";
  396. this->SetError(e.str().c_str());
  397. return false;
  398. }
  399. }
  400. else
  401. {
  402. if (!runtimeArgs.GetDestination().empty())
  403. {
  404. runtimeGenerator = CreateInstallTargetGenerator(target,
  405. runtimeArgs, false);
  406. }
  407. else
  408. {
  409. cmOStringStream e;
  410. e << "TARGETS given no RUNTIME DESTINATION for executable "
  411. "target \"" << target.GetName() << "\".";
  412. this->SetError(e.str().c_str());
  413. return false;
  414. }
  415. }
  416. // On DLL platforms an executable may also have an import
  417. // library. Install it to the archive destination if it
  418. // exists.
  419. if(dll_platform && !archiveArgs.GetDestination().empty() &&
  420. target.GetPropertyAsBool("ENABLE_EXPORTS"))
  421. {
  422. // The import library uses the ARCHIVE properties.
  423. archiveGenerator = CreateInstallTargetGenerator(target,
  424. archiveArgs, true, true);
  425. }
  426. }
  427. break;
  428. default:
  429. // This should never happen due to the above type check.
  430. // Ignore the case.
  431. break;
  432. }
  433. // if(target.GetProperty("ASSOCIATED_FILES");
  434. const char* files = target.GetProperty("PUBLIC_HEADER");
  435. if ((files) && (*files))
  436. {
  437. std::vector<std::string> relFiles;
  438. cmSystemTools::ExpandListArgument(files, relFiles);
  439. std::vector<std::string> absFiles;
  440. if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles))
  441. {
  442. return false;
  443. }
  444. // Create the files install generator.
  445. if (!publicHeaderArgs.GetDestination().empty())
  446. {
  447. publicHeaderGenerator = CreateInstallFilesGenerator(absFiles,
  448. publicHeaderArgs, false);
  449. }
  450. else
  451. {
  452. cmOStringStream e;
  453. e << "TARGETS given no PUBLIC_HEADER DESTINATION for header files\""
  454. << target.GetName() << "\".";
  455. this->SetError(e.str().c_str());
  456. return false;
  457. }
  458. }
  459. files = target.GetProperty("PRIVATE_HEADER");
  460. if ((files) && (*files))
  461. {
  462. std::vector<std::string> relFiles;
  463. cmSystemTools::ExpandListArgument(files, relFiles);
  464. std::vector<std::string> absFiles;
  465. if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles))
  466. {
  467. return false;
  468. }
  469. // Create the files install generator.
  470. if (!privateHeaderArgs.GetDestination().empty())
  471. {
  472. privateHeaderGenerator = CreateInstallFilesGenerator(absFiles,
  473. privateHeaderArgs, false);
  474. }
  475. else
  476. {
  477. cmOStringStream e;
  478. e << "TARGETS given no PRIVATE_HEADER DESTINATION for header files\""
  479. << target.GetName() << "\".";
  480. this->SetError(e.str().c_str());
  481. return false;
  482. }
  483. }
  484. files = target.GetProperty("RESOURCE_FILES");
  485. if ((files) && (*files))
  486. {
  487. std::vector<std::string> relFiles;
  488. cmSystemTools::ExpandListArgument(files, relFiles);
  489. std::vector<std::string> absFiles;
  490. if (!this->MakeFilesFullPath("RESOURCE_FILES", relFiles, absFiles))
  491. {
  492. return false;
  493. }
  494. // Create the files install generator.
  495. if (!privateHeaderArgs.GetDestination().empty())
  496. {
  497. resourcesGenerator = CreateInstallFilesGenerator(absFiles,
  498. resourcesArgs, false);
  499. }
  500. else
  501. {
  502. cmOStringStream e;
  503. e << "TARGETS given no RESOURCES DESTINATION for resource files\""
  504. << target.GetName() << "\".";
  505. this->SetError(e.str().c_str());
  506. return false;
  507. }
  508. }
  509. this->Makefile->AddInstallGenerator(archiveGenerator);
  510. this->Makefile->AddInstallGenerator(libraryGenerator);
  511. this->Makefile->AddInstallGenerator(runtimeGenerator);
  512. this->Makefile->AddInstallGenerator(frameworkGenerator);
  513. this->Makefile->AddInstallGenerator(bundleGenerator);
  514. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  515. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  516. this->Makefile->AddInstallGenerator(resourcesGenerator);
  517. if (!exports.GetString().empty())
  518. {
  519. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  520. ->AddTargetToExports(exports.GetCString(), &target,
  521. archiveGenerator, runtimeGenerator,
  522. libraryGenerator, frameworkGenerator,
  523. bundleGenerator, publicHeaderGenerator);
  524. }
  525. }
  526. // Tell the global generator about any installation component names specified
  527. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  528. ->AddInstallComponent(archiveArgs.GetComponent().c_str());
  529. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  530. ->AddInstallComponent(libraryArgs.GetComponent().c_str());
  531. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  532. ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
  533. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  534. ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
  535. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  536. ->AddInstallComponent(bundleArgs.GetComponent().c_str());
  537. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  538. ->AddInstallComponent(resourcesArgs.GetComponent().c_str());
  539. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  540. ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
  541. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  542. ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
  543. return true;
  544. }
  545. //----------------------------------------------------------------------------
  546. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  547. {
  548. // This is the FILES mode.
  549. bool programs = (args[0] == "PROGRAMS");
  550. cmInstallCommandArguments ica;
  551. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  552. files.Follows(0);
  553. ica.ArgumentGroup.Follows(&files);
  554. std::vector<std::string> unknownArgs;
  555. ica.Parse(&args, &unknownArgs);
  556. if(!unknownArgs.empty())
  557. {
  558. // Unknown argument.
  559. cmOStringStream e;
  560. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  561. this->SetError(e.str().c_str());
  562. return false;
  563. }
  564. // Check if there is something to do.
  565. if(files.GetVector().empty())
  566. {
  567. return true;
  568. }
  569. if(!ica.GetRename().empty() && files.GetVector().size() > 1)
  570. {
  571. // The rename option works only with one file.
  572. cmOStringStream e;
  573. e << args[0] << " given RENAME option with more than one file.";
  574. this->SetError(e.str().c_str());
  575. return false;
  576. }
  577. std::vector<std::string> absFiles;
  578. if (!this->MakeFilesFullPath(args[0].c_str(), files.GetVector(), absFiles))
  579. {
  580. return false;
  581. }
  582. if (!ica.Finalize())
  583. {
  584. return false;
  585. }
  586. if(ica.GetDestination().empty())
  587. {
  588. // A destination is required.
  589. cmOStringStream e;
  590. e << args[0] << " given no DESTINATION!";
  591. this->SetError(e.str().c_str());
  592. return false;
  593. }
  594. // Create the files install generator.
  595. this->Makefile->AddInstallGenerator(
  596. CreateInstallFilesGenerator(absFiles, ica, programs));
  597. // Tell the global generator about any installation component names specified.
  598. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  599. ->AddInstallComponent(ica.GetComponent().c_str());
  600. return true;
  601. }
  602. //----------------------------------------------------------------------------
  603. bool
  604. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  605. {
  606. bool doing_dirs = true;
  607. bool doing_destination = false;
  608. bool doing_pattern = false;
  609. bool doing_regex = false;
  610. bool doing_permissions_file = false;
  611. bool doing_permissions_dir = false;
  612. bool doing_permissions_match = false;
  613. bool doing_configurations = false;
  614. bool doing_component = false;
  615. bool in_match_mode = false;
  616. std::vector<std::string> dirs;
  617. const char* destination = 0;
  618. std::string permissions_file;
  619. std::string permissions_dir;
  620. std::vector<std::string> configurations;
  621. std::string component = "Unspecified";
  622. std::string literal_args;
  623. for(unsigned int i=1; i < args.size(); ++i)
  624. {
  625. if(args[i] == "DESTINATION")
  626. {
  627. if(in_match_mode)
  628. {
  629. cmOStringStream e;
  630. e << args[0] << " does not allow \""
  631. << args[i] << "\" after PATTERN or REGEX.";
  632. this->SetError(e.str().c_str());
  633. return false;
  634. }
  635. // Switch to setting the destination property.
  636. doing_dirs = false;
  637. doing_destination = true;
  638. doing_pattern = false;
  639. doing_regex = false;
  640. doing_permissions_file = false;
  641. doing_permissions_dir = false;
  642. doing_configurations = false;
  643. doing_component = false;
  644. }
  645. else if(args[i] == "PATTERN")
  646. {
  647. // Switch to a new pattern match rule.
  648. doing_dirs = false;
  649. doing_destination = false;
  650. doing_pattern = true;
  651. doing_regex = false;
  652. doing_permissions_file = false;
  653. doing_permissions_dir = false;
  654. doing_permissions_match = false;
  655. doing_configurations = false;
  656. doing_component = false;
  657. in_match_mode = true;
  658. }
  659. else if(args[i] == "REGEX")
  660. {
  661. // Switch to a new regex match rule.
  662. doing_dirs = false;
  663. doing_destination = false;
  664. doing_pattern = false;
  665. doing_regex = true;
  666. doing_permissions_file = false;
  667. doing_permissions_dir = false;
  668. doing_permissions_match = false;
  669. doing_configurations = false;
  670. doing_component = false;
  671. in_match_mode = true;
  672. }
  673. else if(args[i] == "EXCLUDE")
  674. {
  675. // Add this property to the current match rule.
  676. if(!in_match_mode || doing_pattern || doing_regex)
  677. {
  678. cmOStringStream e;
  679. e << args[0] << " does not allow \""
  680. << args[i] << "\" before a PATTERN or REGEX is given.";
  681. this->SetError(e.str().c_str());
  682. return false;
  683. }
  684. literal_args += " EXCLUDE";
  685. doing_permissions_match = false;
  686. }
  687. else if(args[i] == "PERMISSIONS")
  688. {
  689. if(!in_match_mode)
  690. {
  691. cmOStringStream e;
  692. e << args[0] << " does not allow \""
  693. << args[i] << "\" before a PATTERN or REGEX is given.";
  694. this->SetError(e.str().c_str());
  695. return false;
  696. }
  697. // Switch to setting the current match permissions property.
  698. literal_args += " PERMISSIONS";
  699. doing_permissions_match = true;
  700. }
  701. else if(args[i] == "FILE_PERMISSIONS")
  702. {
  703. if(in_match_mode)
  704. {
  705. cmOStringStream e;
  706. e << args[0] << " does not allow \""
  707. << args[i] << "\" after PATTERN or REGEX.";
  708. this->SetError(e.str().c_str());
  709. return false;
  710. }
  711. // Switch to setting the file permissions property.
  712. doing_dirs = false;
  713. doing_destination = false;
  714. doing_pattern = false;
  715. doing_regex = false;
  716. doing_permissions_file = true;
  717. doing_permissions_dir = false;
  718. doing_configurations = false;
  719. doing_component = false;
  720. }
  721. else if(args[i] == "DIRECTORY_PERMISSIONS")
  722. {
  723. if(in_match_mode)
  724. {
  725. cmOStringStream e;
  726. e << args[0] << " does not allow \""
  727. << args[i] << "\" after PATTERN or REGEX.";
  728. this->SetError(e.str().c_str());
  729. return false;
  730. }
  731. // Switch to setting the directory permissions property.
  732. doing_dirs = false;
  733. doing_destination = false;
  734. doing_pattern = false;
  735. doing_regex = false;
  736. doing_permissions_file = false;
  737. doing_permissions_dir = true;
  738. doing_configurations = false;
  739. doing_component = false;
  740. }
  741. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  742. {
  743. if(in_match_mode)
  744. {
  745. cmOStringStream e;
  746. e << args[0] << " does not allow \""
  747. << args[i] << "\" after PATTERN or REGEX.";
  748. this->SetError(e.str().c_str());
  749. return false;
  750. }
  751. // Add this option literally.
  752. doing_dirs = false;
  753. doing_destination = false;
  754. doing_pattern = false;
  755. doing_regex = false;
  756. doing_permissions_file = false;
  757. doing_permissions_dir = false;
  758. doing_configurations = false;
  759. doing_component = false;
  760. literal_args += " USE_SOURCE_PERMISSIONS";
  761. }
  762. else if(args[i] == "CONFIGURATIONS")
  763. {
  764. if(in_match_mode)
  765. {
  766. cmOStringStream e;
  767. e << args[0] << " does not allow \""
  768. << args[i] << "\" after PATTERN or REGEX.";
  769. this->SetError(e.str().c_str());
  770. return false;
  771. }
  772. // Switch to setting the configurations property.
  773. doing_dirs = false;
  774. doing_destination = false;
  775. doing_pattern = false;
  776. doing_regex = false;
  777. doing_permissions_file = false;
  778. doing_permissions_dir = false;
  779. doing_configurations = true;
  780. doing_component = false;
  781. }
  782. else if(args[i] == "COMPONENT")
  783. {
  784. if(in_match_mode)
  785. {
  786. cmOStringStream e;
  787. e << args[0] << " does not allow \""
  788. << args[i] << "\" after PATTERN or REGEX.";
  789. this->SetError(e.str().c_str());
  790. return false;
  791. }
  792. // Switch to setting the component property.
  793. doing_dirs = false;
  794. doing_destination = false;
  795. doing_pattern = false;
  796. doing_regex = false;
  797. doing_permissions_file = false;
  798. doing_permissions_dir = false;
  799. doing_configurations = false;
  800. doing_component = true;
  801. }
  802. else if(doing_dirs)
  803. {
  804. // Convert this directory to a full path.
  805. std::string dir = args[i];
  806. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  807. {
  808. dir = this->Makefile->GetCurrentDirectory();
  809. dir += "/";
  810. dir += args[i];
  811. }
  812. // Make sure the name is a directory.
  813. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  814. {
  815. cmOStringStream e;
  816. e << args[0] << " given non-directory \""
  817. << args[i] << "\" to install.";
  818. this->SetError(e.str().c_str());
  819. return false;
  820. }
  821. // Store the directory for installation.
  822. dirs.push_back(dir);
  823. }
  824. else if(doing_configurations)
  825. {
  826. configurations.push_back(args[i]);
  827. }
  828. else if(doing_destination)
  829. {
  830. destination = args[i].c_str();
  831. doing_destination = false;
  832. }
  833. else if(doing_pattern)
  834. {
  835. // Convert the pattern to a regular expression. Require a
  836. // leading slash and trailing end-of-string in the matched
  837. // string to make sure the pattern matches only whole file
  838. // names.
  839. literal_args += " REGEX \"/";
  840. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  841. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  842. literal_args += regex;
  843. literal_args += "$\"";
  844. doing_pattern = false;
  845. }
  846. else if(doing_regex)
  847. {
  848. literal_args += " REGEX \"";
  849. // Match rules are case-insensitive on some platforms.
  850. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  851. std::string regex = cmSystemTools::LowerCase(args[i]);
  852. #else
  853. std::string regex = args[i];
  854. #endif
  855. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  856. literal_args += regex;
  857. literal_args += "\"";
  858. doing_regex = false;
  859. }
  860. else if(doing_component)
  861. {
  862. component = args[i];
  863. doing_component = false;
  864. }
  865. else if(doing_permissions_file)
  866. {
  867. // Check the requested permission.
  868. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
  869. {
  870. cmOStringStream e;
  871. e << args[0] << " given invalid file permission \""
  872. << args[i] << "\".";
  873. this->SetError(e.str().c_str());
  874. return false;
  875. }
  876. }
  877. else if(doing_permissions_dir)
  878. {
  879. // Check the requested permission.
  880. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
  881. {
  882. cmOStringStream e;
  883. e << args[0] << " given invalid directory permission \""
  884. << args[i] << "\".";
  885. this->SetError(e.str().c_str());
  886. return false;
  887. }
  888. }
  889. else if(doing_permissions_match)
  890. {
  891. // Check the requested permission.
  892. if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
  893. {
  894. cmOStringStream e;
  895. e << args[0] << " given invalid permission \""
  896. << args[i] << "\".";
  897. this->SetError(e.str().c_str());
  898. return false;
  899. }
  900. }
  901. else
  902. {
  903. // Unknown argument.
  904. cmOStringStream e;
  905. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  906. this->SetError(e.str().c_str());
  907. return false;
  908. }
  909. }
  910. // Support installing an empty directory.
  911. if(dirs.empty() && destination)
  912. {
  913. dirs.push_back("");
  914. }
  915. // Check if there is something to do.
  916. if(dirs.empty())
  917. {
  918. return true;
  919. }
  920. if(!destination)
  921. {
  922. // A destination is required.
  923. cmOStringStream e;
  924. e << args[0] << " given no DESTINATION!";
  925. this->SetError(e.str().c_str());
  926. return false;
  927. }
  928. // Compute destination path.
  929. std::string dest;
  930. cmInstallCommandArguments::ComputeDestination(destination, dest);
  931. // Create the directory install generator.
  932. this->Makefile->AddInstallGenerator(
  933. new cmInstallDirectoryGenerator(dirs, dest.c_str(),
  934. permissions_file.c_str(),
  935. permissions_dir.c_str(),
  936. configurations,
  937. component.c_str(),
  938. literal_args.c_str()));
  939. // Tell the global generator about any installation component names
  940. // specified.
  941. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  942. ->AddInstallComponent(component.c_str());
  943. return true;
  944. }
  945. //----------------------------------------------------------------------------
  946. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  947. {
  948. // This is the EXPORT mode.
  949. cmInstallCommandArguments ica;
  950. cmCAStringVector exports(&ica.Parser, "EXPORT");
  951. cmCAString prefix(&ica.Parser, "PREFIX", &ica.ArgumentGroup);
  952. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  953. exports.Follows(0);
  954. ica.ArgumentGroup.Follows(&exports);
  955. std::vector<std::string> unknownArgs;
  956. ica.Parse(&args, &unknownArgs);
  957. if (!unknownArgs.empty())
  958. {
  959. // Unknown argument.
  960. cmOStringStream e;
  961. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  962. this->SetError(e.str().c_str());
  963. return false;
  964. }
  965. if (!ica.Finalize())
  966. {
  967. return false;
  968. }
  969. std::string cmakeDir = this->Makefile->GetHomeOutputDirectory();
  970. cmakeDir += cmake::GetCMakeFilesDirectory();
  971. for(std::vector<std::string>::const_iterator
  972. exportIt = exports.GetVector().begin();
  973. exportIt != exports.GetVector().end();
  974. ++exportIt)
  975. {
  976. const std::vector<cmTargetExport*>* exportSet = this->
  977. Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  978. GetExportSet(exportIt->c_str());
  979. if (exportSet == 0)
  980. {
  981. cmOStringStream e;
  982. e << "EXPORT given unknown export name \"" << exportIt->c_str() << "\".";
  983. this->SetError(e.str().c_str());
  984. return false;
  985. }
  986. // Create the export install generator.
  987. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  988. ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  989. ica.GetConfigurations(),0 , filename.GetCString(),
  990. prefix.GetCString(), cmakeDir.c_str());
  991. if (exportGenerator->SetExportSet(exportIt->c_str(),exportSet))
  992. {
  993. this->Makefile->AddInstallGenerator(exportGenerator);
  994. }
  995. else
  996. {
  997. cmOStringStream e;
  998. e << "EXPORT failed, maybe a target is exported more than once.";
  999. this->SetError(e.str().c_str());
  1000. delete exportGenerator;
  1001. return false;
  1002. }
  1003. }
  1004. return true;
  1005. }
  1006. bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
  1007. const std::vector<std::string>& relFiles,
  1008. std::vector<std::string>& absFiles)
  1009. {
  1010. for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
  1011. fileIt != relFiles.end();
  1012. ++fileIt)
  1013. {
  1014. std::string file = (*fileIt);
  1015. if(!cmSystemTools::FileIsFullPath(file.c_str()))
  1016. {
  1017. file = this->Makefile->GetCurrentDirectory();
  1018. file += "/";
  1019. file += *fileIt;
  1020. }
  1021. // Make sure the file is not a directory.
  1022. if(cmSystemTools::FileIsDirectory(file.c_str()))
  1023. {
  1024. cmOStringStream e;
  1025. e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
  1026. this->SetError(e.str().c_str());
  1027. return false;
  1028. }
  1029. // Store the file for installation.
  1030. absFiles.push_back(file);
  1031. }
  1032. return true;
  1033. }