cmInstallCommand.cxx 46 KB

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