cmInstallCommand.cxx 45 KB

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