cmInstallCommand.cxx 47 KB

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