cmInstallCommand.cxx 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  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. auto addTargetExport = [&]() {
  427. // Add this install rule to an export if one was specified.
  428. if (!exports.empty()) {
  429. auto te = cm::make_unique<cmTargetExport>();
  430. te->TargetName = target.GetName();
  431. te->ArchiveGenerator = archiveGenerator.get();
  432. te->BundleGenerator = bundleGenerator.get();
  433. te->FrameworkGenerator = frameworkGenerator.get();
  434. te->HeaderGenerator = publicHeaderGenerator.get();
  435. te->LibraryGenerator = libraryGenerator.get();
  436. te->RuntimeGenerator = runtimeGenerator.get();
  437. te->ObjectsGenerator = objectGenerator.get();
  438. te->InterfaceIncludeDirectories =
  439. cmJoin(includesArgs.GetIncludeDirs(), ";");
  440. te->NamelinkOnly = namelinkOnly;
  441. helper.Makefile->GetGlobalGenerator()
  442. ->GetExportSets()[exports]
  443. .AddTargetExport(std::move(te));
  444. }
  445. };
  446. switch (target.GetType()) {
  447. case cmStateEnums::SHARED_LIBRARY: {
  448. // Shared libraries are handled differently on DLL and non-DLL
  449. // platforms. All windows platforms are DLL platforms including
  450. // cygwin. Currently no other platform is a DLL platform.
  451. if (target.IsDLLPlatform()) {
  452. // When in namelink only mode skip all libraries on Windows.
  453. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  454. namelinkOnly = true;
  455. addTargetExport();
  456. continue;
  457. }
  458. // This is a DLL platform.
  459. if (!archiveArgs.GetDestination().empty()) {
  460. // The import library uses the ARCHIVE properties.
  461. archiveGenerator = CreateInstallTargetGenerator(
  462. target, archiveArgs, true, helper.Makefile->GetBacktrace());
  463. artifactsSpecified = true;
  464. }
  465. if (!runtimeArgs.GetDestination().empty()) {
  466. // The DLL uses the RUNTIME properties.
  467. runtimeGenerator = CreateInstallTargetGenerator(
  468. target, runtimeArgs, false, helper.Makefile->GetBacktrace());
  469. artifactsSpecified = true;
  470. }
  471. if (!archiveGenerator && !runtimeGenerator) {
  472. archiveGenerator = CreateInstallTargetGenerator(
  473. target, archiveArgs, true, helper.Makefile->GetBacktrace(),
  474. helper.GetArchiveDestination(nullptr));
  475. runtimeGenerator = CreateInstallTargetGenerator(
  476. target, runtimeArgs, false, helper.Makefile->GetBacktrace(),
  477. helper.GetRuntimeDestination(nullptr));
  478. }
  479. } else {
  480. // This is a non-DLL platform.
  481. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  482. // INSTALL properties. Otherwise, use the LIBRARY properties.
  483. if (target.IsFrameworkOnApple()) {
  484. // When in namelink only mode skip frameworks.
  485. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  486. namelinkOnly = true;
  487. addTargetExport();
  488. continue;
  489. }
  490. // Use the FRAMEWORK properties.
  491. if (!frameworkArgs.GetDestination().empty()) {
  492. frameworkGenerator = CreateInstallTargetGenerator(
  493. target, frameworkArgs, false, helper.Makefile->GetBacktrace());
  494. } else {
  495. status.SetError(
  496. cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared "
  497. "library FRAMEWORK target \"",
  498. target.GetName(), "\"."));
  499. return false;
  500. }
  501. } else {
  502. // The shared library uses the LIBRARY properties.
  503. if (!libraryArgs.GetDestination().empty()) {
  504. artifactsSpecified = true;
  505. }
  506. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
  507. libraryGenerator = CreateInstallTargetGenerator(
  508. target, libraryArgs, false, helper.Makefile->GetBacktrace(),
  509. helper.GetLibraryDestination(&libraryArgs));
  510. libraryGenerator->SetNamelinkMode(
  511. cmInstallTargetGenerator::NamelinkModeSkip);
  512. }
  513. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) {
  514. namelinkGenerator = CreateInstallTargetGenerator(
  515. target, libraryArgs, false, helper.Makefile->GetBacktrace(),
  516. helper.GetLibraryDestination(&libraryArgs), false, true);
  517. namelinkGenerator->SetNamelinkMode(
  518. cmInstallTargetGenerator::NamelinkModeOnly);
  519. }
  520. namelinkOnly =
  521. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  522. }
  523. }
  524. } break;
  525. case cmStateEnums::STATIC_LIBRARY: {
  526. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  527. // INSTALL properties. Otherwise, use the LIBRARY properties.
  528. if (target.IsFrameworkOnApple()) {
  529. // When in namelink only mode skip frameworks.
  530. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  531. namelinkOnly = true;
  532. addTargetExport();
  533. continue;
  534. }
  535. // Use the FRAMEWORK properties.
  536. if (!frameworkArgs.GetDestination().empty()) {
  537. frameworkGenerator = CreateInstallTargetGenerator(
  538. target, frameworkArgs, false, helper.Makefile->GetBacktrace());
  539. } else {
  540. status.SetError(
  541. cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static "
  542. "library FRAMEWORK target \"",
  543. target.GetName(), "\"."));
  544. return false;
  545. }
  546. } else {
  547. // Static libraries use ARCHIVE properties.
  548. if (!archiveArgs.GetDestination().empty()) {
  549. artifactsSpecified = true;
  550. }
  551. archiveGenerator = CreateInstallTargetGenerator(
  552. target, archiveArgs, false, helper.Makefile->GetBacktrace(),
  553. helper.GetArchiveDestination(&archiveArgs));
  554. }
  555. } break;
  556. case cmStateEnums::MODULE_LIBRARY: {
  557. // Modules use LIBRARY properties.
  558. if (!libraryArgs.GetDestination().empty()) {
  559. libraryGenerator = CreateInstallTargetGenerator(
  560. target, libraryArgs, false, helper.Makefile->GetBacktrace());
  561. libraryGenerator->SetNamelinkMode(namelinkMode);
  562. namelinkOnly =
  563. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  564. } else {
  565. status.SetError(
  566. cmStrCat("TARGETS given no LIBRARY DESTINATION for module "
  567. "target \"",
  568. target.GetName(), "\"."));
  569. return false;
  570. }
  571. } break;
  572. case cmStateEnums::OBJECT_LIBRARY: {
  573. // Objects use OBJECT properties.
  574. if (!objectArgs.GetDestination().empty()) {
  575. // Verify that we know where the objects are to install them.
  576. std::string reason;
  577. if (!helper.Makefile->GetGlobalGenerator()
  578. ->HasKnownObjectFileLocation(&reason)) {
  579. status.SetError(
  580. cmStrCat("TARGETS given OBJECT library \"", target.GetName(),
  581. "\" whose objects may not be installed", reason, "."));
  582. return false;
  583. }
  584. objectGenerator = CreateInstallTargetGenerator(
  585. target, objectArgs, false, helper.Makefile->GetBacktrace());
  586. } else {
  587. // Installing an OBJECT library without a destination transforms
  588. // it to an INTERFACE library. It installs no files but can be
  589. // exported.
  590. }
  591. } break;
  592. case cmStateEnums::EXECUTABLE: {
  593. if (target.IsAppBundleOnApple()) {
  594. // Application bundles use the BUNDLE properties.
  595. if (!bundleArgs.GetDestination().empty()) {
  596. bundleGenerator = CreateInstallTargetGenerator(
  597. target, bundleArgs, false, helper.Makefile->GetBacktrace());
  598. } else if (!runtimeArgs.GetDestination().empty()) {
  599. bool failure = false;
  600. if (helper.CheckCMP0006(failure)) {
  601. // For CMake 2.4 compatibility fallback to the RUNTIME
  602. // properties.
  603. bundleGenerator = CreateInstallTargetGenerator(
  604. target, runtimeArgs, false, helper.Makefile->GetBacktrace());
  605. } else if (failure) {
  606. return false;
  607. }
  608. }
  609. if (!bundleGenerator) {
  610. status.SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for "
  611. "MACOSX_BUNDLE executable target \"",
  612. target.GetName(), "\"."));
  613. return false;
  614. }
  615. } else {
  616. // Executables use the RUNTIME properties.
  617. if (!runtimeArgs.GetDestination().empty()) {
  618. artifactsSpecified = true;
  619. }
  620. runtimeGenerator = CreateInstallTargetGenerator(
  621. target, runtimeArgs, false, helper.Makefile->GetBacktrace(),
  622. helper.GetRuntimeDestination(&runtimeArgs));
  623. }
  624. // On DLL platforms an executable may also have an import
  625. // library. Install it to the archive destination if it
  626. // exists.
  627. if ((target.IsDLLPlatform() || target.IsAIX()) &&
  628. !archiveArgs.GetDestination().empty() &&
  629. target.IsExecutableWithExports()) {
  630. // The import library uses the ARCHIVE properties.
  631. artifactsSpecified = true;
  632. archiveGenerator = CreateInstallTargetGenerator(
  633. target, archiveArgs, true, helper.Makefile->GetBacktrace(), true);
  634. }
  635. } break;
  636. case cmStateEnums::INTERFACE_LIBRARY:
  637. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  638. // only effect of that is to make it exportable. It installs no
  639. // other files itself.
  640. default:
  641. // This should never happen due to the above type check.
  642. // Ignore the case.
  643. break;
  644. }
  645. // These well-known sets of files are installed *automatically* for
  646. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  647. // FRAMEWORK. For other target types or on other platforms, they are not
  648. // installed automatically and so we need to create install files
  649. // generators for them.
  650. bool createInstallGeneratorsForTargetFileSets = true;
  651. if (target.IsFrameworkOnApple()) {
  652. createInstallGeneratorsForTargetFileSets = false;
  653. }
  654. if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) {
  655. cmProp files = target.GetProperty("PRIVATE_HEADER");
  656. if (cmNonempty(files)) {
  657. std::vector<std::string> relFiles = cmExpandedList(*files);
  658. std::vector<std::string> absFiles;
  659. if (!helper.MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) {
  660. return false;
  661. }
  662. // Create the files install generator.
  663. if (!artifactsSpecified ||
  664. !privateHeaderArgs.GetDestination().empty()) {
  665. privateHeaderGenerator = CreateInstallFilesGenerator(
  666. helper.Makefile, absFiles, privateHeaderArgs, false,
  667. helper.GetIncludeDestination(&privateHeaderArgs));
  668. } else {
  669. std::ostringstream e;
  670. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  671. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  672. cmSystemTools::Message(e.str(), "Warning");
  673. }
  674. }
  675. files = target.GetProperty("PUBLIC_HEADER");
  676. if (cmNonempty(files)) {
  677. std::vector<std::string> relFiles = cmExpandedList(*files);
  678. std::vector<std::string> absFiles;
  679. if (!helper.MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) {
  680. return false;
  681. }
  682. // Create the files install generator.
  683. if (!artifactsSpecified ||
  684. !publicHeaderArgs.GetDestination().empty()) {
  685. publicHeaderGenerator = CreateInstallFilesGenerator(
  686. helper.Makefile, absFiles, publicHeaderArgs, false,
  687. helper.GetIncludeDestination(&publicHeaderArgs));
  688. } else {
  689. std::ostringstream e;
  690. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  691. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  692. cmSystemTools::Message(e.str(), "Warning");
  693. }
  694. }
  695. files = target.GetProperty("RESOURCE");
  696. if (cmNonempty(files)) {
  697. std::vector<std::string> relFiles = cmExpandedList(*files);
  698. std::vector<std::string> absFiles;
  699. if (!helper.MakeFilesFullPath("RESOURCE", relFiles, absFiles)) {
  700. return false;
  701. }
  702. // Create the files install generator.
  703. if (!resourceArgs.GetDestination().empty()) {
  704. resourceGenerator = CreateInstallFilesGenerator(
  705. helper.Makefile, absFiles, resourceArgs, false);
  706. } else {
  707. cmSystemTools::Message(
  708. cmStrCat("INSTALL TARGETS - target ", target.GetName(),
  709. " has RESOURCE files but no RESOURCE DESTINATION."),
  710. "Warning");
  711. }
  712. }
  713. }
  714. // Add this install rule to an export if one was specified.
  715. addTargetExport();
  716. // Keep track of whether we're installing anything in each category
  717. installsArchive = installsArchive || archiveGenerator;
  718. installsLibrary = installsLibrary || libraryGenerator;
  719. installsNamelink = installsNamelink || namelinkGenerator;
  720. installsRuntime = installsRuntime || runtimeGenerator;
  721. installsObject = installsObject || objectGenerator;
  722. installsFramework = installsFramework || frameworkGenerator;
  723. installsBundle = installsBundle || bundleGenerator;
  724. installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator;
  725. installsPublicHeader = installsPublicHeader || publicHeaderGenerator;
  726. installsResource = installsResource || resourceGenerator;
  727. helper.Makefile->AddInstallGenerator(std::move(archiveGenerator));
  728. helper.Makefile->AddInstallGenerator(std::move(libraryGenerator));
  729. helper.Makefile->AddInstallGenerator(std::move(namelinkGenerator));
  730. helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator));
  731. helper.Makefile->AddInstallGenerator(std::move(objectGenerator));
  732. helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator));
  733. helper.Makefile->AddInstallGenerator(std::move(bundleGenerator));
  734. helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator));
  735. helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator));
  736. helper.Makefile->AddInstallGenerator(std::move(resourceGenerator));
  737. }
  738. // Tell the global generator about any installation component names
  739. // specified
  740. if (installsArchive) {
  741. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  742. archiveArgs.GetComponent());
  743. }
  744. if (installsLibrary) {
  745. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  746. libraryArgs.GetComponent());
  747. }
  748. if (installsNamelink) {
  749. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  750. libraryArgs.GetNamelinkComponent());
  751. }
  752. if (installsRuntime) {
  753. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  754. runtimeArgs.GetComponent());
  755. }
  756. if (installsObject) {
  757. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  758. objectArgs.GetComponent());
  759. }
  760. if (installsFramework) {
  761. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  762. frameworkArgs.GetComponent());
  763. }
  764. if (installsBundle) {
  765. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  766. bundleArgs.GetComponent());
  767. }
  768. if (installsPrivateHeader) {
  769. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  770. privateHeaderArgs.GetComponent());
  771. }
  772. if (installsPublicHeader) {
  773. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  774. publicHeaderArgs.GetComponent());
  775. }
  776. if (installsResource) {
  777. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  778. resourceArgs.GetComponent());
  779. }
  780. return true;
  781. }
  782. bool HandleFilesMode(std::vector<std::string> const& args,
  783. cmExecutionStatus& status)
  784. {
  785. Helper helper(status);
  786. // This is the FILES mode.
  787. bool programs = (args[0] == "PROGRAMS");
  788. cmInstallCommandArguments ica(helper.DefaultComponentName);
  789. std::vector<std::string> files;
  790. ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files);
  791. std::vector<std::string> unknownArgs;
  792. ica.Parse(args, &unknownArgs);
  793. if (!unknownArgs.empty()) {
  794. // Unknown argument.
  795. status.SetError(
  796. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  797. return false;
  798. }
  799. std::string type = ica.GetType();
  800. if (!type.empty() && allowedTypes.count(type) == 0) {
  801. status.SetError(
  802. cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument."));
  803. return false;
  804. }
  805. const std::vector<std::string>& filesVector = files;
  806. // Check if there is something to do.
  807. if (filesVector.empty()) {
  808. return true;
  809. }
  810. if (!ica.GetRename().empty() && filesVector.size() > 1) {
  811. // The rename option works only with one file.
  812. status.SetError(
  813. cmStrCat(args[0], " given RENAME option with more than one file."));
  814. return false;
  815. }
  816. std::vector<std::string> absFiles;
  817. if (!helper.MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) {
  818. return false;
  819. }
  820. cmPolicies::PolicyStatus policyStatus =
  821. helper.Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  822. cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator();
  823. for (std::string const& file : filesVector) {
  824. if (gg->IsExportedTargetsFile(file)) {
  825. const char* modal = nullptr;
  826. std::ostringstream e;
  827. MessageType messageType = MessageType::AUTHOR_WARNING;
  828. switch (policyStatus) {
  829. case cmPolicies::WARN:
  830. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  831. modal = "should";
  832. case cmPolicies::OLD:
  833. break;
  834. case cmPolicies::REQUIRED_IF_USED:
  835. case cmPolicies::REQUIRED_ALWAYS:
  836. case cmPolicies::NEW:
  837. modal = "may";
  838. messageType = MessageType::FATAL_ERROR;
  839. }
  840. if (modal) {
  841. e << "The file\n " << file
  842. << "\nwas generated by the export() "
  843. "command. It "
  844. << modal
  845. << " not be installed with the "
  846. "install() command. Use the install(EXPORT) mechanism "
  847. "instead. See the cmake-packages(7) manual for more.\n";
  848. helper.Makefile->IssueMessage(messageType, e.str());
  849. if (messageType == MessageType::FATAL_ERROR) {
  850. return false;
  851. }
  852. }
  853. }
  854. }
  855. if (!ica.Finalize()) {
  856. return false;
  857. }
  858. if (!type.empty() && !ica.GetDestination().empty()) {
  859. status.SetError(cmStrCat(args[0],
  860. " given both TYPE and DESTINATION arguments. "
  861. "You may only specify one."));
  862. return false;
  863. }
  864. std::string destination = helper.GetDestinationForType(&ica, type);
  865. if (destination.empty()) {
  866. // A destination is required.
  867. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  868. return false;
  869. }
  870. // Create the files install generator.
  871. helper.Makefile->AddInstallGenerator(CreateInstallFilesGenerator(
  872. helper.Makefile, absFiles, ica, programs, destination));
  873. // Tell the global generator about any installation component names
  874. // specified.
  875. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  876. ica.GetComponent());
  877. return true;
  878. }
  879. bool HandleDirectoryMode(std::vector<std::string> const& args,
  880. cmExecutionStatus& status)
  881. {
  882. Helper helper(status);
  883. enum Doing
  884. {
  885. DoingNone,
  886. DoingDirs,
  887. DoingDestination,
  888. DoingPattern,
  889. DoingRegex,
  890. DoingPermsFile,
  891. DoingPermsDir,
  892. DoingPermsMatch,
  893. DoingConfigurations,
  894. DoingComponent,
  895. DoingType
  896. };
  897. Doing doing = DoingDirs;
  898. bool in_match_mode = false;
  899. bool optional = false;
  900. bool exclude_from_all = false;
  901. bool message_never = false;
  902. std::vector<std::string> dirs;
  903. const std::string* destination = nullptr;
  904. std::string permissions_file;
  905. std::string permissions_dir;
  906. std::vector<std::string> configurations;
  907. std::string component = helper.DefaultComponentName;
  908. std::string literal_args;
  909. std::string type;
  910. for (unsigned int i = 1; i < args.size(); ++i) {
  911. if (args[i] == "DESTINATION") {
  912. if (in_match_mode) {
  913. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  914. "\" after PATTERN or REGEX."));
  915. return false;
  916. }
  917. // Switch to setting the destination property.
  918. doing = DoingDestination;
  919. } else if (args[i] == "TYPE") {
  920. if (in_match_mode) {
  921. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  922. "\" after PATTERN or REGEX."));
  923. return false;
  924. }
  925. // Switch to setting the type.
  926. doing = DoingType;
  927. } else if (args[i] == "OPTIONAL") {
  928. if (in_match_mode) {
  929. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  930. "\" after PATTERN or REGEX."));
  931. return false;
  932. }
  933. // Mark the rule as optional.
  934. optional = true;
  935. doing = DoingNone;
  936. } else if (args[i] == "MESSAGE_NEVER") {
  937. if (in_match_mode) {
  938. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  939. "\" after PATTERN or REGEX."));
  940. return false;
  941. }
  942. // Mark the rule as quiet.
  943. message_never = true;
  944. doing = DoingNone;
  945. } else if (args[i] == "PATTERN") {
  946. // Switch to a new pattern match rule.
  947. doing = DoingPattern;
  948. in_match_mode = true;
  949. } else if (args[i] == "REGEX") {
  950. // Switch to a new regex match rule.
  951. doing = DoingRegex;
  952. in_match_mode = true;
  953. } else if (args[i] == "EXCLUDE") {
  954. // Add this property to the current match rule.
  955. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
  956. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  957. "\" before a PATTERN or REGEX is given."));
  958. return false;
  959. }
  960. literal_args += " EXCLUDE";
  961. doing = DoingNone;
  962. } else if (args[i] == "PERMISSIONS") {
  963. if (!in_match_mode) {
  964. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  965. "\" before a PATTERN or REGEX is given."));
  966. return false;
  967. }
  968. // Switch to setting the current match permissions property.
  969. literal_args += " PERMISSIONS";
  970. doing = DoingPermsMatch;
  971. } else if (args[i] == "FILE_PERMISSIONS") {
  972. if (in_match_mode) {
  973. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  974. "\" after PATTERN or REGEX."));
  975. return false;
  976. }
  977. // Switch to setting the file permissions property.
  978. doing = DoingPermsFile;
  979. } else if (args[i] == "DIRECTORY_PERMISSIONS") {
  980. if (in_match_mode) {
  981. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  982. "\" after PATTERN or REGEX."));
  983. return false;
  984. }
  985. // Switch to setting the directory permissions property.
  986. doing = DoingPermsDir;
  987. } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
  988. if (in_match_mode) {
  989. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  990. "\" after PATTERN or REGEX."));
  991. return false;
  992. }
  993. // Add this option literally.
  994. literal_args += " USE_SOURCE_PERMISSIONS";
  995. doing = DoingNone;
  996. } else if (args[i] == "FILES_MATCHING") {
  997. if (in_match_mode) {
  998. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  999. "\" after PATTERN or REGEX."));
  1000. return false;
  1001. }
  1002. // Add this option literally.
  1003. literal_args += " FILES_MATCHING";
  1004. doing = DoingNone;
  1005. } else if (args[i] == "CONFIGURATIONS") {
  1006. if (in_match_mode) {
  1007. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1008. "\" after PATTERN or REGEX."));
  1009. return false;
  1010. }
  1011. // Switch to setting the configurations property.
  1012. doing = DoingConfigurations;
  1013. } else if (args[i] == "COMPONENT") {
  1014. if (in_match_mode) {
  1015. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1016. "\" after PATTERN or REGEX."));
  1017. return false;
  1018. }
  1019. // Switch to setting the component property.
  1020. doing = DoingComponent;
  1021. } else if (args[i] == "EXCLUDE_FROM_ALL") {
  1022. if (in_match_mode) {
  1023. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1024. "\" after PATTERN or REGEX."));
  1025. return false;
  1026. }
  1027. exclude_from_all = true;
  1028. doing = DoingNone;
  1029. } else if (doing == DoingDirs) {
  1030. // Convert this directory to a full path.
  1031. std::string dir = args[i];
  1032. std::string::size_type gpos = cmGeneratorExpression::Find(dir);
  1033. if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
  1034. dir =
  1035. cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', args[i]);
  1036. }
  1037. // Make sure the name is a directory.
  1038. if (cmSystemTools::FileExists(dir) &&
  1039. !cmSystemTools::FileIsDirectory(dir)) {
  1040. status.SetError(cmStrCat(args[0], " given non-directory \"", args[i],
  1041. "\" to install."));
  1042. return false;
  1043. }
  1044. // Store the directory for installation.
  1045. dirs.push_back(std::move(dir));
  1046. } else if (doing == DoingConfigurations) {
  1047. configurations.push_back(args[i]);
  1048. } else if (doing == DoingDestination) {
  1049. destination = &args[i];
  1050. doing = DoingNone;
  1051. } else if (doing == DoingType) {
  1052. if (allowedTypes.count(args[i]) == 0) {
  1053. status.SetError(cmStrCat(args[0], " given non-type \"", args[i],
  1054. "\" with TYPE argument."));
  1055. return false;
  1056. }
  1057. type = args[i];
  1058. doing = DoingNone;
  1059. } else if (doing == DoingPattern) {
  1060. // Convert the pattern to a regular expression. Require a
  1061. // leading slash and trailing end-of-string in the matched
  1062. // string to make sure the pattern matches only whole file
  1063. // names.
  1064. literal_args += " REGEX \"/";
  1065. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1066. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1067. literal_args += regex;
  1068. literal_args += "$\"";
  1069. doing = DoingNone;
  1070. } else if (doing == DoingRegex) {
  1071. literal_args += " REGEX \"";
  1072. // Match rules are case-insensitive on some platforms.
  1073. #if defined(_WIN32) || defined(__APPLE__)
  1074. std::string regex = cmSystemTools::LowerCase(args[i]);
  1075. #else
  1076. std::string regex = args[i];
  1077. #endif
  1078. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1079. literal_args += regex;
  1080. literal_args += "\"";
  1081. doing = DoingNone;
  1082. } else if (doing == DoingComponent) {
  1083. component = args[i];
  1084. doing = DoingNone;
  1085. } else if (doing == DoingPermsFile) {
  1086. // Check the requested permission.
  1087. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1088. permissions_file)) {
  1089. status.SetError(cmStrCat(args[0], " given invalid file permission \"",
  1090. args[i], "\"."));
  1091. return false;
  1092. }
  1093. } else if (doing == DoingPermsDir) {
  1094. // Check the requested permission.
  1095. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1096. permissions_dir)) {
  1097. status.SetError(cmStrCat(
  1098. args[0], " given invalid directory permission \"", args[i], "\"."));
  1099. return false;
  1100. }
  1101. } else if (doing == DoingPermsMatch) {
  1102. // Check the requested permission.
  1103. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1104. literal_args)) {
  1105. status.SetError(
  1106. cmStrCat(args[0], " given invalid permission \"", args[i], "\"."));
  1107. return false;
  1108. }
  1109. } else {
  1110. // Unknown argument.
  1111. status.SetError(
  1112. cmStrCat(args[0], " given unknown argument \"", args[i], "\"."));
  1113. return false;
  1114. }
  1115. }
  1116. // Support installing an empty directory.
  1117. if (dirs.empty() && destination) {
  1118. dirs.emplace_back();
  1119. }
  1120. // Check if there is something to do.
  1121. if (dirs.empty()) {
  1122. return true;
  1123. }
  1124. std::string destinationStr;
  1125. if (!destination) {
  1126. if (type.empty()) {
  1127. // A destination is required.
  1128. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1129. return false;
  1130. }
  1131. destinationStr = helper.GetDestinationForType(nullptr, type);
  1132. destination = &destinationStr;
  1133. } else if (!type.empty()) {
  1134. status.SetError(cmStrCat(args[0],
  1135. " given both TYPE and DESTINATION "
  1136. "arguments. You may only specify one."));
  1137. return false;
  1138. }
  1139. cmInstallGenerator::MessageLevel message =
  1140. cmInstallGenerator::SelectMessageLevel(helper.Makefile, message_never);
  1141. // Create the directory install generator.
  1142. helper.Makefile->AddInstallGenerator(
  1143. cm::make_unique<cmInstallDirectoryGenerator>(
  1144. dirs, *destination, permissions_file, permissions_dir, configurations,
  1145. component, message, exclude_from_all, literal_args, optional));
  1146. // Tell the global generator about any installation component names
  1147. // specified.
  1148. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component);
  1149. return true;
  1150. }
  1151. bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
  1152. cmExecutionStatus& status)
  1153. {
  1154. #ifndef CMAKE_BOOTSTRAP
  1155. Helper helper(status);
  1156. // This is the EXPORT mode.
  1157. cmInstallCommandArguments ica(helper.DefaultComponentName);
  1158. std::string exp;
  1159. std::string name_space;
  1160. bool exportOld = false;
  1161. std::string filename;
  1162. ica.Bind("EXPORT_ANDROID_MK"_s, exp);
  1163. ica.Bind("NAMESPACE"_s, name_space);
  1164. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1165. ica.Bind("FILE"_s, filename);
  1166. std::vector<std::string> unknownArgs;
  1167. ica.Parse(args, &unknownArgs);
  1168. if (!unknownArgs.empty()) {
  1169. // Unknown argument.
  1170. status.SetError(
  1171. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1172. return false;
  1173. }
  1174. if (!ica.Finalize()) {
  1175. return false;
  1176. }
  1177. // Make sure there is a destination.
  1178. if (ica.GetDestination().empty()) {
  1179. // A destination is required.
  1180. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1181. return false;
  1182. }
  1183. // Check the file name.
  1184. std::string fname = filename;
  1185. if (fname.find_first_of(":/\\") != std::string::npos) {
  1186. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1187. fname,
  1188. "\". The FILE argument may not contain a path. "
  1189. "Specify the path in the DESTINATION argument."));
  1190. return false;
  1191. }
  1192. // Check the file extension.
  1193. if (!fname.empty() &&
  1194. cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
  1195. status.SetError(cmStrCat(
  1196. args[0], " given invalid export file name \"", fname,
  1197. R"(". The FILE argument must specify a name ending in ".mk".)"));
  1198. return false;
  1199. }
  1200. if (fname.find_first_of(":/\\") != std::string::npos) {
  1201. status.SetError(
  1202. cmStrCat(args[0], " given export name \"", exp,
  1203. "\". "
  1204. "This name cannot be safely converted to a file name. "
  1205. "Specify a different export name or use the FILE option to set "
  1206. "a file name explicitly."));
  1207. return false;
  1208. }
  1209. // Use the default name
  1210. if (fname.empty()) {
  1211. fname = "Android.mk";
  1212. }
  1213. cmExportSet& exportSet =
  1214. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1215. cmInstallGenerator::MessageLevel message =
  1216. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  1217. // Create the export install generator.
  1218. helper.Makefile->AddInstallGenerator(
  1219. cm::make_unique<cmInstallExportGenerator>(
  1220. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  1221. ica.GetConfigurations(), ica.GetComponent(), message,
  1222. ica.GetExcludeFromAll(), fname, name_space, exportOld, true));
  1223. return true;
  1224. #else
  1225. static_cast<void>(args);
  1226. status.SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake");
  1227. return false;
  1228. #endif
  1229. }
  1230. bool HandleExportMode(std::vector<std::string> const& args,
  1231. cmExecutionStatus& status)
  1232. {
  1233. Helper helper(status);
  1234. // This is the EXPORT mode.
  1235. cmInstallCommandArguments ica(helper.DefaultComponentName);
  1236. std::string exp;
  1237. std::string name_space;
  1238. bool exportOld = false;
  1239. std::string filename;
  1240. ica.Bind("EXPORT"_s, exp);
  1241. ica.Bind("NAMESPACE"_s, name_space);
  1242. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1243. ica.Bind("FILE"_s, filename);
  1244. std::vector<std::string> unknownArgs;
  1245. ica.Parse(args, &unknownArgs);
  1246. if (!unknownArgs.empty()) {
  1247. // Unknown argument.
  1248. status.SetError(
  1249. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1250. return false;
  1251. }
  1252. if (!ica.Finalize()) {
  1253. return false;
  1254. }
  1255. // Make sure there is a destination.
  1256. if (ica.GetDestination().empty()) {
  1257. // A destination is required.
  1258. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1259. return false;
  1260. }
  1261. // Check the file name.
  1262. std::string fname = filename;
  1263. if (fname.find_first_of(":/\\") != std::string::npos) {
  1264. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1265. fname,
  1266. "\". "
  1267. "The FILE argument may not contain a path. "
  1268. "Specify the path in the DESTINATION argument."));
  1269. return false;
  1270. }
  1271. // Check the file extension.
  1272. if (!fname.empty() &&
  1273. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
  1274. status.SetError(
  1275. cmStrCat(args[0], " given invalid export file name \"", fname,
  1276. "\". "
  1277. "The FILE argument must specify a name ending in \".cmake\"."));
  1278. return false;
  1279. }
  1280. // Construct the file name.
  1281. if (fname.empty()) {
  1282. fname = cmStrCat(exp, ".cmake");
  1283. if (fname.find_first_of(":/\\") != std::string::npos) {
  1284. status.SetError(cmStrCat(
  1285. args[0], " given export name \"", exp,
  1286. "\". "
  1287. "This name cannot be safely converted to a file name. "
  1288. "Specify a different export name or use the FILE option to set "
  1289. "a file name explicitly."));
  1290. return false;
  1291. }
  1292. }
  1293. cmExportSet& exportSet =
  1294. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1295. if (exportOld) {
  1296. for (auto const& te : exportSet.GetTargetExports()) {
  1297. cmTarget* tgt =
  1298. helper.Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
  1299. const bool newCMP0022Behavior =
  1300. (tgt && tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  1301. tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
  1302. if (!newCMP0022Behavior) {
  1303. status.SetError(cmStrCat(
  1304. "INSTALL(EXPORT) given keyword \""
  1305. "EXPORT_LINK_INTERFACE_LIBRARIES\", but target \"",
  1306. te->TargetName, "\" does not have policy CMP0022 set to NEW."));
  1307. return false;
  1308. }
  1309. }
  1310. }
  1311. cmInstallGenerator::MessageLevel message =
  1312. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  1313. // Create the export install generator.
  1314. helper.Makefile->AddInstallGenerator(
  1315. cm::make_unique<cmInstallExportGenerator>(
  1316. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  1317. ica.GetConfigurations(), ica.GetComponent(), message,
  1318. ica.GetExcludeFromAll(), fname, name_space, exportOld, false));
  1319. return true;
  1320. }
  1321. bool Helper::MakeFilesFullPath(const char* modeName,
  1322. const std::vector<std::string>& relFiles,
  1323. std::vector<std::string>& absFiles)
  1324. {
  1325. for (std::string const& relFile : relFiles) {
  1326. std::string file = relFile;
  1327. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  1328. if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
  1329. file =
  1330. cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', relFile);
  1331. }
  1332. // Make sure the file is not a directory.
  1333. if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) {
  1334. this->SetError(
  1335. cmStrCat(modeName, " given directory \"", relFile, "\" to install."));
  1336. return false;
  1337. }
  1338. // Store the file for installation.
  1339. absFiles.push_back(std::move(file));
  1340. }
  1341. return true;
  1342. }
  1343. bool Helper::CheckCMP0006(bool& failure)
  1344. {
  1345. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
  1346. case cmPolicies::WARN:
  1347. this->Makefile->IssueMessage(
  1348. MessageType::AUTHOR_WARNING,
  1349. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006));
  1350. CM_FALLTHROUGH;
  1351. case cmPolicies::OLD:
  1352. // OLD behavior is to allow compatibility
  1353. return true;
  1354. case cmPolicies::NEW:
  1355. // NEW behavior is to disallow compatibility
  1356. break;
  1357. case cmPolicies::REQUIRED_IF_USED:
  1358. case cmPolicies::REQUIRED_ALWAYS:
  1359. failure = true;
  1360. this->Makefile->IssueMessage(
  1361. MessageType::FATAL_ERROR,
  1362. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006));
  1363. break;
  1364. }
  1365. return false;
  1366. }
  1367. std::string Helper::GetDestination(const cmInstallCommandArguments* args,
  1368. const std::string& varName,
  1369. const std::string& guess)
  1370. {
  1371. if (args && !args->GetDestination().empty()) {
  1372. return args->GetDestination();
  1373. }
  1374. std::string val = this->Makefile->GetSafeDefinition(varName);
  1375. if (!val.empty()) {
  1376. return val;
  1377. }
  1378. return guess;
  1379. }
  1380. std::string Helper::GetRuntimeDestination(
  1381. const cmInstallCommandArguments* args)
  1382. {
  1383. return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin");
  1384. }
  1385. std::string Helper::GetSbinDestination(const cmInstallCommandArguments* args)
  1386. {
  1387. return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin");
  1388. }
  1389. std::string Helper::GetArchiveDestination(
  1390. const cmInstallCommandArguments* args)
  1391. {
  1392. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  1393. }
  1394. std::string Helper::GetLibraryDestination(
  1395. const cmInstallCommandArguments* args)
  1396. {
  1397. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  1398. }
  1399. std::string Helper::GetIncludeDestination(
  1400. const cmInstallCommandArguments* args)
  1401. {
  1402. return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include");
  1403. }
  1404. std::string Helper::GetSysconfDestination(
  1405. const cmInstallCommandArguments* args)
  1406. {
  1407. return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc");
  1408. }
  1409. std::string Helper::GetSharedStateDestination(
  1410. const cmInstallCommandArguments* args)
  1411. {
  1412. return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com");
  1413. }
  1414. std::string Helper::GetLocalStateDestination(
  1415. const cmInstallCommandArguments* args)
  1416. {
  1417. return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var");
  1418. }
  1419. std::string Helper::GetRunStateDestination(
  1420. const cmInstallCommandArguments* args)
  1421. {
  1422. return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR",
  1423. this->GetLocalStateDestination(nullptr) +
  1424. "/run");
  1425. }
  1426. std::string Helper::GetDataRootDestination(
  1427. const cmInstallCommandArguments* args)
  1428. {
  1429. return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share");
  1430. }
  1431. std::string Helper::GetDataDestination(const cmInstallCommandArguments* args)
  1432. {
  1433. return this->GetDestination(args, "CMAKE_INSTALL_DATADIR",
  1434. this->GetDataRootDestination(nullptr));
  1435. }
  1436. std::string Helper::GetInfoDestination(const cmInstallCommandArguments* args)
  1437. {
  1438. return this->GetDestination(args, "CMAKE_INSTALL_INFODIR",
  1439. this->GetDataRootDestination(nullptr) + "/info");
  1440. }
  1441. std::string Helper::GetLocaleDestination(const cmInstallCommandArguments* args)
  1442. {
  1443. return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR",
  1444. this->GetDataRootDestination(nullptr) +
  1445. "/locale");
  1446. }
  1447. std::string Helper::GetManDestination(const cmInstallCommandArguments* args)
  1448. {
  1449. return this->GetDestination(args, "CMAKE_INSTALL_MANDIR",
  1450. this->GetDataRootDestination(nullptr) + "/man");
  1451. }
  1452. std::string Helper::GetDocDestination(const cmInstallCommandArguments* args)
  1453. {
  1454. return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR",
  1455. this->GetDataRootDestination(nullptr) + "/doc");
  1456. }
  1457. std::string Helper::GetDestinationForType(
  1458. const cmInstallCommandArguments* args, const std::string& type)
  1459. {
  1460. if (args && !args->GetDestination().empty()) {
  1461. return args->GetDestination();
  1462. }
  1463. if (type == "BIN") {
  1464. return this->GetRuntimeDestination(nullptr);
  1465. }
  1466. if (type == "SBIN") {
  1467. return this->GetSbinDestination(nullptr);
  1468. }
  1469. if (type == "SYSCONF") {
  1470. return this->GetSysconfDestination(nullptr);
  1471. }
  1472. if (type == "SHAREDSTATE") {
  1473. return this->GetSharedStateDestination(nullptr);
  1474. }
  1475. if (type == "LOCALSTATE") {
  1476. return this->GetLocalStateDestination(nullptr);
  1477. }
  1478. if (type == "RUNSTATE") {
  1479. return this->GetRunStateDestination(nullptr);
  1480. }
  1481. if (type == "LIB") {
  1482. return this->GetLibraryDestination(nullptr);
  1483. }
  1484. if (type == "INCLUDE") {
  1485. return this->GetIncludeDestination(nullptr);
  1486. }
  1487. if (type == "DATA") {
  1488. return this->GetDataDestination(nullptr);
  1489. }
  1490. if (type == "INFO") {
  1491. return this->GetInfoDestination(nullptr);
  1492. }
  1493. if (type == "LOCALE") {
  1494. return this->GetLocaleDestination(nullptr);
  1495. }
  1496. if (type == "MAN") {
  1497. return this->GetManDestination(nullptr);
  1498. }
  1499. if (type == "DOC") {
  1500. return this->GetDocDestination(nullptr);
  1501. }
  1502. return "";
  1503. }
  1504. } // namespace
  1505. bool cmInstallCommand(std::vector<std::string> const& args,
  1506. cmExecutionStatus& status)
  1507. {
  1508. // Allow calling with no arguments so that arguments may be built up
  1509. // using a variable that may be left empty.
  1510. if (args.empty()) {
  1511. return true;
  1512. }
  1513. // Enable the install target.
  1514. status.GetMakefile().GetGlobalGenerator()->EnableInstallTarget();
  1515. static cmSubcommandTable const subcommand{
  1516. { "SCRIPT"_s, HandleScriptMode },
  1517. { "CODE"_s, HandleScriptMode },
  1518. { "TARGETS"_s, HandleTargetsMode },
  1519. { "FILES"_s, HandleFilesMode },
  1520. { "PROGRAMS"_s, HandleFilesMode },
  1521. { "DIRECTORY"_s, HandleDirectoryMode },
  1522. { "EXPORT"_s, HandleExportMode },
  1523. { "EXPORT_ANDROID_MK"_s, HandleExportAndroidMKMode },
  1524. };
  1525. return subcommand(args[0], args, status);
  1526. }