cmInstallCommand.cxx 37 KB

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