cmInstallCommand.cxx 47 KB

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