cmInstallCommand.cxx 61 KB

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