cmInstallCommand.cxx 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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 <cmsys/Glob.hxx>
  19. // cmInstallCommand
  20. bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
  21. {
  22. // Allow calling with no arguments so that arguments may be built up
  23. // using a variable that may be left empty.
  24. if(args.empty())
  25. {
  26. return true;
  27. }
  28. // Enable the install target.
  29. this->Makefile->GetLocalGenerator()
  30. ->GetGlobalGenerator()->EnableInstallTarget();
  31. // Switch among the command modes.
  32. if(args[0] == "SCRIPT")
  33. {
  34. return this->HandleScriptMode(args);
  35. }
  36. else if(args[0] == "CODE")
  37. {
  38. return this->HandleScriptMode(args);
  39. }
  40. else if(args[0] == "TARGETS")
  41. {
  42. return this->HandleTargetsMode(args);
  43. }
  44. else if(args[0] == "FILES")
  45. {
  46. return this->HandleFilesMode(args);
  47. }
  48. else if(args[0] == "PROGRAMS")
  49. {
  50. return this->HandleFilesMode(args);
  51. }
  52. else if(args[0] == "DIRECTORY")
  53. {
  54. return this->HandleDirectoryMode(args);
  55. }
  56. // Unknown mode.
  57. cmStdString e = "called with unknown mode ";
  58. e += args[0];
  59. this->SetError(e.c_str());
  60. return false;
  61. }
  62. //----------------------------------------------------------------------------
  63. bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
  64. {
  65. bool doing_script = false;
  66. bool doing_code = false;
  67. for(size_t i=0; i < args.size(); ++i)
  68. {
  69. if(args[i] == "SCRIPT")
  70. {
  71. doing_script = true;
  72. doing_code = false;
  73. }
  74. else if(args[i] == "CODE")
  75. {
  76. doing_script = false;
  77. doing_code = true;
  78. }
  79. else if(doing_script)
  80. {
  81. doing_script = false;
  82. std::string script = args[i];
  83. if(!cmSystemTools::FileIsFullPath(script.c_str()))
  84. {
  85. script = this->Makefile->GetCurrentDirectory();
  86. script += "/";
  87. script += args[i];
  88. }
  89. if(cmSystemTools::FileIsDirectory(script.c_str()))
  90. {
  91. this->SetError("given a directory as value of SCRIPT argument.");
  92. return false;
  93. }
  94. this->Makefile->AddInstallGenerator(
  95. new cmInstallScriptGenerator(script.c_str()));
  96. }
  97. else if(doing_code)
  98. {
  99. doing_code = false;
  100. std::string code = args[i];
  101. this->Makefile->AddInstallGenerator(
  102. new cmInstallScriptGenerator(code.c_str(), true));
  103. }
  104. }
  105. if(doing_script)
  106. {
  107. this->SetError("given no value for SCRIPT argument.");
  108. return false;
  109. }
  110. if(doing_code)
  111. {
  112. this->SetError("given no value for CODE argument.");
  113. return false;
  114. }
  115. return true;
  116. }
  117. //----------------------------------------------------------------------------
  118. bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
  119. {
  120. // This is the TARGETS mode.
  121. bool doing_targets = true;
  122. bool doing_destination = false;
  123. bool doing_permissions = false;
  124. bool doing_component = false;
  125. bool doing_configurations = false;
  126. bool archive_settings = true;
  127. bool library_settings = true;
  128. bool runtime_settings = true;
  129. std::vector<cmTarget*> targets;
  130. const char* archive_destination = 0;
  131. const char* library_destination = 0;
  132. const char* runtime_destination = 0;
  133. std::string archive_permissions;
  134. std::string library_permissions;
  135. std::string runtime_permissions;
  136. std::string archive_component;
  137. std::string library_component;
  138. std::string runtime_component;
  139. std::vector<std::string> archive_configurations;
  140. std::vector<std::string> library_configurations;
  141. std::vector<std::string> runtime_configurations;
  142. for(unsigned int i=1; i < args.size(); ++i)
  143. {
  144. if(args[i] == "DESTINATION")
  145. {
  146. // Switch to setting the destination property.
  147. doing_targets = false;
  148. doing_destination = true;
  149. doing_permissions = false;
  150. doing_component = false;
  151. doing_configurations = false;
  152. }
  153. else if(args[i] == "PERMISSIONS")
  154. {
  155. // Switch to setting the permissions property.
  156. doing_targets = false;
  157. doing_destination = false;
  158. doing_permissions = true;
  159. doing_component = false;
  160. doing_configurations = false;
  161. }
  162. else if(args[i] == "COMPONENT")
  163. {
  164. // Switch to setting the component property.
  165. doing_targets = false;
  166. doing_destination = false;
  167. doing_permissions = false;
  168. doing_component = true;
  169. doing_configurations = false;
  170. }
  171. else if(args[i] == "CONFIGURATIONS")
  172. {
  173. // Switch to setting the configurations property.
  174. doing_targets = false;
  175. doing_destination = false;
  176. doing_permissions = false;
  177. doing_component = false;
  178. doing_configurations = true;
  179. }
  180. else if(args[i] == "ARCHIVE")
  181. {
  182. // Switch to setting only archive properties.
  183. doing_targets = false;
  184. doing_destination = false;
  185. doing_permissions = false;
  186. doing_component = false;
  187. doing_configurations = false;
  188. archive_settings = true;
  189. library_settings = false;
  190. runtime_settings = false;
  191. }
  192. else if(args[i] == "LIBRARY")
  193. {
  194. // Switch to setting only library properties.
  195. doing_targets = false;
  196. doing_destination = false;
  197. doing_permissions = false;
  198. doing_component = false;
  199. doing_configurations = false;
  200. archive_settings = false;
  201. library_settings = true;
  202. runtime_settings = false;
  203. }
  204. else if(args[i] == "RUNTIME")
  205. {
  206. // Switch to setting only runtime properties.
  207. doing_targets = false;
  208. doing_destination = false;
  209. doing_permissions = false;
  210. doing_component = false;
  211. doing_configurations = false;
  212. archive_settings = false;
  213. library_settings = false;
  214. runtime_settings = true;
  215. }
  216. else if(doing_targets)
  217. {
  218. // Lookup this target in the current directory.
  219. if(cmTarget* target = this->Makefile->FindTarget(args[i].c_str()))
  220. {
  221. // Found the target. Check its type.
  222. if(target->GetType() != cmTarget::EXECUTABLE &&
  223. target->GetType() != cmTarget::STATIC_LIBRARY &&
  224. target->GetType() != cmTarget::SHARED_LIBRARY &&
  225. target->GetType() != cmTarget::MODULE_LIBRARY)
  226. {
  227. cmOStringStream e;
  228. e << "TARGETS given target \"" << args[i]
  229. << "\" which is not an executable, library, or module.";
  230. this->SetError(e.str().c_str());
  231. return false;
  232. }
  233. // Store the target in the list to be installed.
  234. targets.push_back(target);
  235. }
  236. else
  237. {
  238. // Did not find the target.
  239. cmOStringStream e;
  240. e << "TARGETS given target \"" << args[i]
  241. << "\" which does not exist in this directory.";
  242. this->SetError(e.str().c_str());
  243. return false;
  244. }
  245. }
  246. else if(doing_destination)
  247. {
  248. // Set the destination in the active set(s) of properties.
  249. if(archive_settings)
  250. {
  251. archive_destination = args[i].c_str();
  252. }
  253. if(library_settings)
  254. {
  255. library_destination = args[i].c_str();
  256. }
  257. if(runtime_settings)
  258. {
  259. runtime_destination = args[i].c_str();
  260. }
  261. doing_destination = false;
  262. }
  263. else if(doing_component)
  264. {
  265. // Set the component in the active set(s) of properties.
  266. if(archive_settings)
  267. {
  268. archive_component = args[i];
  269. }
  270. if(library_settings)
  271. {
  272. library_component = args[i];
  273. }
  274. if(runtime_settings)
  275. {
  276. runtime_component = args[i];
  277. }
  278. doing_component = false;
  279. }
  280. else if(doing_permissions)
  281. {
  282. // Set the permissions in the active set(s) of properties.
  283. if(archive_settings)
  284. {
  285. // Check the requested permission.
  286. if(!this->CheckPermissions(args[i], archive_permissions))
  287. {
  288. cmOStringStream e;
  289. e << args[0] << " given invalid permission \""
  290. << args[i] << "\".";
  291. this->SetError(e.str().c_str());
  292. return false;
  293. }
  294. }
  295. if(library_settings)
  296. {
  297. // Check the requested permission.
  298. if(!this->CheckPermissions(args[i], library_permissions))
  299. {
  300. cmOStringStream e;
  301. e << args[0] << " given invalid permission \""
  302. << args[i] << "\".";
  303. this->SetError(e.str().c_str());
  304. return false;
  305. }
  306. }
  307. if(runtime_settings)
  308. {
  309. // Check the requested permission.
  310. if(!this->CheckPermissions(args[i], runtime_permissions))
  311. {
  312. cmOStringStream e;
  313. e << args[0] << " given invalid permission \""
  314. << args[i] << "\".";
  315. this->SetError(e.str().c_str());
  316. return false;
  317. }
  318. }
  319. }
  320. else if(doing_configurations)
  321. {
  322. // Add the configuration in the active set(s) of properties.
  323. if(archive_settings)
  324. {
  325. archive_configurations.push_back(args[i]);
  326. }
  327. if(library_settings)
  328. {
  329. library_configurations.push_back(args[i]);
  330. }
  331. if(runtime_settings)
  332. {
  333. runtime_configurations.push_back(args[i]);
  334. }
  335. }
  336. else
  337. {
  338. // Unknown argument.
  339. cmOStringStream e;
  340. e << "TARGETS given unknown argument \"" << args[i] << "\".";
  341. this->SetError(e.str().c_str());
  342. return false;
  343. }
  344. }
  345. // Check if there is something to do.
  346. if(targets.empty())
  347. {
  348. return true;
  349. }
  350. if(!archive_destination && !library_destination && !runtime_destination)
  351. {
  352. this->SetError("TARGETS given no DESTINATION!");
  353. return false;
  354. }
  355. // Compute destination paths.
  356. std::string archive_dest;
  357. std::string library_dest;
  358. std::string runtime_dest;
  359. this->ComputeDestination(archive_destination, archive_dest);
  360. this->ComputeDestination(library_destination, library_dest);
  361. this->ComputeDestination(runtime_destination, runtime_dest);
  362. // Generate install script code to install the given targets.
  363. for(std::vector<cmTarget*>::iterator ti = targets.begin();
  364. ti != targets.end(); ++ti)
  365. {
  366. // Handle each target type.
  367. cmTarget& target = *(*ti);
  368. switch(target.GetType())
  369. {
  370. case cmTarget::SHARED_LIBRARY:
  371. {
  372. // Shared libraries are handled differently on DLL and non-DLL
  373. // platforms. All windows platforms are DLL platforms
  374. // including cygwin. Currently no other platform is a DLL
  375. // platform.
  376. #if defined(_WIN32) || defined(__CYGWIN__)
  377. // This is a DLL platform.
  378. if(archive_destination)
  379. {
  380. // The import library uses the ARCHIVE properties.
  381. this->Makefile->AddInstallGenerator(
  382. new cmInstallTargetGenerator(target, archive_dest.c_str(), true,
  383. archive_permissions.c_str(),
  384. archive_configurations,
  385. archive_component.c_str()));
  386. }
  387. if(runtime_destination)
  388. {
  389. // The DLL uses the RUNTIME properties.
  390. this->Makefile->AddInstallGenerator(
  391. new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
  392. runtime_permissions.c_str(),
  393. runtime_configurations,
  394. runtime_component.c_str()));
  395. }
  396. #else
  397. // This is a non-DLL platform.
  398. if(library_destination)
  399. {
  400. // The shared library uses the LIBRARY properties.
  401. this->Makefile->AddInstallGenerator(
  402. new cmInstallTargetGenerator(target, library_dest.c_str(), false,
  403. library_permissions.c_str(),
  404. library_configurations,
  405. library_component.c_str()));
  406. }
  407. else
  408. {
  409. cmOStringStream e;
  410. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  411. "target \"" << target.GetName() << "\".";
  412. this->SetError(e.str().c_str());
  413. return false;
  414. }
  415. #endif
  416. }
  417. break;
  418. case cmTarget::STATIC_LIBRARY:
  419. {
  420. // Static libraries use ARCHIVE properties.
  421. if(archive_destination)
  422. {
  423. this->Makefile->AddInstallGenerator(
  424. new cmInstallTargetGenerator(target, archive_dest.c_str(), false,
  425. archive_permissions.c_str(),
  426. archive_configurations,
  427. archive_component.c_str()));
  428. }
  429. else
  430. {
  431. cmOStringStream e;
  432. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  433. "target \"" << target.GetName() << "\".";
  434. this->SetError(e.str().c_str());
  435. return false;
  436. }
  437. }
  438. break;
  439. case cmTarget::MODULE_LIBRARY:
  440. {
  441. // Modules use LIBRARY properties.
  442. if(library_destination)
  443. {
  444. this->Makefile->AddInstallGenerator(
  445. new cmInstallTargetGenerator(target, library_dest.c_str(), false,
  446. library_permissions.c_str(),
  447. library_configurations,
  448. library_component.c_str()));
  449. }
  450. else
  451. {
  452. cmOStringStream e;
  453. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  454. << target.GetName() << "\".";
  455. this->SetError(e.str().c_str());
  456. return false;
  457. }
  458. }
  459. break;
  460. case cmTarget::EXECUTABLE:
  461. {
  462. // Executables use the RUNTIME properties.
  463. if(runtime_destination)
  464. {
  465. this->Makefile->AddInstallGenerator(
  466. new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
  467. runtime_permissions.c_str(),
  468. runtime_configurations,
  469. runtime_component.c_str()));
  470. }
  471. else
  472. {
  473. cmOStringStream e;
  474. e << "TARGETS given no RUNTIME DESTINATION for executable target \""
  475. << target.GetName() << "\".";
  476. this->SetError(e.str().c_str());
  477. return false;
  478. }
  479. }
  480. break;
  481. default:
  482. // This should never happen due to the above type check.
  483. // Ignore the case.
  484. break;
  485. }
  486. }
  487. // Tell the global generator about any installation component names
  488. // specified.
  489. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  490. ->AddInstallComponent(archive_component.c_str());
  491. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  492. ->AddInstallComponent(library_component.c_str());
  493. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  494. ->AddInstallComponent(runtime_component.c_str());
  495. return true;
  496. }
  497. //----------------------------------------------------------------------------
  498. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  499. {
  500. // This is the FILES mode.
  501. bool programs = (args[0] == "PROGRAMS");
  502. bool doing_files = true;
  503. bool doing_destination = false;
  504. bool doing_permissions = false;
  505. bool doing_configurations = false;
  506. bool doing_component = false;
  507. bool doing_rename = false;
  508. std::vector<std::string> files;
  509. const char* destination = 0;
  510. std::string rename;
  511. std::string permissions;
  512. std::vector<std::string> configurations;
  513. std::string component;
  514. for(unsigned int i=1; i < args.size(); ++i)
  515. {
  516. if(args[i] == "DESTINATION")
  517. {
  518. // Switch to setting the destination property.
  519. doing_files = false;
  520. doing_destination = true;
  521. doing_permissions = false;
  522. doing_configurations = false;
  523. doing_component = false;
  524. doing_rename = false;
  525. }
  526. else if(args[i] == "PERMISSIONS")
  527. {
  528. // Switch to setting the permissions property.
  529. doing_files = false;
  530. doing_destination = false;
  531. doing_permissions = true;
  532. doing_configurations = false;
  533. doing_component = false;
  534. doing_rename = false;
  535. }
  536. else if(args[i] == "CONFIGURATIONS")
  537. {
  538. // Switch to setting the configurations property.
  539. doing_files = false;
  540. doing_destination = false;
  541. doing_permissions = false;
  542. doing_configurations = true;
  543. doing_component = false;
  544. doing_rename = false;
  545. }
  546. else if(args[i] == "COMPONENT")
  547. {
  548. // Switch to setting the component property.
  549. doing_files = false;
  550. doing_destination = false;
  551. doing_permissions = false;
  552. doing_configurations = false;
  553. doing_component = true;
  554. doing_rename = false;
  555. }
  556. else if(args[i] == "RENAME")
  557. {
  558. // Switch to setting the rename property.
  559. doing_files = false;
  560. doing_destination = false;
  561. doing_permissions = false;
  562. doing_configurations = false;
  563. doing_component = false;
  564. doing_rename = true;
  565. }
  566. else if(doing_files)
  567. {
  568. // Convert this file to a full path.
  569. std::string file = args[i];
  570. if(!cmSystemTools::FileIsFullPath(file.c_str()))
  571. {
  572. file = this->Makefile->GetCurrentDirectory();
  573. file += "/";
  574. file += args[i];
  575. }
  576. // Make sure the file is not a directory.
  577. if(cmSystemTools::FileIsDirectory(file.c_str()))
  578. {
  579. cmOStringStream e;
  580. e << args[0] << " given directory \"" << args[i] << "\" to install.";
  581. this->SetError(e.str().c_str());
  582. return false;
  583. }
  584. // Store the file for installation.
  585. files.push_back(file);
  586. }
  587. else if(doing_configurations)
  588. {
  589. configurations.push_back(args[i]);
  590. }
  591. else if(doing_destination)
  592. {
  593. destination = args[i].c_str();
  594. doing_destination = false;
  595. }
  596. else if(doing_component)
  597. {
  598. component = args[i];
  599. doing_component = false;
  600. }
  601. else if(doing_permissions)
  602. {
  603. // Check the requested permission.
  604. if(!this->CheckPermissions(args[i], permissions))
  605. {
  606. cmOStringStream e;
  607. e << args[0] << " given invalid permission \""
  608. << args[i] << "\".";
  609. this->SetError(e.str().c_str());
  610. return false;
  611. }
  612. }
  613. else if(doing_rename)
  614. {
  615. rename = args[i];
  616. doing_rename = false;
  617. }
  618. else
  619. {
  620. // Unknown argument.
  621. cmOStringStream e;
  622. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  623. this->SetError(e.str().c_str());
  624. return false;
  625. }
  626. }
  627. // Check if there is something to do.
  628. if(files.empty())
  629. {
  630. return true;
  631. }
  632. if(!destination)
  633. {
  634. // A destination is required.
  635. cmOStringStream e;
  636. e << args[0] << " given no DESTINATION!";
  637. this->SetError(e.str().c_str());
  638. return false;
  639. }
  640. if(!rename.empty() && files.size() > 1)
  641. {
  642. // The rename option works only with one file.
  643. cmOStringStream e;
  644. e << args[0] << " given RENAME option with more than one file.";
  645. this->SetError(e.str().c_str());
  646. return false;
  647. }
  648. // Compute destination path.
  649. std::string dest;
  650. this->ComputeDestination(destination, dest);
  651. // Create the files install generator.
  652. this->Makefile->AddInstallGenerator(
  653. new cmInstallFilesGenerator(files, dest.c_str(), programs,
  654. permissions.c_str(), configurations,
  655. component.c_str(), rename.c_str()));
  656. // Tell the global generator about any installation component names
  657. // specified.
  658. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  659. ->AddInstallComponent(component.c_str());
  660. return true;
  661. }
  662. //----------------------------------------------------------------------------
  663. bool
  664. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  665. {
  666. bool doing_dirs = true;
  667. bool doing_destination = false;
  668. bool doing_pattern = false;
  669. bool doing_regex = false;
  670. bool doing_permissions_file = false;
  671. bool doing_permissions_dir = false;
  672. bool doing_permissions_match = false;
  673. bool doing_configurations = false;
  674. bool doing_component = false;
  675. bool in_match_mode = false;
  676. std::vector<std::string> dirs;
  677. const char* destination = 0;
  678. std::string permissions_file;
  679. std::string permissions_dir;
  680. std::vector<std::string> configurations;
  681. std::string component;
  682. std::string literal_args;
  683. for(unsigned int i=1; i < args.size(); ++i)
  684. {
  685. if(args[i] == "DESTINATION")
  686. {
  687. if(in_match_mode)
  688. {
  689. cmOStringStream e;
  690. e << args[0] << " does not allow \""
  691. << args[i] << "\" after PATTERN or REGEX.";
  692. this->SetError(e.str().c_str());
  693. return false;
  694. }
  695. // Switch to setting the destination property.
  696. doing_dirs = false;
  697. doing_destination = true;
  698. doing_pattern = false;
  699. doing_regex = false;
  700. doing_permissions_file = false;
  701. doing_permissions_dir = false;
  702. doing_configurations = false;
  703. doing_component = false;
  704. }
  705. else if(args[i] == "PATTERN")
  706. {
  707. // Switch to a new pattern match rule.
  708. doing_dirs = false;
  709. doing_destination = false;
  710. doing_pattern = true;
  711. doing_regex = false;
  712. doing_permissions_file = false;
  713. doing_permissions_dir = false;
  714. doing_permissions_match = false;
  715. doing_configurations = false;
  716. doing_component = false;
  717. in_match_mode = true;
  718. }
  719. else if(args[i] == "REGEX")
  720. {
  721. // Switch to a new regex match rule.
  722. doing_dirs = false;
  723. doing_destination = false;
  724. doing_pattern = false;
  725. doing_regex = true;
  726. doing_permissions_file = false;
  727. doing_permissions_dir = false;
  728. doing_permissions_match = false;
  729. doing_configurations = false;
  730. doing_component = false;
  731. in_match_mode = true;
  732. }
  733. else if(args[i] == "EXCLUDE")
  734. {
  735. // Add this property to the current match rule.
  736. if(!in_match_mode || doing_pattern || doing_regex)
  737. {
  738. cmOStringStream e;
  739. e << args[0] << " does not allow \""
  740. << args[i] << "\" before a PATTERN or REGEX is given.";
  741. this->SetError(e.str().c_str());
  742. return false;
  743. }
  744. literal_args += " EXCLUDE";
  745. doing_permissions_match = false;
  746. }
  747. else if(args[i] == "PERMISSIONS")
  748. {
  749. if(!in_match_mode)
  750. {
  751. cmOStringStream e;
  752. e << args[0] << " does not allow \""
  753. << args[i] << "\" before a PATTERN or REGEX is given.";
  754. this->SetError(e.str().c_str());
  755. return false;
  756. }
  757. // Switch to setting the current match permissions property.
  758. literal_args += " PERMISSIONS";
  759. doing_permissions_match = true;
  760. }
  761. else if(args[i] == "FILE_PERMISSIONS")
  762. {
  763. if(in_match_mode)
  764. {
  765. cmOStringStream e;
  766. e << args[0] << " does not allow \""
  767. << args[i] << "\" after PATTERN or REGEX.";
  768. this->SetError(e.str().c_str());
  769. return false;
  770. }
  771. // Switch to setting the file permissions property.
  772. doing_dirs = false;
  773. doing_destination = false;
  774. doing_pattern = false;
  775. doing_regex = false;
  776. doing_permissions_file = true;
  777. doing_permissions_dir = false;
  778. doing_configurations = false;
  779. doing_component = false;
  780. }
  781. else if(args[i] == "DIRECTORY_PERMISSIONS")
  782. {
  783. if(in_match_mode)
  784. {
  785. cmOStringStream e;
  786. e << args[0] << " does not allow \""
  787. << args[i] << "\" after PATTERN or REGEX.";
  788. this->SetError(e.str().c_str());
  789. return false;
  790. }
  791. // Switch to setting the directory permissions property.
  792. doing_dirs = false;
  793. doing_destination = false;
  794. doing_pattern = false;
  795. doing_regex = false;
  796. doing_permissions_file = false;
  797. doing_permissions_dir = true;
  798. doing_configurations = false;
  799. doing_component = false;
  800. }
  801. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  802. {
  803. if(in_match_mode)
  804. {
  805. cmOStringStream e;
  806. e << args[0] << " does not allow \""
  807. << args[i] << "\" after PATTERN or REGEX.";
  808. this->SetError(e.str().c_str());
  809. return false;
  810. }
  811. // Add this option literally.
  812. doing_dirs = false;
  813. doing_destination = false;
  814. doing_pattern = false;
  815. doing_regex = false;
  816. doing_permissions_file = false;
  817. doing_permissions_dir = false;
  818. doing_configurations = false;
  819. doing_component = false;
  820. literal_args += " USE_SOURCE_PERMISSIONS";
  821. }
  822. else if(args[i] == "CONFIGURATIONS")
  823. {
  824. if(in_match_mode)
  825. {
  826. cmOStringStream e;
  827. e << args[0] << " does not allow \""
  828. << args[i] << "\" after PATTERN or REGEX.";
  829. this->SetError(e.str().c_str());
  830. return false;
  831. }
  832. // Switch to setting the configurations property.
  833. doing_dirs = false;
  834. doing_destination = false;
  835. doing_pattern = false;
  836. doing_regex = false;
  837. doing_permissions_file = false;
  838. doing_permissions_dir = false;
  839. doing_configurations = true;
  840. doing_component = false;
  841. }
  842. else if(args[i] == "COMPONENT")
  843. {
  844. if(in_match_mode)
  845. {
  846. cmOStringStream e;
  847. e << args[0] << " does not allow \""
  848. << args[i] << "\" after PATTERN or REGEX.";
  849. this->SetError(e.str().c_str());
  850. return false;
  851. }
  852. // Switch to setting the component property.
  853. doing_dirs = false;
  854. doing_destination = false;
  855. doing_pattern = false;
  856. doing_regex = false;
  857. doing_permissions_file = false;
  858. doing_permissions_dir = false;
  859. doing_configurations = false;
  860. doing_component = true;
  861. }
  862. else if(doing_dirs)
  863. {
  864. // Convert this directory to a full path.
  865. std::string dir = args[i];
  866. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  867. {
  868. dir = this->Makefile->GetCurrentDirectory();
  869. dir += "/";
  870. dir += args[i];
  871. }
  872. // Make sure the name is a directory.
  873. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  874. {
  875. cmOStringStream e;
  876. e << args[0] << " given non-directory \""
  877. << args[i] << "\" to install.";
  878. this->SetError(e.str().c_str());
  879. return false;
  880. }
  881. // Store the directory for installation.
  882. dirs.push_back(dir);
  883. }
  884. else if(doing_configurations)
  885. {
  886. configurations.push_back(args[i]);
  887. }
  888. else if(doing_destination)
  889. {
  890. destination = args[i].c_str();
  891. doing_destination = false;
  892. }
  893. else if(doing_pattern)
  894. {
  895. // Convert the pattern to a regular expression. Require a
  896. // leading slash and trailing end-of-string in the matched
  897. // string to make sure the pattern matches only whole file
  898. // names.
  899. literal_args += " REGEX \"/";
  900. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  901. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  902. literal_args += regex;
  903. literal_args += "$\"";
  904. doing_pattern = false;
  905. }
  906. else if(doing_regex)
  907. {
  908. literal_args += " REGEX \"";
  909. // Match rules are case-insensitive on some platforms.
  910. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  911. std::string regex = cmSystemTools::LowerCase(args[i]);
  912. #else
  913. std::string regex = args[i];
  914. #endif
  915. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  916. literal_args += regex;
  917. literal_args += "\"";
  918. doing_regex = false;
  919. }
  920. else if(doing_component)
  921. {
  922. component = args[i];
  923. doing_component = false;
  924. }
  925. else if(doing_permissions_file)
  926. {
  927. // Check the requested permission.
  928. if(!this->CheckPermissions(args[i], permissions_file))
  929. {
  930. cmOStringStream e;
  931. e << args[0] << " given invalid file permission \""
  932. << args[i] << "\".";
  933. this->SetError(e.str().c_str());
  934. return false;
  935. }
  936. }
  937. else if(doing_permissions_dir)
  938. {
  939. // Check the requested permission.
  940. if(!this->CheckPermissions(args[i], permissions_dir))
  941. {
  942. cmOStringStream e;
  943. e << args[0] << " given invalid directory permission \""
  944. << args[i] << "\".";
  945. this->SetError(e.str().c_str());
  946. return false;
  947. }
  948. }
  949. else if(doing_permissions_match)
  950. {
  951. // Check the requested permission.
  952. if(!this->CheckPermissions(args[i], literal_args))
  953. {
  954. cmOStringStream e;
  955. e << args[0] << " given invalid permission \""
  956. << args[i] << "\".";
  957. this->SetError(e.str().c_str());
  958. return false;
  959. }
  960. }
  961. else
  962. {
  963. // Unknown argument.
  964. cmOStringStream e;
  965. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  966. this->SetError(e.str().c_str());
  967. return false;
  968. }
  969. }
  970. // Support installing an empty directory.
  971. if(dirs.empty() && destination)
  972. {
  973. dirs.push_back("");
  974. }
  975. // Check if there is something to do.
  976. if(dirs.empty())
  977. {
  978. return true;
  979. }
  980. if(!destination)
  981. {
  982. // A destination is required.
  983. cmOStringStream e;
  984. e << args[0] << " given no DESTINATION!";
  985. this->SetError(e.str().c_str());
  986. return false;
  987. }
  988. // Compute destination path.
  989. std::string dest;
  990. this->ComputeDestination(destination, dest);
  991. // Create the directory install generator.
  992. this->Makefile->AddInstallGenerator(
  993. new cmInstallDirectoryGenerator(dirs, dest.c_str(),
  994. permissions_file.c_str(),
  995. permissions_dir.c_str(),
  996. configurations,
  997. component.c_str(),
  998. literal_args.c_str()));
  999. // Tell the global generator about any installation component names
  1000. // specified.
  1001. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  1002. ->AddInstallComponent(component.c_str());
  1003. return true;
  1004. }
  1005. //----------------------------------------------------------------------------
  1006. void cmInstallCommand::ComputeDestination(const char* destination,
  1007. std::string& dest)
  1008. {
  1009. if(destination)
  1010. {
  1011. if(cmSystemTools::FileIsFullPath(destination))
  1012. {
  1013. // Full paths are absolute.
  1014. dest = destination;
  1015. }
  1016. else
  1017. {
  1018. // Relative paths are treated with respect to the installation prefix.
  1019. dest = "${CMAKE_INSTALL_PREFIX}/";
  1020. dest += destination;
  1021. }
  1022. // Format the path nicely. Note this also removes trailing
  1023. // slashes.
  1024. cmSystemTools::ConvertToUnixSlashes(dest);
  1025. }
  1026. else
  1027. {
  1028. dest = "";
  1029. }
  1030. }
  1031. //----------------------------------------------------------------------------
  1032. bool cmInstallCommand::CheckPermissions(std::string const& arg,
  1033. std::string& permissions)
  1034. {
  1035. // Table of valid permissions.
  1036. const char* table[] =
  1037. {
  1038. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
  1039. "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
  1040. "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
  1041. "SETUID", "SETGID", 0
  1042. };
  1043. // Check the permission against the table.
  1044. for(const char** valid = table; *valid; ++valid)
  1045. {
  1046. if(arg == *valid)
  1047. {
  1048. // This is a valid permission.
  1049. permissions += " ";
  1050. permissions += arg;
  1051. return true;
  1052. }
  1053. }
  1054. // This is not a valid permission.
  1055. return false;
  1056. }