cmInstallCommand.cxx 45 KB

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