cmInstallCommand.cxx 46 KB

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