cmInstallCommand.cxx 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. if (installsArchive || installsRuntime || installsFramework
  702. || installsLibrary || installsBundle)
  703. {
  704. target.SetHaveInstallRule(true);
  705. }
  706. this->Makefile->AddInstallGenerator(archiveGenerator);
  707. this->Makefile->AddInstallGenerator(libraryGenerator);
  708. this->Makefile->AddInstallGenerator(runtimeGenerator);
  709. this->Makefile->AddInstallGenerator(frameworkGenerator);
  710. this->Makefile->AddInstallGenerator(bundleGenerator);
  711. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  712. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  713. this->Makefile->AddInstallGenerator(resourceGenerator);
  714. // Add this install rule to an export if one was specified and
  715. // this is not a namelink-only rule.
  716. if(!exports.GetString().empty() && !namelinkOnly)
  717. {
  718. cmTargetExport *te = new cmTargetExport;
  719. te->Target = &target;
  720. te->ArchiveGenerator = archiveGenerator;
  721. te->BundleGenerator = bundleGenerator;
  722. te->FrameworkGenerator = frameworkGenerator;
  723. te->HeaderGenerator = publicHeaderGenerator;
  724. te->LibraryGenerator = libraryGenerator;
  725. te->RuntimeGenerator = runtimeGenerator;
  726. this->Makefile->GetGlobalGenerator()
  727. ->GetExportSets()[exports.GetString()]->AddTargetExport(te);
  728. te->InterfaceIncludeDirectories =
  729. cmJoin(includesArgs.GetIncludeDirs(), ";");
  730. }
  731. }
  732. // Tell the global generator about any installation component names
  733. // specified
  734. if (installsArchive)
  735. {
  736. this->Makefile->GetGlobalGenerator()
  737. ->AddInstallComponent(archiveArgs.GetComponent().c_str());
  738. }
  739. if (installsLibrary)
  740. {
  741. this->Makefile->GetGlobalGenerator()
  742. ->AddInstallComponent(libraryArgs.GetComponent().c_str());
  743. }
  744. if (installsRuntime)
  745. {
  746. this->Makefile->GetGlobalGenerator()
  747. ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
  748. }
  749. if (installsFramework)
  750. {
  751. this->Makefile->GetGlobalGenerator()
  752. ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
  753. }
  754. if (installsBundle)
  755. {
  756. this->Makefile->GetGlobalGenerator()
  757. ->AddInstallComponent(bundleArgs.GetComponent().c_str());
  758. }
  759. if (installsPrivateHeader)
  760. {
  761. this->Makefile->GetGlobalGenerator()
  762. ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
  763. }
  764. if (installsPublicHeader)
  765. {
  766. this->Makefile->GetGlobalGenerator()
  767. ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
  768. }
  769. if (installsResource)
  770. {
  771. this->Makefile->GetGlobalGenerator()
  772. ->AddInstallComponent(resourceArgs.GetComponent().c_str());
  773. }
  774. return true;
  775. }
  776. //----------------------------------------------------------------------------
  777. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  778. {
  779. // This is the FILES mode.
  780. bool programs = (args[0] == "PROGRAMS");
  781. cmInstallCommandArguments ica(this->DefaultComponentName);
  782. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  783. files.Follows(0);
  784. ica.ArgumentGroup.Follows(&files);
  785. std::vector<std::string> unknownArgs;
  786. ica.Parse(&args, &unknownArgs);
  787. if(!unknownArgs.empty())
  788. {
  789. // Unknown argument.
  790. std::ostringstream e;
  791. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  792. this->SetError(e.str());
  793. return false;
  794. }
  795. const std::vector<std::string>& filesVector = files.GetVector();
  796. // Check if there is something to do.
  797. if(filesVector.empty())
  798. {
  799. return true;
  800. }
  801. if(!ica.GetRename().empty() && filesVector.size() > 1)
  802. {
  803. // The rename option works only with one file.
  804. std::ostringstream e;
  805. e << args[0] << " given RENAME option with more than one file.";
  806. this->SetError(e.str());
  807. return false;
  808. }
  809. std::vector<std::string> absFiles;
  810. if (!this->MakeFilesFullPath(args[0].c_str(), filesVector, absFiles))
  811. {
  812. return false;
  813. }
  814. cmPolicies::PolicyStatus status =
  815. this->Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  816. cmGlobalGenerator *gg = this->Makefile->GetGlobalGenerator();
  817. for(std::vector<std::string>::const_iterator fileIt = filesVector.begin();
  818. fileIt != filesVector.end(); ++fileIt)
  819. {
  820. if (gg->IsExportedTargetsFile(*fileIt))
  821. {
  822. const char *modal = 0;
  823. std::ostringstream e;
  824. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  825. switch(status)
  826. {
  827. case cmPolicies::WARN:
  828. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  829. modal = "should";
  830. case cmPolicies::OLD:
  831. break;
  832. case cmPolicies::REQUIRED_IF_USED:
  833. case cmPolicies::REQUIRED_ALWAYS:
  834. case cmPolicies::NEW:
  835. modal = "may";
  836. messageType = cmake::FATAL_ERROR;
  837. }
  838. if (modal)
  839. {
  840. e << "The file\n " << *fileIt << "\nwas generated by the export() "
  841. "command. It " << modal << " not be installed with the "
  842. "install() command. Use the install(EXPORT) mechanism "
  843. "instead. See the cmake-packages(7) manual for more.\n";
  844. this->Makefile->IssueMessage(messageType, e.str());
  845. if (messageType == cmake::FATAL_ERROR)
  846. {
  847. return false;
  848. }
  849. }
  850. }
  851. }
  852. if (!ica.Finalize())
  853. {
  854. return false;
  855. }
  856. if(ica.GetDestination().empty())
  857. {
  858. // A destination is required.
  859. std::ostringstream e;
  860. e << args[0] << " given no DESTINATION!";
  861. this->SetError(e.str());
  862. return false;
  863. }
  864. // Create the files install generator.
  865. this->Makefile->AddInstallGenerator(
  866. CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
  867. //Tell the global generator about any installation component names specified.
  868. this->Makefile->GetGlobalGenerator()
  869. ->AddInstallComponent(ica.GetComponent().c_str());
  870. return true;
  871. }
  872. //----------------------------------------------------------------------------
  873. bool
  874. cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
  875. {
  876. enum Doing { DoingNone, DoingDirs, DoingDestination, DoingPattern,
  877. DoingRegex, DoingPermsFile, DoingPermsDir, DoingPermsMatch,
  878. DoingConfigurations, DoingComponent };
  879. Doing doing = DoingDirs;
  880. bool in_match_mode = false;
  881. bool optional = false;
  882. bool message_never = false;
  883. std::vector<std::string> dirs;
  884. const char* destination = 0;
  885. std::string permissions_file;
  886. std::string permissions_dir;
  887. std::vector<std::string> configurations;
  888. std::string component = this->DefaultComponentName;
  889. std::string literal_args;
  890. for(unsigned int i=1; i < args.size(); ++i)
  891. {
  892. if(args[i] == "DESTINATION")
  893. {
  894. if(in_match_mode)
  895. {
  896. std::ostringstream e;
  897. e << args[0] << " does not allow \""
  898. << args[i] << "\" after PATTERN or REGEX.";
  899. this->SetError(e.str());
  900. return false;
  901. }
  902. // Switch to setting the destination property.
  903. doing = DoingDestination;
  904. }
  905. else if(args[i] == "OPTIONAL")
  906. {
  907. if(in_match_mode)
  908. {
  909. std::ostringstream e;
  910. e << args[0] << " does not allow \""
  911. << args[i] << "\" after PATTERN or REGEX.";
  912. this->SetError(e.str());
  913. return false;
  914. }
  915. // Mark the rule as optional.
  916. optional = true;
  917. doing = DoingNone;
  918. }
  919. else if(args[i] == "MESSAGE_NEVER")
  920. {
  921. if(in_match_mode)
  922. {
  923. std::ostringstream e;
  924. e << args[0] << " does not allow \""
  925. << args[i] << "\" after PATTERN or REGEX.";
  926. this->SetError(e.str());
  927. return false;
  928. }
  929. // Mark the rule as quiet.
  930. message_never = true;
  931. doing = DoingNone;
  932. }
  933. else if(args[i] == "PATTERN")
  934. {
  935. // Switch to a new pattern match rule.
  936. doing = DoingPattern;
  937. in_match_mode = true;
  938. }
  939. else if(args[i] == "REGEX")
  940. {
  941. // Switch to a new regex match rule.
  942. doing = DoingRegex;
  943. in_match_mode = true;
  944. }
  945. else if(args[i] == "EXCLUDE")
  946. {
  947. // Add this property to the current match rule.
  948. if(!in_match_mode || doing == DoingPattern || doing == DoingRegex)
  949. {
  950. std::ostringstream e;
  951. e << args[0] << " does not allow \""
  952. << args[i] << "\" before a PATTERN or REGEX is given.";
  953. this->SetError(e.str());
  954. return false;
  955. }
  956. literal_args += " EXCLUDE";
  957. doing = DoingNone;
  958. }
  959. else if(args[i] == "PERMISSIONS")
  960. {
  961. if(!in_match_mode)
  962. {
  963. std::ostringstream e;
  964. e << args[0] << " does not allow \""
  965. << args[i] << "\" before a PATTERN or REGEX is given.";
  966. this->SetError(e.str());
  967. return false;
  968. }
  969. // Switch to setting the current match permissions property.
  970. literal_args += " PERMISSIONS";
  971. doing = DoingPermsMatch;
  972. }
  973. else if(args[i] == "FILE_PERMISSIONS")
  974. {
  975. if(in_match_mode)
  976. {
  977. std::ostringstream e;
  978. e << args[0] << " does not allow \""
  979. << args[i] << "\" after PATTERN or REGEX.";
  980. this->SetError(e.str());
  981. return false;
  982. }
  983. // Switch to setting the file permissions property.
  984. doing = DoingPermsFile;
  985. }
  986. else if(args[i] == "DIRECTORY_PERMISSIONS")
  987. {
  988. if(in_match_mode)
  989. {
  990. std::ostringstream e;
  991. e << args[0] << " does not allow \""
  992. << args[i] << "\" after PATTERN or REGEX.";
  993. this->SetError(e.str());
  994. return false;
  995. }
  996. // Switch to setting the directory permissions property.
  997. doing = DoingPermsDir;
  998. }
  999. else if(args[i] == "USE_SOURCE_PERMISSIONS")
  1000. {
  1001. if(in_match_mode)
  1002. {
  1003. std::ostringstream e;
  1004. e << args[0] << " does not allow \""
  1005. << args[i] << "\" after PATTERN or REGEX.";
  1006. this->SetError(e.str());
  1007. return false;
  1008. }
  1009. // Add this option literally.
  1010. literal_args += " USE_SOURCE_PERMISSIONS";
  1011. doing = DoingNone;
  1012. }
  1013. else if(args[i] == "FILES_MATCHING")
  1014. {
  1015. if(in_match_mode)
  1016. {
  1017. std::ostringstream e;
  1018. e << args[0] << " does not allow \""
  1019. << args[i] << "\" after PATTERN or REGEX.";
  1020. this->SetError(e.str());
  1021. return false;
  1022. }
  1023. // Add this option literally.
  1024. literal_args += " FILES_MATCHING";
  1025. doing = DoingNone;
  1026. }
  1027. else if(args[i] == "CONFIGURATIONS")
  1028. {
  1029. if(in_match_mode)
  1030. {
  1031. std::ostringstream e;
  1032. e << args[0] << " does not allow \""
  1033. << args[i] << "\" after PATTERN or REGEX.";
  1034. this->SetError(e.str());
  1035. return false;
  1036. }
  1037. // Switch to setting the configurations property.
  1038. doing = DoingConfigurations;
  1039. }
  1040. else if(args[i] == "COMPONENT")
  1041. {
  1042. if(in_match_mode)
  1043. {
  1044. std::ostringstream e;
  1045. e << args[0] << " does not allow \""
  1046. << args[i] << "\" after PATTERN or REGEX.";
  1047. this->SetError(e.str());
  1048. return false;
  1049. }
  1050. // Switch to setting the component property.
  1051. doing = DoingComponent;
  1052. }
  1053. else if(doing == DoingDirs)
  1054. {
  1055. // Convert this directory to a full path.
  1056. std::string dir = args[i];
  1057. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  1058. {
  1059. dir = this->Makefile->GetCurrentSourceDirectory();
  1060. dir += "/";
  1061. dir += args[i];
  1062. }
  1063. // Make sure the name is a directory.
  1064. if(cmSystemTools::FileExists(dir.c_str()) &&
  1065. !cmSystemTools::FileIsDirectory(dir))
  1066. {
  1067. std::ostringstream e;
  1068. e << args[0] << " given non-directory \""
  1069. << args[i] << "\" to install.";
  1070. this->SetError(e.str());
  1071. return false;
  1072. }
  1073. // Store the directory for installation.
  1074. dirs.push_back(dir);
  1075. }
  1076. else if(doing == DoingConfigurations)
  1077. {
  1078. configurations.push_back(args[i]);
  1079. }
  1080. else if(doing == DoingDestination)
  1081. {
  1082. destination = args[i].c_str();
  1083. doing = DoingNone;
  1084. }
  1085. else if(doing == DoingPattern)
  1086. {
  1087. // Convert the pattern to a regular expression. Require a
  1088. // leading slash and trailing end-of-string in the matched
  1089. // string to make sure the pattern matches only whole file
  1090. // names.
  1091. literal_args += " REGEX \"/";
  1092. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1093. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1094. literal_args += regex;
  1095. literal_args += "$\"";
  1096. doing = DoingNone;
  1097. }
  1098. else if(doing == DoingRegex)
  1099. {
  1100. literal_args += " REGEX \"";
  1101. // Match rules are case-insensitive on some platforms.
  1102. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  1103. std::string regex = cmSystemTools::LowerCase(args[i]);
  1104. #else
  1105. std::string regex = args[i];
  1106. #endif
  1107. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1108. literal_args += regex;
  1109. literal_args += "\"";
  1110. doing = DoingNone;
  1111. }
  1112. else if(doing == DoingComponent)
  1113. {
  1114. component = args[i];
  1115. doing = DoingNone;
  1116. }
  1117. else if(doing == DoingPermsFile)
  1118. {
  1119. // Check the requested permission.
  1120. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
  1121. {
  1122. std::ostringstream e;
  1123. e << args[0] << " given invalid file permission \""
  1124. << args[i] << "\".";
  1125. this->SetError(e.str());
  1126. return false;
  1127. }
  1128. }
  1129. else if(doing == DoingPermsDir)
  1130. {
  1131. // Check the requested permission.
  1132. if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
  1133. {
  1134. std::ostringstream e;
  1135. e << args[0] << " given invalid directory permission \""
  1136. << args[i] << "\".";
  1137. this->SetError(e.str());
  1138. return false;
  1139. }
  1140. }
  1141. else if(doing == DoingPermsMatch)
  1142. {
  1143. // Check the requested permission.
  1144. if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
  1145. {
  1146. std::ostringstream e;
  1147. e << args[0] << " given invalid permission \""
  1148. << args[i] << "\".";
  1149. this->SetError(e.str());
  1150. return false;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. // Unknown argument.
  1156. std::ostringstream e;
  1157. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  1158. this->SetError(e.str());
  1159. return false;
  1160. }
  1161. }
  1162. // Support installing an empty directory.
  1163. if(dirs.empty() && destination)
  1164. {
  1165. dirs.push_back("");
  1166. }
  1167. // Check if there is something to do.
  1168. if(dirs.empty())
  1169. {
  1170. return true;
  1171. }
  1172. if(!destination)
  1173. {
  1174. // A destination is required.
  1175. std::ostringstream e;
  1176. e << args[0] << " given no DESTINATION!";
  1177. this->SetError(e.str());
  1178. return false;
  1179. }
  1180. cmInstallGenerator::MessageLevel message =
  1181. cmInstallGenerator::SelectMessageLevel(this->Makefile, message_never);
  1182. // Create the directory install generator.
  1183. this->Makefile->AddInstallGenerator(
  1184. new cmInstallDirectoryGenerator(dirs, destination,
  1185. permissions_file.c_str(),
  1186. permissions_dir.c_str(),
  1187. configurations,
  1188. component.c_str(),
  1189. message,
  1190. literal_args.c_str(),
  1191. optional));
  1192. // Tell the global generator about any installation component names
  1193. // specified.
  1194. this->Makefile->GetGlobalGenerator()
  1195. ->AddInstallComponent(component.c_str());
  1196. return true;
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  1200. {
  1201. // This is the EXPORT mode.
  1202. cmInstallCommandArguments ica(this->DefaultComponentName);
  1203. cmCAString exp(&ica.Parser, "EXPORT");
  1204. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1205. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1206. &ica.ArgumentGroup);
  1207. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1208. exp.Follows(0);
  1209. ica.ArgumentGroup.Follows(&exp);
  1210. std::vector<std::string> unknownArgs;
  1211. ica.Parse(&args, &unknownArgs);
  1212. if (!unknownArgs.empty())
  1213. {
  1214. // Unknown argument.
  1215. std::ostringstream e;
  1216. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1217. this->SetError(e.str());
  1218. return false;
  1219. }
  1220. if (!ica.Finalize())
  1221. {
  1222. return false;
  1223. }
  1224. // Make sure there is a destination.
  1225. if(ica.GetDestination().empty())
  1226. {
  1227. // A destination is required.
  1228. std::ostringstream e;
  1229. e << args[0] << " given no DESTINATION!";
  1230. this->SetError(e.str());
  1231. return false;
  1232. }
  1233. // Check the file name.
  1234. std::string fname = filename.GetString();
  1235. if(fname.find_first_of(":/\\") != fname.npos)
  1236. {
  1237. std::ostringstream e;
  1238. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1239. << "The FILE argument may not contain a path. "
  1240. << "Specify the path in the DESTINATION argument.";
  1241. this->SetError(e.str());
  1242. return false;
  1243. }
  1244. // Check the file extension.
  1245. if(!fname.empty() &&
  1246. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake")
  1247. {
  1248. std::ostringstream e;
  1249. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1250. << "The FILE argument must specify a name ending in \".cmake\".";
  1251. this->SetError(e.str());
  1252. return false;
  1253. }
  1254. // Construct the file name.
  1255. if(fname.empty())
  1256. {
  1257. fname = exp.GetString();
  1258. fname += ".cmake";
  1259. if(fname.find_first_of(":/\\") != fname.npos)
  1260. {
  1261. std::ostringstream e;
  1262. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1263. << "This name cannot be safely converted to a file name. "
  1264. << "Specify a different export name or use the FILE option to set "
  1265. << "a file name explicitly.";
  1266. this->SetError(e.str());
  1267. return false;
  1268. }
  1269. }
  1270. cmExportSet *exportSet = this->Makefile->GetGlobalGenerator()
  1271. ->GetExportSets()[exp.GetString()];
  1272. if (exportOld.IsEnabled())
  1273. {
  1274. for(std::vector<cmTargetExport*>::const_iterator
  1275. tei = exportSet->GetTargetExports()->begin();
  1276. tei != exportSet->GetTargetExports()->end(); ++tei)
  1277. {
  1278. cmTargetExport const* te = *tei;
  1279. const bool newCMP0022Behavior =
  1280. te->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN
  1281. && te->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  1282. if(!newCMP0022Behavior)
  1283. {
  1284. std::ostringstream e;
  1285. e << "INSTALL(EXPORT) given keyword \""
  1286. << "EXPORT_LINK_INTERFACE_LIBRARIES" << "\", but target \""
  1287. << te->Target->GetName()
  1288. << "\" does not have policy CMP0022 set to NEW.";
  1289. this->SetError(e.str());
  1290. return false;
  1291. }
  1292. }
  1293. }
  1294. cmInstallGenerator::MessageLevel message =
  1295. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1296. // Create the export install generator.
  1297. cmInstallExportGenerator* exportGenerator =
  1298. new cmInstallExportGenerator(
  1299. exportSet,
  1300. ica.GetDestination().c_str(),
  1301. ica.GetPermissions().c_str(), ica.GetConfigurations(),
  1302. ica.GetComponent().c_str(), message, fname.c_str(),
  1303. name_space.GetCString(), exportOld.IsEnabled(), this->Makefile);
  1304. this->Makefile->AddInstallGenerator(exportGenerator);
  1305. return true;
  1306. }
  1307. bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
  1308. const std::vector<std::string>& relFiles,
  1309. std::vector<std::string>& absFiles)
  1310. {
  1311. for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
  1312. fileIt != relFiles.end();
  1313. ++fileIt)
  1314. {
  1315. std::string file = (*fileIt);
  1316. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  1317. if(gpos != 0 && !cmSystemTools::FileIsFullPath(file.c_str()))
  1318. {
  1319. file = this->Makefile->GetCurrentSourceDirectory();
  1320. file += "/";
  1321. file += *fileIt;
  1322. }
  1323. // Make sure the file is not a directory.
  1324. if(gpos == file.npos && cmSystemTools::FileIsDirectory(file))
  1325. {
  1326. std::ostringstream e;
  1327. e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
  1328. this->SetError(e.str());
  1329. return false;
  1330. }
  1331. // Store the file for installation.
  1332. absFiles.push_back(file);
  1333. }
  1334. return true;
  1335. }
  1336. //----------------------------------------------------------------------------
  1337. bool cmInstallCommand::CheckCMP0006(bool& failure)
  1338. {
  1339. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0006))
  1340. {
  1341. case cmPolicies::WARN:
  1342. {
  1343. this->Makefile->IssueMessage(
  1344. cmake::AUTHOR_WARNING,
  1345. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006)
  1346. );
  1347. }
  1348. case cmPolicies::OLD:
  1349. // OLD behavior is to allow compatibility
  1350. return true;
  1351. case cmPolicies::NEW:
  1352. // NEW behavior is to disallow compatibility
  1353. break;
  1354. case cmPolicies::REQUIRED_IF_USED:
  1355. case cmPolicies::REQUIRED_ALWAYS:
  1356. failure = true;
  1357. this->Makefile->IssueMessage(
  1358. cmake::FATAL_ERROR,
  1359. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006)
  1360. );
  1361. break;
  1362. }
  1363. return false;
  1364. }