cmInstallCommand.cxx 48 KB

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