cmInstallCommand.cxx 45 KB

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