cmInstallCommand.cxx 32 KB

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