cmInstallCommand.cxx 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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.Parser, "TARGETS");
  162. cmCAString exports(&genericArgs.Parser,"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. cmInstallFilesGenerator* resourcesGenerator = 0;
  266. cmInstallFilesGenerator* publicHeaderGenerator = 0;
  267. cmInstallFilesGenerator* 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. }
  337. break;
  338. case cmTarget::STATIC_LIBRARY:
  339. {
  340. // Static libraries use ARCHIVE properties.
  341. if (!archiveArgs.GetDestination().empty())
  342. {
  343. archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
  344. false);
  345. }
  346. else
  347. {
  348. cmOStringStream e;
  349. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  350. "target \"" << target.GetName() << "\".";
  351. this->SetError(e.str().c_str());
  352. return false;
  353. }
  354. }
  355. break;
  356. case cmTarget::MODULE_LIBRARY:
  357. {
  358. // Modules use LIBRARY properties.
  359. if (!libraryArgs.GetDestination().empty())
  360. {
  361. libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
  362. false);
  363. }
  364. else
  365. {
  366. cmOStringStream e;
  367. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  368. << target.GetName() << "\".";
  369. this->SetError(e.str().c_str());
  370. return false;
  371. }
  372. }
  373. break;
  374. case cmTarget::EXECUTABLE:
  375. {
  376. // Executables use the RUNTIME properties.
  377. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  378. {
  379. if (!bundleArgs.GetDestination().empty())
  380. {
  381. bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
  382. false);
  383. }
  384. else
  385. {
  386. cmOStringStream e;
  387. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  388. "executable target \"" << target.GetName() << "\".";
  389. this->SetError(e.str().c_str());
  390. return false;
  391. }
  392. }
  393. else
  394. {
  395. if (!runtimeArgs.GetDestination().empty())
  396. {
  397. runtimeGenerator = CreateInstallTargetGenerator(target,
  398. runtimeArgs, false);
  399. }
  400. else
  401. {
  402. cmOStringStream e;
  403. e << "TARGETS given no RUNTIME DESTINATION for executable "
  404. "target \"" << target.GetName() << "\".";
  405. this->SetError(e.str().c_str());
  406. return false;
  407. }
  408. }
  409. // On DLL platforms an executable may also have an import
  410. // library. Install it to the archive destination if it
  411. // exists.
  412. if(dll_platform && !archiveArgs.GetDestination().empty() &&
  413. target.GetPropertyAsBool("ENABLE_EXPORTS"))
  414. {
  415. // The import library uses the ARCHIVE properties.
  416. archiveGenerator = CreateInstallTargetGenerator(target,
  417. archiveArgs, true, true);
  418. }
  419. }
  420. break;
  421. default:
  422. // This should never happen due to the above type check.
  423. // Ignore the case.
  424. break;
  425. }
  426. // if(target.GetProperty("ASSOCIATED_FILES");
  427. const char* files = target.GetProperty("PUBLIC_HEADER");
  428. if ((files) && (*files))
  429. {
  430. std::vector<std::string> relFiles;
  431. cmSystemTools::ExpandListArgument(files, relFiles);
  432. std::vector<std::string> absFiles;
  433. if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles))
  434. {
  435. return false;
  436. }
  437. // Create the files install generator.
  438. if (!publicHeaderArgs.GetDestination().empty())
  439. {
  440. publicHeaderGenerator = CreateInstallFilesGenerator(absFiles,
  441. publicHeaderArgs, false);
  442. }
  443. else
  444. {
  445. cmOStringStream e;
  446. e << "TARGETS given no PUBLIC_HEADER DESTINATION for header files\""
  447. << target.GetName() << "\".";
  448. this->SetError(e.str().c_str());
  449. return false;
  450. }
  451. }
  452. files = target.GetProperty("PRIVATE_HEADER");
  453. if ((files) && (*files))
  454. {
  455. std::vector<std::string> relFiles;
  456. cmSystemTools::ExpandListArgument(files, relFiles);
  457. std::vector<std::string> absFiles;
  458. if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles))
  459. {
  460. return false;
  461. }
  462. // Create the files install generator.
  463. if (!privateHeaderArgs.GetDestination().empty())
  464. {
  465. privateHeaderGenerator = CreateInstallFilesGenerator(absFiles,
  466. privateHeaderArgs, false);
  467. }
  468. else
  469. {
  470. cmOStringStream e;
  471. e << "TARGETS given no PRIVATE_HEADER DESTINATION for header files\""
  472. << target.GetName() << "\".";
  473. this->SetError(e.str().c_str());
  474. return false;
  475. }
  476. }
  477. files = target.GetProperty("RESOURCE_FILES");
  478. if ((files) && (*files))
  479. {
  480. std::vector<std::string> relFiles;
  481. cmSystemTools::ExpandListArgument(files, relFiles);
  482. std::vector<std::string> absFiles;
  483. if (!this->MakeFilesFullPath("RESOURCE_FILES", relFiles, absFiles))
  484. {
  485. return false;
  486. }
  487. // Create the files install generator.
  488. if (!privateHeaderArgs.GetDestination().empty())
  489. {
  490. resourcesGenerator = CreateInstallFilesGenerator(absFiles,
  491. resourcesArgs, false);
  492. }
  493. else
  494. {
  495. cmOStringStream e;
  496. e << "TARGETS given no RESOURCES DESTINATION for resource files\""
  497. << target.GetName() << "\".";
  498. this->SetError(e.str().c_str());
  499. return false;
  500. }
  501. }
  502. this->Makefile->AddInstallGenerator(archiveGenerator);
  503. this->Makefile->AddInstallGenerator(libraryGenerator);
  504. this->Makefile->AddInstallGenerator(runtimeGenerator);
  505. this->Makefile->AddInstallGenerator(frameworkGenerator);
  506. this->Makefile->AddInstallGenerator(bundleGenerator);
  507. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  508. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  509. this->Makefile->AddInstallGenerator(resourcesGenerator);
  510. if (!exports.GetString().empty())
  511. {
  512. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  513. ->AddTargetToExports(exports.GetCString(), &target,
  514. archiveGenerator, runtimeGenerator,
  515. libraryGenerator, frameworkGenerator,
  516. bundleGenerator, publicHeaderGenerator);
  517. }
  518. }
  519. // Tell the global generator about any installation component names specified
  520. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  521. ->AddInstallComponent(archiveArgs.GetComponent().c_str());
  522. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  523. ->AddInstallComponent(libraryArgs.GetComponent().c_str());
  524. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  525. ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
  526. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  527. ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
  528. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  529. ->AddInstallComponent(bundleArgs.GetComponent().c_str());
  530. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  531. ->AddInstallComponent(resourcesArgs.GetComponent().c_str());
  532. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  533. ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
  534. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  535. ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
  536. return true;
  537. }
  538. //----------------------------------------------------------------------------
  539. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  540. {
  541. // This is the FILES mode.
  542. bool programs = (args[0] == "PROGRAMS");
  543. cmInstallCommandArguments ica;
  544. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  545. files.Follows(0);
  546. ica.ArgumentGroup.Follows(&files);
  547. std::vector<std::string> unknownArgs;
  548. ica.Parse(&args, &unknownArgs);
  549. if(!unknownArgs.empty())
  550. {
  551. // Unknown argument.
  552. cmOStringStream e;
  553. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  554. this->SetError(e.str().c_str());
  555. return false;
  556. }
  557. // Check if there is something to do.
  558. if(files.GetVector().empty())
  559. {
  560. return true;
  561. }
  562. if(!ica.GetRename().empty() && files.GetVector().size() > 1)
  563. {
  564. // The rename option works only with one file.
  565. cmOStringStream e;
  566. e << args[0] << " given RENAME option with more than one file.";
  567. this->SetError(e.str().c_str());
  568. return false;
  569. }
  570. std::vector<std::string> absFiles;
  571. if (!this->MakeFilesFullPath(args[0].c_str(), files.GetVector(), absFiles))
  572. {
  573. return false;
  574. }
  575. if (!ica.Finalize())
  576. {
  577. return false;
  578. }
  579. if(ica.GetDestination().empty())
  580. {
  581. // A destination is required.
  582. cmOStringStream e;
  583. e << args[0] << " given no DESTINATION!";
  584. this->SetError(e.str().c_str());
  585. return false;
  586. }
  587. // Create the files install generator.
  588. this->Makefile->AddInstallGenerator(
  589. CreateInstallFilesGenerator(absFiles, ica, programs));
  590. // Tell the global generator about any installation component names specified.
  591. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  592. ->AddInstallComponent(ica.GetComponent().c_str());
  593. return true;
  594. }
  595. //----------------------------------------------------------------------------
  596. bool
  597. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  598. {
  599. bool doing_dirs = true;
  600. bool doing_destination = false;
  601. bool doing_pattern = false;
  602. bool doing_regex = false;
  603. bool doing_permissions_file = false;
  604. bool doing_permissions_dir = false;
  605. bool doing_permissions_match = false;
  606. bool doing_configurations = false;
  607. bool doing_component = false;
  608. bool in_match_mode = false;
  609. std::vector<std::string> dirs;
  610. const char* destination = 0;
  611. std::string permissions_file;
  612. std::string permissions_dir;
  613. std::vector<std::string> configurations;
  614. std::string component = "Unspecified";
  615. std::string literal_args;
  616. for(unsigned int i=1; i < args.size(); ++i)
  617. {
  618. if(args[i] == "DESTINATION")
  619. {
  620. if(in_match_mode)
  621. {
  622. cmOStringStream e;
  623. e << args[0] << " does not allow \""
  624. << args[i] << "\" after PATTERN or REGEX.";
  625. this->SetError(e.str().c_str());
  626. return false;
  627. }
  628. // Switch to setting the destination property.
  629. doing_dirs = false;
  630. doing_destination = true;
  631. doing_pattern = false;
  632. doing_regex = false;
  633. doing_permissions_file = false;
  634. doing_permissions_dir = false;
  635. doing_configurations = false;
  636. doing_component = false;
  637. }
  638. else if(args[i] == "PATTERN")
  639. {
  640. // Switch to a new pattern match rule.
  641. doing_dirs = false;
  642. doing_destination = false;
  643. doing_pattern = true;
  644. doing_regex = false;
  645. doing_permissions_file = false;
  646. doing_permissions_dir = false;
  647. doing_permissions_match = false;
  648. doing_configurations = false;
  649. doing_component = false;
  650. in_match_mode = true;
  651. }
  652. else if(args[i] == "REGEX")
  653. {
  654. // Switch to a new regex match rule.
  655. doing_dirs = false;
  656. doing_destination = false;
  657. doing_pattern = false;
  658. doing_regex = true;
  659. doing_permissions_file = false;
  660. doing_permissions_dir = false;
  661. doing_permissions_match = false;
  662. doing_configurations = false;
  663. doing_component = false;
  664. in_match_mode = true;
  665. }
  666. else if(args[i] == "EXCLUDE")
  667. {
  668. // Add this property to the current match rule.
  669. if(!in_match_mode || doing_pattern || doing_regex)
  670. {
  671. cmOStringStream e;
  672. e << args[0] << " does not allow \""
  673. << args[i] << "\" before a PATTERN or REGEX is given.";
  674. this->SetError(e.str().c_str());
  675. return false;
  676. }
  677. literal_args += " EXCLUDE";
  678. doing_permissions_match = false;
  679. }
  680. else if(args[i] == "PERMISSIONS")
  681. {
  682. if(!in_match_mode)
  683. {
  684. cmOStringStream e;
  685. e << args[0] << " does not allow \""
  686. << args[i] << "\" before a PATTERN or REGEX is given.";
  687. this->SetError(e.str().c_str());
  688. return false;
  689. }
  690. // Switch to setting the current match permissions property.
  691. literal_args += " PERMISSIONS";
  692. doing_permissions_match = true;
  693. }
  694. else if(args[i] == "FILE_PERMISSIONS")
  695. {
  696. if(in_match_mode)
  697. {
  698. cmOStringStream e;
  699. e << args[0] << " does not allow \""
  700. << args[i] << "\" after PATTERN or REGEX.";
  701. this->SetError(e.str().c_str());
  702. return false;
  703. }
  704. // Switch to setting the file permissions property.
  705. doing_dirs = false;
  706. doing_destination = false;
  707. doing_pattern = false;
  708. doing_regex = false;
  709. doing_permissions_file = true;
  710. doing_permissions_dir = false;
  711. doing_configurations = false;
  712. doing_component = false;
  713. }
  714. else if(args[i] == "DIRECTORY_PERMISSIONS")
  715. {
  716. if(in_match_mode)
  717. {
  718. cmOStringStream e;
  719. e << args[0] << " does not allow \""
  720. << args[i] << "\" after PATTERN or REGEX.";
  721. this->SetError(e.str().c_str());
  722. return false;
  723. }
  724. // Switch to setting the directory permissions property.
  725. doing_dirs = false;
  726. doing_destination = false;
  727. doing_pattern = false;
  728. doing_regex = false;
  729. doing_permissions_file = false;
  730. doing_permissions_dir = true;
  731. doing_configurations = false;
  732. doing_component = false;
  733. }
  734. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  735. {
  736. if(in_match_mode)
  737. {
  738. cmOStringStream e;
  739. e << args[0] << " does not allow \""
  740. << args[i] << "\" after PATTERN or REGEX.";
  741. this->SetError(e.str().c_str());
  742. return false;
  743. }
  744. // Add this option literally.
  745. doing_dirs = false;
  746. doing_destination = false;
  747. doing_pattern = false;
  748. doing_regex = false;
  749. doing_permissions_file = false;
  750. doing_permissions_dir = false;
  751. doing_configurations = false;
  752. doing_component = false;
  753. literal_args += " USE_SOURCE_PERMISSIONS";
  754. }
  755. else if(args[i] == "CONFIGURATIONS")
  756. {
  757. if(in_match_mode)
  758. {
  759. cmOStringStream e;
  760. e << args[0] << " does not allow \""
  761. << args[i] << "\" after PATTERN or REGEX.";
  762. this->SetError(e.str().c_str());
  763. return false;
  764. }
  765. // Switch to setting the configurations property.
  766. doing_dirs = false;
  767. doing_destination = false;
  768. doing_pattern = false;
  769. doing_regex = false;
  770. doing_permissions_file = false;
  771. doing_permissions_dir = false;
  772. doing_configurations = true;
  773. doing_component = false;
  774. }
  775. else if(args[i] == "COMPONENT")
  776. {
  777. if(in_match_mode)
  778. {
  779. cmOStringStream e;
  780. e << args[0] << " does not allow \""
  781. << args[i] << "\" after PATTERN or REGEX.";
  782. this->SetError(e.str().c_str());
  783. return false;
  784. }
  785. // Switch to setting the component property.
  786. doing_dirs = false;
  787. doing_destination = false;
  788. doing_pattern = false;
  789. doing_regex = false;
  790. doing_permissions_file = false;
  791. doing_permissions_dir = false;
  792. doing_configurations = false;
  793. doing_component = true;
  794. }
  795. else if(doing_dirs)
  796. {
  797. // Convert this directory to a full path.
  798. std::string dir = args[i];
  799. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  800. {
  801. dir = this->Makefile->GetCurrentDirectory();
  802. dir += "/";
  803. dir += args[i];
  804. }
  805. // Make sure the name is a directory.
  806. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  807. {
  808. cmOStringStream e;
  809. e << args[0] << " given non-directory \""
  810. << args[i] << "\" to install.";
  811. this->SetError(e.str().c_str());
  812. return false;
  813. }
  814. // Store the directory for installation.
  815. dirs.push_back(dir);
  816. }
  817. else if(doing_configurations)
  818. {
  819. configurations.push_back(args[i]);
  820. }
  821. else if(doing_destination)
  822. {
  823. destination = args[i].c_str();
  824. doing_destination = false;
  825. }
  826. else if(doing_pattern)
  827. {
  828. // Convert the pattern to a regular expression. Require a
  829. // leading slash and trailing end-of-string in the matched
  830. // string to make sure the pattern matches only whole file
  831. // names.
  832. literal_args += " REGEX \"/";
  833. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  834. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  835. literal_args += regex;
  836. literal_args += "$\"";
  837. doing_pattern = false;
  838. }
  839. else if(doing_regex)
  840. {
  841. literal_args += " REGEX \"";
  842. // Match rules are case-insensitive on some platforms.
  843. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  844. std::string regex = cmSystemTools::LowerCase(args[i]);
  845. #else
  846. std::string regex = args[i];
  847. #endif
  848. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  849. literal_args += regex;
  850. literal_args += "\"";
  851. doing_regex = false;
  852. }
  853. else if(doing_component)
  854. {
  855. component = args[i];
  856. doing_component = false;
  857. }
  858. else if(doing_permissions_file)
  859. {
  860. // Check the requested permission.
  861. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
  862. {
  863. cmOStringStream e;
  864. e << args[0] << " given invalid file permission \""
  865. << args[i] << "\".";
  866. this->SetError(e.str().c_str());
  867. return false;
  868. }
  869. }
  870. else if(doing_permissions_dir)
  871. {
  872. // Check the requested permission.
  873. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
  874. {
  875. cmOStringStream e;
  876. e << args[0] << " given invalid directory permission \""
  877. << args[i] << "\".";
  878. this->SetError(e.str().c_str());
  879. return false;
  880. }
  881. }
  882. else if(doing_permissions_match)
  883. {
  884. // Check the requested permission.
  885. if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
  886. {
  887. cmOStringStream e;
  888. e << args[0] << " given invalid permission \""
  889. << args[i] << "\".";
  890. this->SetError(e.str().c_str());
  891. return false;
  892. }
  893. }
  894. else
  895. {
  896. // Unknown argument.
  897. cmOStringStream e;
  898. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  899. this->SetError(e.str().c_str());
  900. return false;
  901. }
  902. }
  903. // Support installing an empty directory.
  904. if(dirs.empty() && destination)
  905. {
  906. dirs.push_back("");
  907. }
  908. // Check if there is something to do.
  909. if(dirs.empty())
  910. {
  911. return true;
  912. }
  913. if(!destination)
  914. {
  915. // A destination is required.
  916. cmOStringStream e;
  917. e << args[0] << " given no DESTINATION!";
  918. this->SetError(e.str().c_str());
  919. return false;
  920. }
  921. // Compute destination path.
  922. std::string dest;
  923. cmInstallCommandArguments::ComputeDestination(destination, dest);
  924. // Create the directory install generator.
  925. this->Makefile->AddInstallGenerator(
  926. new cmInstallDirectoryGenerator(dirs, dest.c_str(),
  927. permissions_file.c_str(),
  928. permissions_dir.c_str(),
  929. configurations,
  930. component.c_str(),
  931. literal_args.c_str()));
  932. // Tell the global generator about any installation component names
  933. // specified.
  934. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  935. ->AddInstallComponent(component.c_str());
  936. return true;
  937. }
  938. //----------------------------------------------------------------------------
  939. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  940. {
  941. // This is the EXPORT mode.
  942. cmInstallCommandArguments ica;
  943. cmCAStringVector exports(&ica.Parser, "EXPORT");
  944. cmCAString prefix(&ica.Parser, "PREFIX", &ica.ArgumentGroup);
  945. cmCAString filename(&ica.Parser, "FILENAME", &ica.ArgumentGroup);
  946. exports.Follows(0);
  947. ica.ArgumentGroup.Follows(&exports);
  948. std::vector<std::string> unknownArgs;
  949. ica.Parse(&args, &unknownArgs);
  950. if (!unknownArgs.empty())
  951. {
  952. // Unknown argument.
  953. cmOStringStream e;
  954. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  955. this->SetError(e.str().c_str());
  956. return false;
  957. }
  958. if (!ica.Finalize())
  959. {
  960. return false;
  961. }
  962. std::string cmakeDir = this->Makefile->GetHomeOutputDirectory();
  963. cmakeDir += cmake::GetCMakeFilesDirectory();
  964. for(std::vector<std::string>::const_iterator
  965. exportIt = exports.GetVector().begin();
  966. exportIt != exports.GetVector().end();
  967. ++exportIt)
  968. {
  969. const std::vector<cmTargetExport*>* exportSet = this->
  970. Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  971. GetExportSet(exportIt->c_str());
  972. if (exportSet == 0)
  973. {
  974. return false;
  975. }
  976. // Create the export install generator.
  977. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  978. ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  979. ica.GetConfigurations(),0 , filename.GetCString(),
  980. prefix.GetCString(), cmakeDir.c_str());
  981. if (exportGenerator->SetExportSet(exportIt->c_str(),exportSet))
  982. {
  983. this->Makefile->AddInstallGenerator(exportGenerator);
  984. }
  985. else
  986. {
  987. delete exportGenerator;
  988. return false;
  989. }
  990. }
  991. return true;
  992. }
  993. bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
  994. const std::vector<std::string>& relFiles,
  995. std::vector<std::string>& absFiles)
  996. {
  997. for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
  998. fileIt != relFiles.end();
  999. ++fileIt)
  1000. {
  1001. std::string file = (*fileIt);
  1002. if(!cmSystemTools::FileIsFullPath(file.c_str()))
  1003. {
  1004. file = this->Makefile->GetCurrentDirectory();
  1005. file += "/";
  1006. file += *fileIt;
  1007. }
  1008. // Make sure the file is not a directory.
  1009. if(cmSystemTools::FileIsDirectory(file.c_str()))
  1010. {
  1011. cmOStringStream e;
  1012. e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
  1013. this->SetError(e.str().c_str());
  1014. return false;
  1015. }
  1016. // Store the file for installation.
  1017. absFiles.push_back(file);
  1018. }
  1019. return true;
  1020. }