cmInstallCommand.cxx 60 KB

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