cmInstallCommand.cxx 45 KB

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