cmInstallCommand.cxx 44 KB

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