cmInstallCommand.cxx 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallCommand.h"
  11. #include "cmInstallDirectoryGenerator.h"
  12. #include "cmInstallFilesGenerator.h"
  13. #include "cmInstallScriptGenerator.h"
  14. #include "cmInstallTargetGenerator.h"
  15. #include "cmInstallExportGenerator.h"
  16. #include "cmInstallCommandArguments.h"
  17. #include "cmTargetExport.h"
  18. #include "cmExportSet.h"
  19. #include <cmsys/Glob.hxx>
  20. static cmInstallTargetGenerator* CreateInstallTargetGenerator(cmTarget& target,
  21. const cmInstallCommandArguments& args, bool impLib, bool forceOpt = false)
  22. {
  23. cmInstallGenerator::MessageLevel message =
  24. cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
  25. return new cmInstallTargetGenerator(target.GetName(),
  26. args.GetDestination().c_str(),
  27. impLib, args.GetPermissions().c_str(),
  28. args.GetConfigurations(), args.GetComponent().c_str(),
  29. message,
  30. args.GetOptional() || forceOpt);
  31. }
  32. static cmInstallFilesGenerator* CreateInstallFilesGenerator(
  33. cmMakefile* mf,
  34. const std::vector<std::string>& absFiles,
  35. const cmInstallCommandArguments& args, bool programs)
  36. {
  37. cmInstallGenerator::MessageLevel message =
  38. cmInstallGenerator::SelectMessageLevel(mf);
  39. return new cmInstallFilesGenerator(
  40. absFiles, args.GetDestination().c_str(),
  41. programs, args.GetPermissions().c_str(),
  42. args.GetConfigurations(), args.GetComponent().c_str(),
  43. message,
  44. args.GetRename().c_str(), args.GetOptional());
  45. }
  46. // cmInstallCommand
  47. bool cmInstallCommand::InitialPass(std::vector<std::string> const& args,
  48. cmExecutionStatus &)
  49. {
  50. // Allow calling with no arguments so that arguments may be built up
  51. // using a variable that may be left empty.
  52. if(args.empty())
  53. {
  54. return true;
  55. }
  56. // Enable the install target.
  57. this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
  58. this->DefaultComponentName = this->Makefile->GetSafeDefinition(
  59. "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
  60. if (this->DefaultComponentName.empty())
  61. {
  62. this->DefaultComponentName = "Unspecified";
  63. }
  64. // Switch among the command modes.
  65. if(args[0] == "SCRIPT")
  66. {
  67. return this->HandleScriptMode(args);
  68. }
  69. else if(args[0] == "CODE")
  70. {
  71. return this->HandleScriptMode(args);
  72. }
  73. else if(args[0] == "TARGETS")
  74. {
  75. return this->HandleTargetsMode(args);
  76. }
  77. else if(args[0] == "FILES")
  78. {
  79. return this->HandleFilesMode(args);
  80. }
  81. else if(args[0] == "PROGRAMS")
  82. {
  83. return this->HandleFilesMode(args);
  84. }
  85. else if(args[0] == "DIRECTORY")
  86. {
  87. return this->HandleDirectoryMode(args);
  88. }
  89. else if(args[0] == "EXPORT")
  90. {
  91. return this->HandleExportMode(args);
  92. }
  93. // Unknown mode.
  94. std::string e = "called with unknown mode ";
  95. e += args[0];
  96. this->SetError(e);
  97. return false;
  98. }
  99. //----------------------------------------------------------------------------
  100. bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
  101. {
  102. std::string component = this->DefaultComponentName;
  103. int componentCount = 0;
  104. bool doing_script = false;
  105. bool doing_code = false;
  106. // Scan the args once for COMPONENT. Only allow one.
  107. //
  108. for(size_t i=0; i < args.size(); ++i)
  109. {
  110. if(args[i] == "COMPONENT" && i+1 < args.size())
  111. {
  112. ++componentCount;
  113. ++i;
  114. component = args[i];
  115. }
  116. }
  117. if(componentCount>1)
  118. {
  119. this->SetError("given more than one COMPONENT for the SCRIPT or CODE "
  120. "signature of the INSTALL command. "
  121. "Use multiple INSTALL commands with one COMPONENT each.");
  122. return false;
  123. }
  124. // Scan the args again, this time adding install generators each time we
  125. // encounter a SCRIPT or CODE arg:
  126. //
  127. for(size_t i=0; i < args.size(); ++i)
  128. {
  129. if(args[i] == "SCRIPT")
  130. {
  131. doing_script = true;
  132. doing_code = false;
  133. }
  134. else if(args[i] == "CODE")
  135. {
  136. doing_script = false;
  137. doing_code = true;
  138. }
  139. else if(args[i] == "COMPONENT")
  140. {
  141. doing_script = false;
  142. doing_code = false;
  143. }
  144. else if(doing_script)
  145. {
  146. doing_script = false;
  147. std::string script = args[i];
  148. if(!cmSystemTools::FileIsFullPath(script.c_str()))
  149. {
  150. script = this->Makefile->GetCurrentSourceDirectory();
  151. script += "/";
  152. script += args[i];
  153. }
  154. if(cmSystemTools::FileIsDirectory(script))
  155. {
  156. this->SetError("given a directory as value of SCRIPT argument.");
  157. return false;
  158. }
  159. this->Makefile->AddInstallGenerator(
  160. new cmInstallScriptGenerator(script.c_str(), false,
  161. component.c_str()));
  162. }
  163. else if(doing_code)
  164. {
  165. doing_code = false;
  166. std::string code = args[i];
  167. this->Makefile->AddInstallGenerator(
  168. new cmInstallScriptGenerator(code.c_str(), true,
  169. component.c_str()));
  170. }
  171. }
  172. if(doing_script)
  173. {
  174. this->SetError("given no value for SCRIPT argument.");
  175. return false;
  176. }
  177. if(doing_code)
  178. {
  179. this->SetError("given no value for CODE argument.");
  180. return false;
  181. }
  182. //Tell the global generator about any installation component names specified.
  183. this->Makefile->GetGlobalGenerator()
  184. ->AddInstallComponent(component.c_str());
  185. return true;
  186. }
  187. /*struct InstallPart
  188. {
  189. InstallPart(cmCommandArgumentsHelper* helper, const char* key,
  190. cmCommandArgumentGroup* group);
  191. cmCAStringVector argVector;
  192. cmInstallCommandArguments args;
  193. };*/
  194. //----------------------------------------------------------------------------
  195. bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
  196. {
  197. // This is the TARGETS mode.
  198. std::vector<cmTarget*> targets;
  199. cmCommandArgumentsHelper argHelper;
  200. cmCommandArgumentGroup group;
  201. cmCAStringVector genericArgVector (&argHelper,0);
  202. cmCAStringVector archiveArgVector (&argHelper,"ARCHIVE",&group);
  203. cmCAStringVector libraryArgVector (&argHelper,"LIBRARY",&group);
  204. cmCAStringVector runtimeArgVector (&argHelper,"RUNTIME",&group);
  205. cmCAStringVector frameworkArgVector (&argHelper,"FRAMEWORK",&group);
  206. cmCAStringVector bundleArgVector (&argHelper,"BUNDLE",&group);
  207. cmCAStringVector includesArgVector (&argHelper,"INCLUDES",&group);
  208. cmCAStringVector privateHeaderArgVector(&argHelper,"PRIVATE_HEADER",&group);
  209. cmCAStringVector publicHeaderArgVector (&argHelper,"PUBLIC_HEADER",&group);
  210. cmCAStringVector resourceArgVector (&argHelper,"RESOURCE",&group);
  211. genericArgVector.Follows(0);
  212. group.Follows(&genericArgVector);
  213. argHelper.Parse(&args, 0);
  214. // now parse the generic args (i.e. the ones not specialized on LIBRARY/
  215. // ARCHIVE, RUNTIME etc. (see above)
  216. // These generic args also contain the targets and the export stuff
  217. std::vector<std::string> unknownArgs;
  218. cmInstallCommandArguments genericArgs(this->DefaultComponentName);
  219. cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
  220. cmCAString exports(&genericArgs.Parser,"EXPORT", &genericArgs.ArgumentGroup);
  221. targetList.Follows(0);
  222. genericArgs.ArgumentGroup.Follows(&targetList);
  223. genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
  224. bool success = genericArgs.Finalize();
  225. cmInstallCommandArguments archiveArgs(this->DefaultComponentName);
  226. cmInstallCommandArguments libraryArgs(this->DefaultComponentName);
  227. cmInstallCommandArguments runtimeArgs(this->DefaultComponentName);
  228. cmInstallCommandArguments frameworkArgs(this->DefaultComponentName);
  229. cmInstallCommandArguments bundleArgs(this->DefaultComponentName);
  230. cmInstallCommandArguments privateHeaderArgs(this->DefaultComponentName);
  231. cmInstallCommandArguments publicHeaderArgs(this->DefaultComponentName);
  232. cmInstallCommandArguments resourceArgs(this->DefaultComponentName);
  233. cmInstallCommandIncludesArgument includesArgs;
  234. // now parse the args for specific parts of the target (e.g. LIBRARY,
  235. // RUNTIME, ARCHIVE etc.
  236. archiveArgs.Parse (&archiveArgVector.GetVector(), &unknownArgs);
  237. libraryArgs.Parse (&libraryArgVector.GetVector(), &unknownArgs);
  238. runtimeArgs.Parse (&runtimeArgVector.GetVector(), &unknownArgs);
  239. frameworkArgs.Parse (&frameworkArgVector.GetVector(), &unknownArgs);
  240. bundleArgs.Parse (&bundleArgVector.GetVector(), &unknownArgs);
  241. privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
  242. publicHeaderArgs.Parse (&publicHeaderArgVector.GetVector(), &unknownArgs);
  243. resourceArgs.Parse (&resourceArgVector.GetVector(), &unknownArgs);
  244. includesArgs.Parse (&includesArgVector.GetVector(), &unknownArgs);
  245. if(!unknownArgs.empty())
  246. {
  247. // Unknown argument.
  248. std::ostringstream e;
  249. e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
  250. this->SetError(e.str());
  251. return false;
  252. }
  253. // apply generic args
  254. archiveArgs.SetGenericArguments(&genericArgs);
  255. libraryArgs.SetGenericArguments(&genericArgs);
  256. runtimeArgs.SetGenericArguments(&genericArgs);
  257. frameworkArgs.SetGenericArguments(&genericArgs);
  258. bundleArgs.SetGenericArguments(&genericArgs);
  259. privateHeaderArgs.SetGenericArguments(&genericArgs);
  260. publicHeaderArgs.SetGenericArguments(&genericArgs);
  261. resourceArgs.SetGenericArguments(&genericArgs);
  262. success = success && archiveArgs.Finalize();
  263. success = success && libraryArgs.Finalize();
  264. success = success && runtimeArgs.Finalize();
  265. success = success && frameworkArgs.Finalize();
  266. success = success && bundleArgs.Finalize();
  267. success = success && privateHeaderArgs.Finalize();
  268. success = success && publicHeaderArgs.Finalize();
  269. success = success && resourceArgs.Finalize();
  270. if(!success)
  271. {
  272. return false;
  273. }
  274. // Enforce argument rules too complex to specify for the
  275. // general-purpose parser.
  276. if(archiveArgs.GetNamelinkOnly() ||
  277. runtimeArgs.GetNamelinkOnly() ||
  278. frameworkArgs.GetNamelinkOnly() ||
  279. bundleArgs.GetNamelinkOnly() ||
  280. privateHeaderArgs.GetNamelinkOnly() ||
  281. publicHeaderArgs.GetNamelinkOnly() ||
  282. resourceArgs.GetNamelinkOnly())
  283. {
  284. this->SetError(
  285. "TARGETS given NAMELINK_ONLY option not in LIBRARY group. "
  286. "The NAMELINK_ONLY option may be specified only following LIBRARY."
  287. );
  288. return false;
  289. }
  290. if(archiveArgs.GetNamelinkSkip() ||
  291. runtimeArgs.GetNamelinkSkip() ||
  292. frameworkArgs.GetNamelinkSkip() ||
  293. bundleArgs.GetNamelinkSkip() ||
  294. privateHeaderArgs.GetNamelinkSkip() ||
  295. publicHeaderArgs.GetNamelinkSkip() ||
  296. resourceArgs.GetNamelinkSkip())
  297. {
  298. this->SetError(
  299. "TARGETS given NAMELINK_SKIP option not in LIBRARY group. "
  300. "The NAMELINK_SKIP option may be specified only following LIBRARY."
  301. );
  302. return false;
  303. }
  304. if(libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip())
  305. {
  306. this->SetError(
  307. "TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. "
  308. "At most one of these two options may be specified."
  309. );
  310. return false;
  311. }
  312. // Select the mode for installing symlinks to versioned shared libraries.
  313. cmInstallTargetGenerator::NamelinkModeType
  314. namelinkMode = cmInstallTargetGenerator::NamelinkModeNone;
  315. if(libraryArgs.GetNamelinkOnly())
  316. {
  317. namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
  318. }
  319. else if(libraryArgs.GetNamelinkSkip())
  320. {
  321. namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
  322. }
  323. // Check if there is something to do.
  324. if(targetList.GetVector().empty())
  325. {
  326. return true;
  327. }
  328. // Check whether this is a DLL platform.
  329. bool dll_platform = (this->Makefile->IsOn("WIN32") ||
  330. this->Makefile->IsOn("CYGWIN") ||
  331. this->Makefile->IsOn("MINGW"));
  332. for(std::vector<std::string>::const_iterator
  333. targetIt=targetList.GetVector().begin();
  334. targetIt!=targetList.GetVector().end();
  335. ++targetIt)
  336. {
  337. if (this->Makefile->IsAlias(*targetIt))
  338. {
  339. std::ostringstream e;
  340. e << "TARGETS given target \"" << (*targetIt)
  341. << "\" which is an alias.";
  342. this->SetError(e.str());
  343. return false;
  344. }
  345. // Lookup this target in the current directory.
  346. if(cmTarget* target=this->Makefile->FindTarget(*targetIt))
  347. {
  348. // Found the target. Check its type.
  349. if(target->GetType() != cmState::EXECUTABLE &&
  350. target->GetType() != cmState::STATIC_LIBRARY &&
  351. target->GetType() != cmState::SHARED_LIBRARY &&
  352. target->GetType() != cmState::MODULE_LIBRARY &&
  353. target->GetType() != cmState::OBJECT_LIBRARY &&
  354. target->GetType() != cmState::INTERFACE_LIBRARY)
  355. {
  356. std::ostringstream e;
  357. e << "TARGETS given target \"" << (*targetIt)
  358. << "\" which is not an executable, library, or module.";
  359. this->SetError(e.str());
  360. return false;
  361. }
  362. else if(target->GetType() == cmState::OBJECT_LIBRARY)
  363. {
  364. std::ostringstream e;
  365. e << "TARGETS given OBJECT library \"" << (*targetIt)
  366. << "\" which may not be installed.";
  367. this->SetError(e.str());
  368. return false;
  369. }
  370. // Store the target in the list to be installed.
  371. targets.push_back(target);
  372. }
  373. else
  374. {
  375. // Did not find the target.
  376. std::ostringstream e;
  377. e << "TARGETS given target \"" << (*targetIt)
  378. << "\" which does not exist in this directory.";
  379. this->SetError(e.str());
  380. return false;
  381. }
  382. }
  383. // Keep track of whether we will be performing an installation of
  384. // any files of the given type.
  385. bool installsArchive = false;
  386. bool installsLibrary = false;
  387. bool installsRuntime = false;
  388. bool installsFramework = false;
  389. bool installsBundle = false;
  390. bool installsPrivateHeader = false;
  391. bool installsPublicHeader = false;
  392. bool installsResource = false;
  393. // Generate install script code to install the given targets.
  394. for(std::vector<cmTarget*>::iterator ti = targets.begin();
  395. ti != targets.end(); ++ti)
  396. {
  397. // Handle each target type.
  398. cmTarget& target = *(*ti);
  399. cmInstallTargetGenerator* archiveGenerator = 0;
  400. cmInstallTargetGenerator* libraryGenerator = 0;
  401. cmInstallTargetGenerator* runtimeGenerator = 0;
  402. cmInstallTargetGenerator* frameworkGenerator = 0;
  403. cmInstallTargetGenerator* bundleGenerator = 0;
  404. cmInstallFilesGenerator* privateHeaderGenerator = 0;
  405. cmInstallFilesGenerator* publicHeaderGenerator = 0;
  406. cmInstallFilesGenerator* resourceGenerator = 0;
  407. // Track whether this is a namelink-only rule.
  408. bool namelinkOnly = false;
  409. switch(target.GetType())
  410. {
  411. case cmState::SHARED_LIBRARY:
  412. {
  413. // Shared libraries are handled differently on DLL and non-DLL
  414. // platforms. All windows platforms are DLL platforms including
  415. // cygwin. Currently no other platform is a DLL platform.
  416. if(dll_platform)
  417. {
  418. // When in namelink only mode skip all libraries on Windows.
  419. if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
  420. {
  421. continue;
  422. }
  423. // This is a DLL platform.
  424. if(!archiveArgs.GetDestination().empty())
  425. {
  426. // The import library uses the ARCHIVE properties.
  427. archiveGenerator = CreateInstallTargetGenerator(target,
  428. archiveArgs, true);
  429. }
  430. if(!runtimeArgs.GetDestination().empty())
  431. {
  432. // The DLL uses the RUNTIME properties.
  433. runtimeGenerator = CreateInstallTargetGenerator(target,
  434. runtimeArgs, false);
  435. }
  436. if ((archiveGenerator==0) && (runtimeGenerator==0))
  437. {
  438. this->SetError("Library TARGETS given no DESTINATION!");
  439. return false;
  440. }
  441. }
  442. else
  443. {
  444. // This is a non-DLL platform.
  445. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  446. // INSTALL properties. Otherwise, use the LIBRARY properties.
  447. if(target.IsFrameworkOnApple())
  448. {
  449. // When in namelink only mode skip frameworks.
  450. if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
  451. {
  452. continue;
  453. }
  454. // Use the FRAMEWORK properties.
  455. if (!frameworkArgs.GetDestination().empty())
  456. {
  457. frameworkGenerator = CreateInstallTargetGenerator(target,
  458. frameworkArgs, false);
  459. }
  460. else
  461. {
  462. std::ostringstream e;
  463. e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
  464. "FRAMEWORK target \"" << target.GetName() << "\".";
  465. this->SetError(e.str());
  466. return false;
  467. }
  468. }
  469. else
  470. {
  471. // The shared library uses the LIBRARY properties.
  472. if (!libraryArgs.GetDestination().empty())
  473. {
  474. libraryGenerator = CreateInstallTargetGenerator(target,
  475. libraryArgs, false);
  476. libraryGenerator->SetNamelinkMode(namelinkMode);
  477. namelinkOnly =
  478. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  479. }
  480. else
  481. {
  482. std::ostringstream e;
  483. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  484. "target \"" << target.GetName() << "\".";
  485. this->SetError(e.str());
  486. return false;
  487. }
  488. }
  489. }
  490. }
  491. break;
  492. case cmState::STATIC_LIBRARY:
  493. {
  494. // Static libraries use ARCHIVE properties.
  495. if (!archiveArgs.GetDestination().empty())
  496. {
  497. archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
  498. false);
  499. }
  500. else
  501. {
  502. std::ostringstream e;
  503. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  504. "target \"" << target.GetName() << "\".";
  505. this->SetError(e.str());
  506. return false;
  507. }
  508. }
  509. break;
  510. case cmState::MODULE_LIBRARY:
  511. {
  512. // Modules use LIBRARY properties.
  513. if (!libraryArgs.GetDestination().empty())
  514. {
  515. libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
  516. false);
  517. libraryGenerator->SetNamelinkMode(namelinkMode);
  518. namelinkOnly =
  519. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  520. }
  521. else
  522. {
  523. std::ostringstream e;
  524. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  525. << target.GetName() << "\".";
  526. this->SetError(e.str());
  527. return false;
  528. }
  529. }
  530. break;
  531. case cmState::EXECUTABLE:
  532. {
  533. if(target.IsAppBundleOnApple())
  534. {
  535. // Application bundles use the BUNDLE properties.
  536. if (!bundleArgs.GetDestination().empty())
  537. {
  538. bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
  539. false);
  540. }
  541. else if(!runtimeArgs.GetDestination().empty())
  542. {
  543. bool failure = false;
  544. if(this->CheckCMP0006(failure))
  545. {
  546. // For CMake 2.4 compatibility fallback to the RUNTIME
  547. // properties.
  548. bundleGenerator =
  549. CreateInstallTargetGenerator(target, runtimeArgs, false);
  550. }
  551. else if(failure)
  552. {
  553. return false;
  554. }
  555. }
  556. if(!bundleGenerator)
  557. {
  558. std::ostringstream e;
  559. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  560. "executable target \"" << target.GetName() << "\".";
  561. this->SetError(e.str());
  562. return false;
  563. }
  564. }
  565. else
  566. {
  567. // Executables use the RUNTIME properties.
  568. if (!runtimeArgs.GetDestination().empty())
  569. {
  570. runtimeGenerator = CreateInstallTargetGenerator(target,
  571. runtimeArgs, false);
  572. }
  573. else
  574. {
  575. std::ostringstream e;
  576. e << "TARGETS given no RUNTIME DESTINATION for executable "
  577. "target \"" << target.GetName() << "\".";
  578. this->SetError(e.str());
  579. return false;
  580. }
  581. }
  582. // On DLL platforms an executable may also have an import
  583. // library. Install it to the archive destination if it
  584. // exists.
  585. if(dll_platform && !archiveArgs.GetDestination().empty() &&
  586. target.IsExecutableWithExports())
  587. {
  588. // The import library uses the ARCHIVE properties.
  589. archiveGenerator = CreateInstallTargetGenerator(target,
  590. archiveArgs, true, true);
  591. }
  592. }
  593. break;
  594. case cmState::INTERFACE_LIBRARY:
  595. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  596. // only effect of that is to make it exportable. It installs no
  597. // other files itself.
  598. break;
  599. default:
  600. // This should never happen due to the above type check.
  601. // Ignore the case.
  602. break;
  603. }
  604. // These well-known sets of files are installed *automatically* for
  605. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  606. // FRAMEWORK. For other target types or on other platforms, they are not
  607. // installed automatically and so we need to create install files
  608. // generators for them.
  609. bool createInstallGeneratorsForTargetFileSets = true;
  610. if(target.IsFrameworkOnApple()
  611. || target.GetType() == cmState::INTERFACE_LIBRARY)
  612. {
  613. createInstallGeneratorsForTargetFileSets = false;
  614. }
  615. if(createInstallGeneratorsForTargetFileSets && !namelinkOnly)
  616. {
  617. const char* files = target.GetProperty("PRIVATE_HEADER");
  618. if ((files) && (*files))
  619. {
  620. std::vector<std::string> relFiles;
  621. cmSystemTools::ExpandListArgument(files, relFiles);
  622. std::vector<std::string> absFiles;
  623. if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles))
  624. {
  625. return false;
  626. }
  627. // Create the files install generator.
  628. if (!privateHeaderArgs.GetDestination().empty())
  629. {
  630. privateHeaderGenerator =
  631. CreateInstallFilesGenerator(this->Makefile, absFiles,
  632. privateHeaderArgs, false);
  633. }
  634. else
  635. {
  636. std::ostringstream e;
  637. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  638. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  639. cmSystemTools::Message(e.str().c_str(), "Warning");
  640. }
  641. }
  642. files = target.GetProperty("PUBLIC_HEADER");
  643. if ((files) && (*files))
  644. {
  645. std::vector<std::string> relFiles;
  646. cmSystemTools::ExpandListArgument(files, relFiles);
  647. std::vector<std::string> absFiles;
  648. if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles))
  649. {
  650. return false;
  651. }
  652. // Create the files install generator.
  653. if (!publicHeaderArgs.GetDestination().empty())
  654. {
  655. publicHeaderGenerator =
  656. CreateInstallFilesGenerator(this->Makefile, absFiles,
  657. publicHeaderArgs, false);
  658. }
  659. else
  660. {
  661. std::ostringstream e;
  662. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  663. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  664. cmSystemTools::Message(e.str().c_str(), "Warning");
  665. }
  666. }
  667. files = target.GetProperty("RESOURCE");
  668. if ((files) && (*files))
  669. {
  670. std::vector<std::string> relFiles;
  671. cmSystemTools::ExpandListArgument(files, relFiles);
  672. std::vector<std::string> absFiles;
  673. if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles))
  674. {
  675. return false;
  676. }
  677. // Create the files install generator.
  678. if (!resourceArgs.GetDestination().empty())
  679. {
  680. resourceGenerator = CreateInstallFilesGenerator(
  681. this->Makefile, absFiles, resourceArgs, false);
  682. }
  683. else
  684. {
  685. std::ostringstream e;
  686. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  687. << "RESOURCE files but no RESOURCE DESTINATION.";
  688. cmSystemTools::Message(e.str().c_str(), "Warning");
  689. }
  690. }
  691. }
  692. // Keep track of whether we're installing anything in each category
  693. installsArchive = installsArchive || archiveGenerator != 0;
  694. installsLibrary = installsLibrary || libraryGenerator != 0;
  695. installsRuntime = installsRuntime || runtimeGenerator != 0;
  696. installsFramework = installsFramework || frameworkGenerator != 0;
  697. installsBundle = installsBundle || bundleGenerator != 0;
  698. installsPrivateHeader = installsPrivateHeader
  699. || privateHeaderGenerator != 0;
  700. installsPublicHeader = installsPublicHeader || publicHeaderGenerator != 0;
  701. installsResource = installsResource || resourceGenerator;
  702. if (installsArchive || installsRuntime || installsFramework
  703. || installsLibrary || installsBundle)
  704. {
  705. target.SetHaveInstallRule(true);
  706. }
  707. this->Makefile->AddInstallGenerator(archiveGenerator);
  708. this->Makefile->AddInstallGenerator(libraryGenerator);
  709. this->Makefile->AddInstallGenerator(runtimeGenerator);
  710. this->Makefile->AddInstallGenerator(frameworkGenerator);
  711. this->Makefile->AddInstallGenerator(bundleGenerator);
  712. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  713. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  714. this->Makefile->AddInstallGenerator(resourceGenerator);
  715. // Add this install rule to an export if one was specified and
  716. // this is not a namelink-only rule.
  717. if(!exports.GetString().empty() && !namelinkOnly)
  718. {
  719. cmTargetExport *te = new cmTargetExport;
  720. te->TargetName = target.GetName();
  721. te->ArchiveGenerator = archiveGenerator;
  722. te->BundleGenerator = bundleGenerator;
  723. te->FrameworkGenerator = frameworkGenerator;
  724. te->HeaderGenerator = publicHeaderGenerator;
  725. te->LibraryGenerator = libraryGenerator;
  726. te->RuntimeGenerator = runtimeGenerator;
  727. this->Makefile->GetGlobalGenerator()
  728. ->GetExportSets()[exports.GetString()]->AddTargetExport(te);
  729. te->InterfaceIncludeDirectories =
  730. cmJoin(includesArgs.GetIncludeDirs(), ";");
  731. }
  732. }
  733. // Tell the global generator about any installation component names
  734. // specified
  735. if (installsArchive)
  736. {
  737. this->Makefile->GetGlobalGenerator()
  738. ->AddInstallComponent(archiveArgs.GetComponent().c_str());
  739. }
  740. if (installsLibrary)
  741. {
  742. this->Makefile->GetGlobalGenerator()
  743. ->AddInstallComponent(libraryArgs.GetComponent().c_str());
  744. }
  745. if (installsRuntime)
  746. {
  747. this->Makefile->GetGlobalGenerator()
  748. ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
  749. }
  750. if (installsFramework)
  751. {
  752. this->Makefile->GetGlobalGenerator()
  753. ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
  754. }
  755. if (installsBundle)
  756. {
  757. this->Makefile->GetGlobalGenerator()
  758. ->AddInstallComponent(bundleArgs.GetComponent().c_str());
  759. }
  760. if (installsPrivateHeader)
  761. {
  762. this->Makefile->GetGlobalGenerator()
  763. ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
  764. }
  765. if (installsPublicHeader)
  766. {
  767. this->Makefile->GetGlobalGenerator()
  768. ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
  769. }
  770. if (installsResource)
  771. {
  772. this->Makefile->GetGlobalGenerator()
  773. ->AddInstallComponent(resourceArgs.GetComponent().c_str());
  774. }
  775. return true;
  776. }
  777. //----------------------------------------------------------------------------
  778. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  779. {
  780. // This is the FILES mode.
  781. bool programs = (args[0] == "PROGRAMS");
  782. cmInstallCommandArguments ica(this->DefaultComponentName);
  783. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  784. files.Follows(0);
  785. ica.ArgumentGroup.Follows(&files);
  786. std::vector<std::string> unknownArgs;
  787. ica.Parse(&args, &unknownArgs);
  788. if(!unknownArgs.empty())
  789. {
  790. // Unknown argument.
  791. std::ostringstream e;
  792. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  793. this->SetError(e.str());
  794. return false;
  795. }
  796. const std::vector<std::string>& filesVector = files.GetVector();
  797. // Check if there is something to do.
  798. if(filesVector.empty())
  799. {
  800. return true;
  801. }
  802. if(!ica.GetRename().empty() && filesVector.size() > 1)
  803. {
  804. // The rename option works only with one file.
  805. std::ostringstream e;
  806. e << args[0] << " given RENAME option with more than one file.";
  807. this->SetError(e.str());
  808. return false;
  809. }
  810. std::vector<std::string> absFiles;
  811. if (!this->MakeFilesFullPath(args[0].c_str(), filesVector, absFiles))
  812. {
  813. return false;
  814. }
  815. cmPolicies::PolicyStatus status =
  816. this->Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  817. cmGlobalGenerator *gg = this->Makefile->GetGlobalGenerator();
  818. for(std::vector<std::string>::const_iterator fileIt = filesVector.begin();
  819. fileIt != filesVector.end(); ++fileIt)
  820. {
  821. if (gg->IsExportedTargetsFile(*fileIt))
  822. {
  823. const char *modal = 0;
  824. std::ostringstream e;
  825. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  826. switch(status)
  827. {
  828. case cmPolicies::WARN:
  829. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  830. modal = "should";
  831. case cmPolicies::OLD:
  832. break;
  833. case cmPolicies::REQUIRED_IF_USED:
  834. case cmPolicies::REQUIRED_ALWAYS:
  835. case cmPolicies::NEW:
  836. modal = "may";
  837. messageType = cmake::FATAL_ERROR;
  838. }
  839. if (modal)
  840. {
  841. e << "The file\n " << *fileIt << "\nwas generated by the export() "
  842. "command. It " << modal << " not be installed with the "
  843. "install() command. Use the install(EXPORT) mechanism "
  844. "instead. See the cmake-packages(7) manual for more.\n";
  845. this->Makefile->IssueMessage(messageType, e.str());
  846. if (messageType == cmake::FATAL_ERROR)
  847. {
  848. return false;
  849. }
  850. }
  851. }
  852. }
  853. if (!ica.Finalize())
  854. {
  855. return false;
  856. }
  857. if(ica.GetDestination().empty())
  858. {
  859. // A destination is required.
  860. std::ostringstream e;
  861. e << args[0] << " given no DESTINATION!";
  862. this->SetError(e.str());
  863. return false;
  864. }
  865. // Create the files install generator.
  866. this->Makefile->AddInstallGenerator(
  867. CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
  868. //Tell the global generator about any installation component names specified.
  869. this->Makefile->GetGlobalGenerator()
  870. ->AddInstallComponent(ica.GetComponent().c_str());
  871. return true;
  872. }
  873. //----------------------------------------------------------------------------
  874. bool
  875. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  876. {
  877. enum Doing { DoingNone, DoingDirs, DoingDestination, DoingPattern,
  878. DoingRegex, DoingPermsFile, DoingPermsDir, DoingPermsMatch,
  879. DoingConfigurations, DoingComponent };
  880. Doing doing = DoingDirs;
  881. bool in_match_mode = false;
  882. bool optional = false;
  883. bool message_never = false;
  884. std::vector<std::string> dirs;
  885. const char* destination = 0;
  886. std::string permissions_file;
  887. std::string permissions_dir;
  888. std::vector<std::string> configurations;
  889. std::string component = this->DefaultComponentName;
  890. std::string literal_args;
  891. for(unsigned int i=1; i < args.size(); ++i)
  892. {
  893. if(args[i] == "DESTINATION")
  894. {
  895. if(in_match_mode)
  896. {
  897. std::ostringstream e;
  898. e << args[0] << " does not allow \""
  899. << args[i] << "\" after PATTERN or REGEX.";
  900. this->SetError(e.str());
  901. return false;
  902. }
  903. // Switch to setting the destination property.
  904. doing = DoingDestination;
  905. }
  906. else if(args[i] == "OPTIONAL")
  907. {
  908. if(in_match_mode)
  909. {
  910. std::ostringstream e;
  911. e << args[0] << " does not allow \""
  912. << args[i] << "\" after PATTERN or REGEX.";
  913. this->SetError(e.str());
  914. return false;
  915. }
  916. // Mark the rule as optional.
  917. optional = true;
  918. doing = DoingNone;
  919. }
  920. else if(args[i] == "MESSAGE_NEVER")
  921. {
  922. if(in_match_mode)
  923. {
  924. std::ostringstream e;
  925. e << args[0] << " does not allow \""
  926. << args[i] << "\" after PATTERN or REGEX.";
  927. this->SetError(e.str());
  928. return false;
  929. }
  930. // Mark the rule as quiet.
  931. message_never = true;
  932. doing = DoingNone;
  933. }
  934. else if(args[i] == "PATTERN")
  935. {
  936. // Switch to a new pattern match rule.
  937. doing = DoingPattern;
  938. in_match_mode = true;
  939. }
  940. else if(args[i] == "REGEX")
  941. {
  942. // Switch to a new regex match rule.
  943. doing = DoingRegex;
  944. in_match_mode = true;
  945. }
  946. else if(args[i] == "EXCLUDE")
  947. {
  948. // Add this property to the current match rule.
  949. if(!in_match_mode || doing == DoingPattern || doing == DoingRegex)
  950. {
  951. std::ostringstream e;
  952. e << args[0] << " does not allow \""
  953. << args[i] << "\" before a PATTERN or REGEX is given.";
  954. this->SetError(e.str());
  955. return false;
  956. }
  957. literal_args += " EXCLUDE";
  958. doing = DoingNone;
  959. }
  960. else if(args[i] == "PERMISSIONS")
  961. {
  962. if(!in_match_mode)
  963. {
  964. std::ostringstream e;
  965. e << args[0] << " does not allow \""
  966. << args[i] << "\" before a PATTERN or REGEX is given.";
  967. this->SetError(e.str());
  968. return false;
  969. }
  970. // Switch to setting the current match permissions property.
  971. literal_args += " PERMISSIONS";
  972. doing = DoingPermsMatch;
  973. }
  974. else if(args[i] == "FILE_PERMISSIONS")
  975. {
  976. if(in_match_mode)
  977. {
  978. std::ostringstream e;
  979. e << args[0] << " does not allow \""
  980. << args[i] << "\" after PATTERN or REGEX.";
  981. this->SetError(e.str());
  982. return false;
  983. }
  984. // Switch to setting the file permissions property.
  985. doing = DoingPermsFile;
  986. }
  987. else if(args[i] == "DIRECTORY_PERMISSIONS")
  988. {
  989. if(in_match_mode)
  990. {
  991. std::ostringstream e;
  992. e << args[0] << " does not allow \""
  993. << args[i] << "\" after PATTERN or REGEX.";
  994. this->SetError(e.str());
  995. return false;
  996. }
  997. // Switch to setting the directory permissions property.
  998. doing = DoingPermsDir;
  999. }
  1000. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  1001. {
  1002. if(in_match_mode)
  1003. {
  1004. std::ostringstream e;
  1005. e << args[0] << " does not allow \""
  1006. << args[i] << "\" after PATTERN or REGEX.";
  1007. this->SetError(e.str());
  1008. return false;
  1009. }
  1010. // Add this option literally.
  1011. literal_args += " USE_SOURCE_PERMISSIONS";
  1012. doing = DoingNone;
  1013. }
  1014. else if(args[i] == "FILES_MATCHING")
  1015. {
  1016. if(in_match_mode)
  1017. {
  1018. std::ostringstream e;
  1019. e << args[0] << " does not allow \""
  1020. << args[i] << "\" after PATTERN or REGEX.";
  1021. this->SetError(e.str());
  1022. return false;
  1023. }
  1024. // Add this option literally.
  1025. literal_args += " FILES_MATCHING";
  1026. doing = DoingNone;
  1027. }
  1028. else if(args[i] == "CONFIGURATIONS")
  1029. {
  1030. if(in_match_mode)
  1031. {
  1032. std::ostringstream e;
  1033. e << args[0] << " does not allow \""
  1034. << args[i] << "\" after PATTERN or REGEX.";
  1035. this->SetError(e.str());
  1036. return false;
  1037. }
  1038. // Switch to setting the configurations property.
  1039. doing = DoingConfigurations;
  1040. }
  1041. else if(args[i] == "COMPONENT")
  1042. {
  1043. if(in_match_mode)
  1044. {
  1045. std::ostringstream e;
  1046. e << args[0] << " does not allow \""
  1047. << args[i] << "\" after PATTERN or REGEX.";
  1048. this->SetError(e.str());
  1049. return false;
  1050. }
  1051. // Switch to setting the component property.
  1052. doing = DoingComponent;
  1053. }
  1054. else if(doing == DoingDirs)
  1055. {
  1056. // Convert this directory to a full path.
  1057. std::string dir = args[i];
  1058. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  1059. {
  1060. dir = this->Makefile->GetCurrentSourceDirectory();
  1061. dir += "/";
  1062. dir += args[i];
  1063. }
  1064. // Make sure the name is a directory.
  1065. if(cmSystemTools::FileExists(dir.c_str()) &&
  1066. !cmSystemTools::FileIsDirectory(dir))
  1067. {
  1068. std::ostringstream e;
  1069. e << args[0] << " given non-directory \""
  1070. << args[i] << "\" to install.";
  1071. this->SetError(e.str());
  1072. return false;
  1073. }
  1074. // Store the directory for installation.
  1075. dirs.push_back(dir);
  1076. }
  1077. else if(doing == DoingConfigurations)
  1078. {
  1079. configurations.push_back(args[i]);
  1080. }
  1081. else if(doing == DoingDestination)
  1082. {
  1083. destination = args[i].c_str();
  1084. doing = DoingNone;
  1085. }
  1086. else if(doing == DoingPattern)
  1087. {
  1088. // Convert the pattern to a regular expression. Require a
  1089. // leading slash and trailing end-of-string in the matched
  1090. // string to make sure the pattern matches only whole file
  1091. // names.
  1092. literal_args += " REGEX \"/";
  1093. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1094. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1095. literal_args += regex;
  1096. literal_args += "$\"";
  1097. doing = DoingNone;
  1098. }
  1099. else if(doing == DoingRegex)
  1100. {
  1101. literal_args += " REGEX \"";
  1102. // Match rules are case-insensitive on some platforms.
  1103. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  1104. std::string regex = cmSystemTools::LowerCase(args[i]);
  1105. #else
  1106. std::string regex = args[i];
  1107. #endif
  1108. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1109. literal_args += regex;
  1110. literal_args += "\"";
  1111. doing = DoingNone;
  1112. }
  1113. else if(doing == DoingComponent)
  1114. {
  1115. component = args[i];
  1116. doing = DoingNone;
  1117. }
  1118. else if(doing == DoingPermsFile)
  1119. {
  1120. // Check the requested permission.
  1121. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
  1122. {
  1123. std::ostringstream e;
  1124. e << args[0] << " given invalid file permission \""
  1125. << args[i] << "\".";
  1126. this->SetError(e.str());
  1127. return false;
  1128. }
  1129. }
  1130. else if(doing == DoingPermsDir)
  1131. {
  1132. // Check the requested permission.
  1133. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
  1134. {
  1135. std::ostringstream e;
  1136. e << args[0] << " given invalid directory permission \""
  1137. << args[i] << "\".";
  1138. this->SetError(e.str());
  1139. return false;
  1140. }
  1141. }
  1142. else if(doing == DoingPermsMatch)
  1143. {
  1144. // Check the requested permission.
  1145. if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
  1146. {
  1147. std::ostringstream e;
  1148. e << args[0] << " given invalid permission \""
  1149. << args[i] << "\".";
  1150. this->SetError(e.str());
  1151. return false;
  1152. }
  1153. }
  1154. else
  1155. {
  1156. // Unknown argument.
  1157. std::ostringstream e;
  1158. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  1159. this->SetError(e.str());
  1160. return false;
  1161. }
  1162. }
  1163. // Support installing an empty directory.
  1164. if(dirs.empty() && destination)
  1165. {
  1166. dirs.push_back("");
  1167. }
  1168. // Check if there is something to do.
  1169. if(dirs.empty())
  1170. {
  1171. return true;
  1172. }
  1173. if(!destination)
  1174. {
  1175. // A destination is required.
  1176. std::ostringstream e;
  1177. e << args[0] << " given no DESTINATION!";
  1178. this->SetError(e.str());
  1179. return false;
  1180. }
  1181. cmInstallGenerator::MessageLevel message =
  1182. cmInstallGenerator::SelectMessageLevel(this->Makefile, message_never);
  1183. // Create the directory install generator.
  1184. this->Makefile->AddInstallGenerator(
  1185. new cmInstallDirectoryGenerator(dirs, destination,
  1186. permissions_file.c_str(),
  1187. permissions_dir.c_str(),
  1188. configurations,
  1189. component.c_str(),
  1190. message,
  1191. literal_args.c_str(),
  1192. optional));
  1193. // Tell the global generator about any installation component names
  1194. // specified.
  1195. this->Makefile->GetGlobalGenerator()
  1196. ->AddInstallComponent(component.c_str());
  1197. return true;
  1198. }
  1199. //----------------------------------------------------------------------------
  1200. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  1201. {
  1202. // This is the EXPORT mode.
  1203. cmInstallCommandArguments ica(this->DefaultComponentName);
  1204. cmCAString exp(&ica.Parser, "EXPORT");
  1205. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1206. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1207. &ica.ArgumentGroup);
  1208. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1209. exp.Follows(0);
  1210. ica.ArgumentGroup.Follows(&exp);
  1211. std::vector<std::string> unknownArgs;
  1212. ica.Parse(&args, &unknownArgs);
  1213. if (!unknownArgs.empty())
  1214. {
  1215. // Unknown argument.
  1216. std::ostringstream e;
  1217. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1218. this->SetError(e.str());
  1219. return false;
  1220. }
  1221. if (!ica.Finalize())
  1222. {
  1223. return false;
  1224. }
  1225. // Make sure there is a destination.
  1226. if(ica.GetDestination().empty())
  1227. {
  1228. // A destination is required.
  1229. std::ostringstream e;
  1230. e << args[0] << " given no DESTINATION!";
  1231. this->SetError(e.str());
  1232. return false;
  1233. }
  1234. // Check the file name.
  1235. std::string fname = filename.GetString();
  1236. if(fname.find_first_of(":/\\") != fname.npos)
  1237. {
  1238. std::ostringstream e;
  1239. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1240. << "The FILE argument may not contain a path. "
  1241. << "Specify the path in the DESTINATION argument.";
  1242. this->SetError(e.str());
  1243. return false;
  1244. }
  1245. // Check the file extension.
  1246. if(!fname.empty() &&
  1247. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake")
  1248. {
  1249. std::ostringstream e;
  1250. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1251. << "The FILE argument must specify a name ending in \".cmake\".";
  1252. this->SetError(e.str());
  1253. return false;
  1254. }
  1255. // Construct the file name.
  1256. if(fname.empty())
  1257. {
  1258. fname = exp.GetString();
  1259. fname += ".cmake";
  1260. if(fname.find_first_of(":/\\") != fname.npos)
  1261. {
  1262. std::ostringstream e;
  1263. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1264. << "This name cannot be safely converted to a file name. "
  1265. << "Specify a different export name or use the FILE option to set "
  1266. << "a file name explicitly.";
  1267. this->SetError(e.str());
  1268. return false;
  1269. }
  1270. }
  1271. cmExportSet *exportSet = this->Makefile->GetGlobalGenerator()
  1272. ->GetExportSets()[exp.GetString()];
  1273. if (exportOld.IsEnabled())
  1274. {
  1275. for(std::vector<cmTargetExport*>::const_iterator
  1276. tei = exportSet->GetTargetExports()->begin();
  1277. tei != exportSet->GetTargetExports()->end(); ++tei)
  1278. {
  1279. cmTargetExport const* te = *tei;
  1280. cmTarget* tgt = this->Makefile->FindTarget(te->TargetName);
  1281. const bool newCMP0022Behavior =
  1282. tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN
  1283. && tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  1284. if(!newCMP0022Behavior)
  1285. {
  1286. std::ostringstream e;
  1287. e << "INSTALL(EXPORT) given keyword \""
  1288. << "EXPORT_LINK_INTERFACE_LIBRARIES" << "\", but target \""
  1289. << te->TargetName
  1290. << "\" does not have policy CMP0022 set to NEW.";
  1291. this->SetError(e.str());
  1292. return false;
  1293. }
  1294. }
  1295. }
  1296. cmInstallGenerator::MessageLevel message =
  1297. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1298. // Create the export install generator.
  1299. cmInstallExportGenerator* exportGenerator =
  1300. new cmInstallExportGenerator(
  1301. exportSet,
  1302. ica.GetDestination().c_str(),
  1303. ica.GetPermissions().c_str(), ica.GetConfigurations(),
  1304. ica.GetComponent().c_str(), message, fname.c_str(),
  1305. name_space.GetCString(), exportOld.IsEnabled());
  1306. this->Makefile->AddInstallGenerator(exportGenerator);
  1307. return true;
  1308. }
  1309. bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
  1310. const std::vector<std::string>& relFiles,
  1311. std::vector<std::string>& absFiles)
  1312. {
  1313. for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
  1314. fileIt != relFiles.end();
  1315. ++fileIt)
  1316. {
  1317. std::string file = (*fileIt);
  1318. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  1319. if(gpos != 0 && !cmSystemTools::FileIsFullPath(file.c_str()))
  1320. {
  1321. file = this->Makefile->GetCurrentSourceDirectory();
  1322. file += "/";
  1323. file += *fileIt;
  1324. }
  1325. // Make sure the file is not a directory.
  1326. if(gpos == file.npos && cmSystemTools::FileIsDirectory(file))
  1327. {
  1328. std::ostringstream e;
  1329. e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
  1330. this->SetError(e.str());
  1331. return false;
  1332. }
  1333. // Store the file for installation.
  1334. absFiles.push_back(file);
  1335. }
  1336. return true;
  1337. }
  1338. //----------------------------------------------------------------------------
  1339. bool cmInstallCommand::CheckCMP0006(bool& failure)
  1340. {
  1341. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0006))
  1342. {
  1343. case cmPolicies::WARN:
  1344. {
  1345. this->Makefile->IssueMessage(
  1346. cmake::AUTHOR_WARNING,
  1347. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006)
  1348. );
  1349. }
  1350. case cmPolicies::OLD:
  1351. // OLD behavior is to allow compatibility
  1352. return true;
  1353. case cmPolicies::NEW:
  1354. // NEW behavior is to disallow compatibility
  1355. break;
  1356. case cmPolicies::REQUIRED_IF_USED:
  1357. case cmPolicies::REQUIRED_ALWAYS:
  1358. failure = true;
  1359. this->Makefile->IssueMessage(
  1360. cmake::FATAL_ERROR,
  1361. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006)
  1362. );
  1363. break;
  1364. }
  1365. return false;
  1366. }