cmInstallCommand.cxx 44 KB

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