cmInstallCommand.cxx 59 KB

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