cmInstallCommand.cxx 38 KB

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