cmInstallCommand.cxx 46 KB

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