cmInstallCommand.cxx 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmInstallCommand.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <cstddef>
  7. #include <iterator>
  8. #include <map>
  9. #include <set>
  10. #include <sstream>
  11. #include <utility>
  12. #include <cm/memory>
  13. #include <cm/optional>
  14. #include <cm/string_view>
  15. #include <cmext/string_view>
  16. #include "cmsys/Glob.hxx"
  17. #include "cmArgumentParser.h"
  18. #include "cmArgumentParserTypes.h"
  19. #include "cmCMakePath.h"
  20. #include "cmExecutionStatus.h"
  21. #include "cmExperimental.h"
  22. #include "cmExportSet.h"
  23. #include "cmGeneratorExpression.h"
  24. #include "cmGlobalGenerator.h"
  25. #include "cmInstallAndroidMKExportGenerator.h"
  26. #include "cmInstallCMakeConfigExportGenerator.h"
  27. #include "cmInstallCommandArguments.h"
  28. #include "cmInstallCxxModuleBmiGenerator.h"
  29. #include "cmInstallDirectoryGenerator.h"
  30. #include "cmInstallFileSetGenerator.h"
  31. #include "cmInstallFilesGenerator.h"
  32. #include "cmInstallGenerator.h"
  33. #include "cmInstallGetRuntimeDependenciesGenerator.h"
  34. #include "cmInstallImportedRuntimeArtifactsGenerator.h"
  35. #include "cmInstallPackageInfoExportGenerator.h"
  36. #include "cmInstallRuntimeDependencySet.h"
  37. #include "cmInstallRuntimeDependencySetGenerator.h"
  38. #include "cmInstallScriptGenerator.h"
  39. #include "cmInstallTargetGenerator.h"
  40. #include "cmList.h"
  41. #include "cmMakefile.h"
  42. #include "cmMessageType.h"
  43. #include "cmPackageInfoArguments.h"
  44. #include "cmPolicies.h"
  45. #include "cmRange.h"
  46. #include "cmRuntimeDependencyArchive.h"
  47. #include "cmStateTypes.h"
  48. #include "cmStringAlgorithms.h"
  49. #include "cmSubcommandTable.h"
  50. #include "cmSystemTools.h"
  51. #include "cmTarget.h"
  52. #include "cmTargetExport.h"
  53. #include "cmValue.h"
  54. class cmListFileBacktrace;
  55. namespace {
  56. struct RuntimeDependenciesArgs
  57. {
  58. ArgumentParser::MaybeEmpty<std::vector<std::string>> Directories;
  59. ArgumentParser::MaybeEmpty<std::vector<std::string>> PreIncludeRegexes;
  60. ArgumentParser::MaybeEmpty<std::vector<std::string>> PreExcludeRegexes;
  61. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeRegexes;
  62. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeRegexes;
  63. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeFiles;
  64. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeFiles;
  65. };
  66. auto const RuntimeDependenciesArgHelper =
  67. cmArgumentParser<RuntimeDependenciesArgs>{}
  68. .Bind("DIRECTORIES"_s, &RuntimeDependenciesArgs::Directories)
  69. .Bind("PRE_INCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreIncludeRegexes)
  70. .Bind("PRE_EXCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreExcludeRegexes)
  71. .Bind("POST_INCLUDE_REGEXES"_s,
  72. &RuntimeDependenciesArgs::PostIncludeRegexes)
  73. .Bind("POST_EXCLUDE_REGEXES"_s,
  74. &RuntimeDependenciesArgs::PostExcludeRegexes)
  75. .Bind("POST_INCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostIncludeFiles)
  76. .Bind("POST_EXCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostExcludeFiles);
  77. class Helper
  78. {
  79. public:
  80. Helper(cmExecutionStatus& status)
  81. : Status(status)
  82. , Makefile(&status.GetMakefile())
  83. {
  84. this->DefaultComponentName = this->Makefile->GetSafeDefinition(
  85. "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
  86. if (this->DefaultComponentName.empty()) {
  87. this->DefaultComponentName = "Unspecified";
  88. }
  89. }
  90. void SetError(std::string const& err) { this->Status.SetError(err); }
  91. bool MakeFilesFullPath(char const* modeName,
  92. std::vector<std::string> const& relFiles,
  93. std::vector<std::string>& absFiles);
  94. bool MakeFilesFullPath(char const* modeName, std::string const& basePath,
  95. std::vector<std::string> const& relFiles,
  96. std::vector<std::string>& absFiles);
  97. std::string GetDestination(cmInstallCommandArguments const* args,
  98. std::string const& varName,
  99. std::string const& guess) const;
  100. std::string GetRuntimeDestination(
  101. cmInstallCommandArguments const* args) const;
  102. std::string GetSbinDestination(cmInstallCommandArguments const* args) const;
  103. std::string GetArchiveDestination(
  104. cmInstallCommandArguments const* args) const;
  105. std::string GetLibraryDestination(
  106. cmInstallCommandArguments const* args) const;
  107. std::string GetCxxModulesBmiDestination(
  108. cmInstallCommandArguments const* args) const;
  109. std::string GetIncludeDestination(
  110. cmInstallCommandArguments const* args) const;
  111. std::string GetSysconfDestination(
  112. cmInstallCommandArguments const* args) const;
  113. std::string GetSharedStateDestination(
  114. cmInstallCommandArguments const* args) const;
  115. std::string GetLocalStateDestination(
  116. cmInstallCommandArguments const* args) const;
  117. std::string GetRunStateDestination(
  118. cmInstallCommandArguments const* args) const;
  119. std::string GetDataRootDestination(
  120. cmInstallCommandArguments const* args) const;
  121. std::string GetDataDestination(cmInstallCommandArguments const* args) const;
  122. std::string GetInfoDestination(cmInstallCommandArguments const* args) const;
  123. std::string GetLocaleDestination(
  124. cmInstallCommandArguments const* args) const;
  125. std::string GetManDestination(cmInstallCommandArguments const* args) const;
  126. std::string GetDocDestination(cmInstallCommandArguments const* args) const;
  127. std::string GetProgramExecutablesDestination(
  128. cmInstallCommandArguments const* args) const;
  129. std::string GetDestinationForType(cmInstallCommandArguments const* args,
  130. std::string const& type) const;
  131. cmExecutionStatus& Status;
  132. cmMakefile* Makefile;
  133. std::string DefaultComponentName;
  134. };
  135. std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator(
  136. cmTarget& target, cmInstallCommandArguments const& args, bool impLib,
  137. cmListFileBacktrace const& backtrace, std::string const& destination,
  138. bool forceOpt = false, bool namelink = false)
  139. {
  140. cmInstallGenerator::MessageLevel message =
  141. cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
  142. target.SetHaveInstallRule(true);
  143. std::string const& component =
  144. namelink ? args.GetNamelinkComponent() : args.GetComponent();
  145. auto g = cm::make_unique<cmInstallTargetGenerator>(
  146. target.GetName(), destination, impLib, args.GetPermissions(),
  147. args.GetConfigurations(), component, message, args.GetExcludeFromAll(),
  148. args.GetOptional() || forceOpt, backtrace);
  149. target.AddInstallGenerator(g.get());
  150. return g;
  151. }
  152. std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator(
  153. cmTarget& target, cmInstallCommandArguments const& args, bool impLib,
  154. cmListFileBacktrace const& backtrace, bool forceOpt = false,
  155. bool namelink = false)
  156. {
  157. return CreateInstallTargetGenerator(target, args, impLib, backtrace,
  158. args.GetDestination(), forceOpt,
  159. namelink);
  160. }
  161. std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator(
  162. cmMakefile* mf, std::vector<std::string> const& absFiles,
  163. cmInstallCommandArguments const& args, bool programs,
  164. std::string const& destination)
  165. {
  166. cmInstallGenerator::MessageLevel message =
  167. cmInstallGenerator::SelectMessageLevel(mf);
  168. return cm::make_unique<cmInstallFilesGenerator>(
  169. absFiles, destination, programs, args.GetPermissions(),
  170. args.GetConfigurations(), args.GetComponent(), message,
  171. args.GetExcludeFromAll(), args.GetRename(), args.GetOptional(),
  172. mf->GetBacktrace());
  173. }
  174. std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator(
  175. cmMakefile* mf, std::vector<std::string> const& absFiles,
  176. cmInstallCommandArguments const& args, bool programs)
  177. {
  178. return CreateInstallFilesGenerator(mf, absFiles, args, programs,
  179. args.GetDestination());
  180. }
  181. std::unique_ptr<cmInstallFileSetGenerator> CreateInstallFileSetGenerator(
  182. Helper& helper, cmTarget& target, cmFileSetDestinations dests,
  183. cmInstallCommandFileSetArguments const& args)
  184. {
  185. cmInstallGenerator::MessageLevel message =
  186. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  187. return cm::make_unique<cmInstallFileSetGenerator>(
  188. target.GetName(), args.GetFileSet(), std::move(dests),
  189. args.GetPermissions(), args.GetConfigurations(), args.GetComponent(),
  190. message, args.GetExcludeFromAll(), args.GetOptional(),
  191. helper.Makefile->GetBacktrace());
  192. }
  193. void AddInstallRuntimeDependenciesGenerator(
  194. Helper& helper, cmInstallRuntimeDependencySet* runtimeDependencySet,
  195. cmInstallCommandArguments const& runtimeArgs,
  196. cmInstallCommandArguments const& libraryArgs,
  197. cmInstallCommandArguments const& frameworkArgs,
  198. RuntimeDependenciesArgs runtimeDependenciesArgs, bool& installsRuntime,
  199. bool& installsLibrary, bool& installsFramework)
  200. {
  201. bool dllPlatform =
  202. !helper.Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
  203. bool apple =
  204. helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") == "Darwin";
  205. auto const& runtimeDependenciesArgsRef =
  206. dllPlatform ? runtimeArgs : libraryArgs;
  207. std::vector<std::string> configurations =
  208. runtimeDependenciesArgsRef.GetConfigurations();
  209. if (apple) {
  210. std::copy(frameworkArgs.GetConfigurations().begin(),
  211. frameworkArgs.GetConfigurations().end(),
  212. std::back_inserter(configurations));
  213. }
  214. // Create file(GET_RUNTIME_DEPENDENCIES) generator.
  215. auto getRuntimeDependenciesGenerator =
  216. cm::make_unique<cmInstallGetRuntimeDependenciesGenerator>(
  217. runtimeDependencySet, std::move(runtimeDependenciesArgs.Directories),
  218. std::move(runtimeDependenciesArgs.PreIncludeRegexes),
  219. std::move(runtimeDependenciesArgs.PreExcludeRegexes),
  220. std::move(runtimeDependenciesArgs.PostIncludeRegexes),
  221. std::move(runtimeDependenciesArgs.PostExcludeRegexes),
  222. std::move(runtimeDependenciesArgs.PostIncludeFiles),
  223. std::move(runtimeDependenciesArgs.PostExcludeFiles),
  224. runtimeDependenciesArgsRef.GetComponent(),
  225. apple ? frameworkArgs.GetComponent() : "", true, "_CMAKE_DEPS",
  226. "_CMAKE_RPATH", configurations,
  227. cmInstallGenerator::SelectMessageLevel(helper.Makefile),
  228. runtimeDependenciesArgsRef.GetExcludeFromAll() &&
  229. (apple ? frameworkArgs.GetExcludeFromAll() : true),
  230. helper.Makefile->GetBacktrace());
  231. helper.Makefile->AddInstallGenerator(
  232. std::move(getRuntimeDependenciesGenerator));
  233. // Create the library dependencies generator.
  234. auto libraryRuntimeDependenciesGenerator =
  235. cm::make_unique<cmInstallRuntimeDependencySetGenerator>(
  236. cmInstallRuntimeDependencySetGenerator::DependencyType::Library,
  237. runtimeDependencySet, std::vector<std::string>{}, true, std::string{},
  238. true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP",
  239. dllPlatform ? helper.GetRuntimeDestination(&runtimeArgs)
  240. : helper.GetLibraryDestination(&libraryArgs),
  241. runtimeDependenciesArgsRef.GetConfigurations(),
  242. runtimeDependenciesArgsRef.GetComponent(),
  243. runtimeDependenciesArgsRef.GetPermissions(),
  244. cmInstallGenerator::SelectMessageLevel(helper.Makefile),
  245. runtimeDependenciesArgsRef.GetExcludeFromAll(),
  246. helper.Makefile->GetBacktrace());
  247. helper.Makefile->AddInstallGenerator(
  248. std::move(libraryRuntimeDependenciesGenerator));
  249. if (dllPlatform) {
  250. installsRuntime = true;
  251. } else {
  252. installsLibrary = true;
  253. }
  254. if (apple) {
  255. // Create the framework dependencies generator.
  256. auto frameworkRuntimeDependenciesGenerator =
  257. cm::make_unique<cmInstallRuntimeDependencySetGenerator>(
  258. cmInstallRuntimeDependencySetGenerator::DependencyType::Framework,
  259. runtimeDependencySet, std::vector<std::string>{}, true, std::string{},
  260. true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP",
  261. frameworkArgs.GetDestination(), frameworkArgs.GetConfigurations(),
  262. frameworkArgs.GetComponent(), frameworkArgs.GetPermissions(),
  263. cmInstallGenerator::SelectMessageLevel(helper.Makefile),
  264. frameworkArgs.GetExcludeFromAll(), helper.Makefile->GetBacktrace());
  265. helper.Makefile->AddInstallGenerator(
  266. std::move(frameworkRuntimeDependenciesGenerator));
  267. installsFramework = true;
  268. }
  269. }
  270. std::set<std::string> const allowedTypes{
  271. "BIN", "SBIN", "LIB", "INCLUDE", "SYSCONF",
  272. "SHAREDSTATE", "LOCALSTATE", "RUNSTATE", "DATA", "INFO",
  273. "LOCALE", "MAN", "DOC", "LIBEXEC",
  274. };
  275. template <typename T>
  276. bool AddBundleExecutable(Helper& helper,
  277. cmInstallRuntimeDependencySet* runtimeDependencySet,
  278. T&& bundleExecutable)
  279. {
  280. if (!runtimeDependencySet->AddBundleExecutable(bundleExecutable)) {
  281. helper.SetError(
  282. "A runtime dependency set may only have one bundle executable.");
  283. return false;
  284. }
  285. return true;
  286. }
  287. bool HandleScriptMode(std::vector<std::string> const& args,
  288. cmExecutionStatus& status)
  289. {
  290. Helper helper(status);
  291. std::string component = helper.DefaultComponentName;
  292. int componentCount = 0;
  293. bool doing_script = false;
  294. bool doing_code = false;
  295. bool exclude_from_all = false;
  296. bool all_components = false;
  297. // Scan the args once for COMPONENT. Only allow one.
  298. //
  299. for (size_t i = 0; i < args.size(); ++i) {
  300. if (args[i] == "COMPONENT" && i + 1 < args.size()) {
  301. ++componentCount;
  302. ++i;
  303. component = args[i];
  304. }
  305. if (args[i] == "EXCLUDE_FROM_ALL") {
  306. exclude_from_all = true;
  307. } else if (args[i] == "ALL_COMPONENTS") {
  308. all_components = true;
  309. }
  310. }
  311. if (componentCount > 1) {
  312. status.SetError("given more than one COMPONENT for the SCRIPT or CODE "
  313. "signature of the INSTALL command. "
  314. "Use multiple INSTALL commands with one COMPONENT each.");
  315. return false;
  316. }
  317. if (all_components && componentCount == 1) {
  318. status.SetError("ALL_COMPONENTS and COMPONENT are mutually exclusive");
  319. return false;
  320. }
  321. // Scan the args again, this time adding install generators each time we
  322. // encounter a SCRIPT or CODE arg:
  323. //
  324. for (std::string const& arg : args) {
  325. if (arg == "SCRIPT") {
  326. doing_script = true;
  327. doing_code = false;
  328. } else if (arg == "CODE") {
  329. doing_script = false;
  330. doing_code = true;
  331. } else if (arg == "COMPONENT") {
  332. doing_script = false;
  333. doing_code = false;
  334. } else if (doing_script) {
  335. doing_script = false;
  336. std::string script = arg;
  337. if (!cmHasLiteralPrefix(script, "$<INSTALL_PREFIX>")) {
  338. if (!cmSystemTools::FileIsFullPath(script)) {
  339. script =
  340. cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg);
  341. }
  342. if (cmSystemTools::FileIsDirectory(script)) {
  343. status.SetError("given a directory as value of SCRIPT argument.");
  344. return false;
  345. }
  346. }
  347. helper.Makefile->AddInstallGenerator(
  348. cm::make_unique<cmInstallScriptGenerator>(
  349. script, false, component, exclude_from_all, all_components,
  350. helper.Makefile->GetBacktrace()));
  351. } else if (doing_code) {
  352. doing_code = false;
  353. std::string const& code = arg;
  354. helper.Makefile->AddInstallGenerator(
  355. cm::make_unique<cmInstallScriptGenerator>(
  356. code, true, component, exclude_from_all, all_components,
  357. helper.Makefile->GetBacktrace()));
  358. }
  359. }
  360. if (doing_script) {
  361. status.SetError("given no value for SCRIPT argument.");
  362. return false;
  363. }
  364. if (doing_code) {
  365. status.SetError("given no value for CODE argument.");
  366. return false;
  367. }
  368. // Tell the global generator about any installation component names
  369. // specified.
  370. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component);
  371. return true;
  372. }
  373. bool HandleTargetsMode(std::vector<std::string> const& args,
  374. cmExecutionStatus& status)
  375. {
  376. Helper helper(status);
  377. // This is the TARGETS mode.
  378. std::vector<cmTarget*> targets;
  379. struct ArgVectors
  380. {
  381. ArgumentParser::MaybeEmpty<std::vector<std::string>> Archive;
  382. ArgumentParser::MaybeEmpty<std::vector<std::string>> Library;
  383. ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime;
  384. ArgumentParser::MaybeEmpty<std::vector<std::string>> Object;
  385. ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework;
  386. ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle;
  387. ArgumentParser::MaybeEmpty<std::vector<std::string>> Includes;
  388. ArgumentParser::MaybeEmpty<std::vector<std::string>> PrivateHeader;
  389. ArgumentParser::MaybeEmpty<std::vector<std::string>> PublicHeader;
  390. ArgumentParser::MaybeEmpty<std::vector<std::string>> Resource;
  391. ArgumentParser::MaybeEmpty<std::vector<std::string>> CxxModulesBmi;
  392. std::vector<std::vector<std::string>> FileSets;
  393. };
  394. static auto const argHelper =
  395. cmArgumentParser<ArgVectors>{}
  396. .Bind("ARCHIVE"_s, &ArgVectors::Archive)
  397. .Bind("LIBRARY"_s, &ArgVectors::Library)
  398. .Bind("RUNTIME"_s, &ArgVectors::Runtime)
  399. .Bind("OBJECTS"_s, &ArgVectors::Object)
  400. .Bind("FRAMEWORK"_s, &ArgVectors::Framework)
  401. .Bind("BUNDLE"_s, &ArgVectors::Bundle)
  402. .Bind("INCLUDES"_s, &ArgVectors::Includes)
  403. .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader)
  404. .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader)
  405. .Bind("RESOURCE"_s, &ArgVectors::Resource)
  406. .Bind("FILE_SET"_s, &ArgVectors::FileSets)
  407. .Bind("CXX_MODULES_BMI"_s, &ArgVectors::CxxModulesBmi);
  408. std::vector<std::string> genericArgVector;
  409. ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
  410. // now parse the generic args (i.e. the ones not specialized on LIBRARY/
  411. // ARCHIVE, RUNTIME etc. (see above)
  412. // These generic args also contain the targets and the export stuff
  413. ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList;
  414. std::string exports;
  415. cm::optional<ArgumentParser::MaybeEmpty<std::vector<std::string>>>
  416. runtimeDependenciesArgVector;
  417. std::string runtimeDependencySetArg;
  418. std::vector<std::string> unknownArgs;
  419. cmInstallCommandArguments genericArgs(helper.DefaultComponentName,
  420. *helper.Makefile);
  421. genericArgs.Bind("TARGETS"_s, targetList);
  422. genericArgs.Bind("EXPORT"_s, exports);
  423. genericArgs.Bind("RUNTIME_DEPENDENCIES"_s, runtimeDependenciesArgVector);
  424. genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg);
  425. genericArgs.Parse(genericArgVector, &unknownArgs);
  426. bool success = genericArgs.Finalize();
  427. RuntimeDependenciesArgs runtimeDependenciesArgs =
  428. runtimeDependenciesArgVector
  429. ? RuntimeDependenciesArgHelper.Parse(*runtimeDependenciesArgVector,
  430. &unknownArgs)
  431. : RuntimeDependenciesArgs();
  432. cmInstallCommandArguments archiveArgs(helper.DefaultComponentName,
  433. *helper.Makefile);
  434. cmInstallCommandArguments libraryArgs(helper.DefaultComponentName,
  435. *helper.Makefile);
  436. cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName,
  437. *helper.Makefile);
  438. cmInstallCommandArguments objectArgs(helper.DefaultComponentName,
  439. *helper.Makefile);
  440. cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName,
  441. *helper.Makefile);
  442. cmInstallCommandArguments bundleArgs(helper.DefaultComponentName,
  443. *helper.Makefile);
  444. cmInstallCommandArguments privateHeaderArgs(helper.DefaultComponentName,
  445. *helper.Makefile);
  446. cmInstallCommandArguments publicHeaderArgs(helper.DefaultComponentName,
  447. *helper.Makefile);
  448. cmInstallCommandArguments resourceArgs(helper.DefaultComponentName,
  449. *helper.Makefile);
  450. cmInstallCommandIncludesArgument includesArgs;
  451. std::vector<cmInstallCommandFileSetArguments> fileSetArgs(
  452. argVectors.FileSets.size(),
  453. { cmInstallCommandFileSetArguments(helper.DefaultComponentName,
  454. *helper.Makefile) });
  455. cmInstallCommandArguments cxxModuleBmiArgs(helper.DefaultComponentName,
  456. *helper.Makefile);
  457. // now parse the args for specific parts of the target (e.g. LIBRARY,
  458. // RUNTIME, ARCHIVE etc.
  459. archiveArgs.Parse(argVectors.Archive, &unknownArgs);
  460. libraryArgs.Parse(argVectors.Library, &unknownArgs);
  461. runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
  462. objectArgs.Parse(argVectors.Object, &unknownArgs);
  463. frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
  464. bundleArgs.Parse(argVectors.Bundle, &unknownArgs);
  465. privateHeaderArgs.Parse(argVectors.PrivateHeader, &unknownArgs);
  466. publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs);
  467. resourceArgs.Parse(argVectors.Resource, &unknownArgs);
  468. includesArgs.Parse(&argVectors.Includes, &unknownArgs);
  469. cxxModuleBmiArgs.Parse(argVectors.CxxModulesBmi, &unknownArgs);
  470. for (std::size_t i = 0; i < argVectors.FileSets.size(); i++) {
  471. // We have to create a separate object for the parsing because
  472. // cmArgumentParser<void>::Bind() binds to a specific address, but the
  473. // objects in the vector can move around. So we parse in an object with a
  474. // fixed address and then copy the data into the vector.
  475. cmInstallCommandFileSetArguments fileSetArg(helper.DefaultComponentName,
  476. *helper.Makefile);
  477. fileSetArg.Parse(argVectors.FileSets[i], &unknownArgs);
  478. fileSetArgs[i] = std::move(fileSetArg);
  479. }
  480. if (!unknownArgs.empty()) {
  481. // Unknown argument.
  482. status.SetError(
  483. cmStrCat("TARGETS given unknown argument \"", unknownArgs[0], "\"."));
  484. return false;
  485. }
  486. // apply generic args
  487. archiveArgs.SetGenericArguments(&genericArgs);
  488. libraryArgs.SetGenericArguments(&genericArgs);
  489. runtimeArgs.SetGenericArguments(&genericArgs);
  490. objectArgs.SetGenericArguments(&genericArgs);
  491. frameworkArgs.SetGenericArguments(&genericArgs);
  492. bundleArgs.SetGenericArguments(&genericArgs);
  493. privateHeaderArgs.SetGenericArguments(&genericArgs);
  494. publicHeaderArgs.SetGenericArguments(&genericArgs);
  495. resourceArgs.SetGenericArguments(&genericArgs);
  496. for (auto& fileSetArg : fileSetArgs) {
  497. fileSetArg.SetGenericArguments(&genericArgs);
  498. }
  499. cxxModuleBmiArgs.SetGenericArguments(&genericArgs);
  500. success = success && archiveArgs.Finalize();
  501. success = success && libraryArgs.Finalize();
  502. success = success && runtimeArgs.Finalize();
  503. success = success && objectArgs.Finalize();
  504. success = success && frameworkArgs.Finalize();
  505. success = success && bundleArgs.Finalize();
  506. success = success && privateHeaderArgs.Finalize();
  507. success = success && publicHeaderArgs.Finalize();
  508. success = success && resourceArgs.Finalize();
  509. success = success && cxxModuleBmiArgs.Finalize();
  510. for (auto& fileSetArg : fileSetArgs) {
  511. success = success && fileSetArg.Finalize();
  512. }
  513. if (!success) {
  514. return false;
  515. }
  516. // Enforce argument rules too complex to specify for the
  517. // general-purpose parser.
  518. if (runtimeArgs.GetNamelinkOnly() || objectArgs.GetNamelinkOnly() ||
  519. frameworkArgs.GetNamelinkOnly() || bundleArgs.GetNamelinkOnly() ||
  520. privateHeaderArgs.GetNamelinkOnly() ||
  521. publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly() ||
  522. std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
  523. [](cmInstallCommandFileSetArguments const& fileSetArg)
  524. -> bool { return fileSetArg.GetNamelinkOnly(); }) ||
  525. cxxModuleBmiArgs.GetNamelinkOnly()) {
  526. status.SetError(
  527. "TARGETS given NAMELINK_ONLY option not in LIBRARY or ARCHIVE group. "
  528. "The NAMELINK_ONLY option may be specified only following LIBRARY or "
  529. "ARCHIVE.");
  530. return false;
  531. }
  532. if (runtimeArgs.GetNamelinkSkip() || objectArgs.GetNamelinkSkip() ||
  533. frameworkArgs.GetNamelinkSkip() || bundleArgs.GetNamelinkSkip() ||
  534. privateHeaderArgs.GetNamelinkSkip() ||
  535. publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip() ||
  536. std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
  537. [](cmInstallCommandFileSetArguments const& fileSetArg)
  538. -> bool { return fileSetArg.GetNamelinkSkip(); }) ||
  539. cxxModuleBmiArgs.GetNamelinkSkip()) {
  540. status.SetError(
  541. "TARGETS given NAMELINK_SKIP option not in LIBRARY or ARCHIVE group. "
  542. "The NAMELINK_SKIP option may be specified only following LIBRARY or "
  543. "ARCHIVE.");
  544. return false;
  545. }
  546. if (runtimeArgs.HasNamelinkComponent() ||
  547. objectArgs.HasNamelinkComponent() ||
  548. frameworkArgs.HasNamelinkComponent() ||
  549. bundleArgs.HasNamelinkComponent() ||
  550. privateHeaderArgs.HasNamelinkComponent() ||
  551. publicHeaderArgs.HasNamelinkComponent() ||
  552. resourceArgs.HasNamelinkComponent() ||
  553. std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
  554. [](cmInstallCommandFileSetArguments const& fileSetArg)
  555. -> bool { return fileSetArg.HasNamelinkComponent(); }) ||
  556. cxxModuleBmiArgs.HasNamelinkComponent()) {
  557. status.SetError(
  558. "TARGETS given NAMELINK_COMPONENT option not in LIBRARY or ARCHIVE "
  559. "group. The NAMELINK_COMPONENT option may be specified only following "
  560. "LIBRARY or ARCHIVE.");
  561. return false;
  562. }
  563. if (libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip()) {
  564. status.SetError("TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. "
  565. "At most one of these two options may be specified.");
  566. return false;
  567. }
  568. if (!genericArgs.GetType().empty() || !archiveArgs.GetType().empty() ||
  569. !libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() ||
  570. !objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() ||
  571. !bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() ||
  572. !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty() ||
  573. std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
  574. [](cmInstallCommandFileSetArguments const& fileSetArg)
  575. -> bool { return !fileSetArg.GetType().empty(); }) ||
  576. !cxxModuleBmiArgs.GetType().empty()) {
  577. status.SetError(
  578. "TARGETS given TYPE option. The TYPE option may only be specified in "
  579. " install(FILES) and install(DIRECTORIES).");
  580. return false;
  581. }
  582. if (std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
  583. [](cmInstallCommandFileSetArguments const& fileSetArg)
  584. -> bool { return fileSetArg.GetFileSet().empty(); })) {
  585. status.SetError("TARGETS given FILE_SET option without file set name.");
  586. return false;
  587. }
  588. cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr;
  589. if (runtimeDependenciesArgVector) {
  590. if (!runtimeDependencySetArg.empty()) {
  591. status.SetError("TARGETS cannot have both RUNTIME_DEPENDENCIES and "
  592. "RUNTIME_DEPENDENCY_SET.");
  593. return false;
  594. }
  595. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  596. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  597. system)) {
  598. status.SetError(
  599. cmStrCat("TARGETS RUNTIME_DEPENDENCIES is not supported on system \"",
  600. system, '"'));
  601. return false;
  602. }
  603. if (helper.Makefile->IsOn("CMAKE_CROSSCOMPILING")) {
  604. status.SetError("TARGETS RUNTIME_DEPENDENCIES is not supported "
  605. "when cross-compiling.");
  606. return false;
  607. }
  608. if (helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") ==
  609. "Darwin" &&
  610. frameworkArgs.GetDestination().empty()) {
  611. status.SetError(
  612. "TARGETS RUNTIME_DEPENDENCIES given no FRAMEWORK DESTINATION");
  613. return false;
  614. }
  615. runtimeDependencySet = helper.Makefile->GetGlobalGenerator()
  616. ->CreateAnonymousRuntimeDependencySet();
  617. } else if (!runtimeDependencySetArg.empty()) {
  618. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  619. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  620. system)) {
  621. status.SetError(cmStrCat(
  622. "TARGETS RUNTIME_DEPENDENCY_SET is not supported on system \"", system,
  623. '"'));
  624. return false;
  625. }
  626. runtimeDependencySet =
  627. helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet(
  628. runtimeDependencySetArg);
  629. }
  630. // Select the mode for installing symlinks to versioned shared libraries.
  631. cmInstallTargetGenerator::NamelinkModeType namelinkMode =
  632. cmInstallTargetGenerator::NamelinkModeNone;
  633. if (libraryArgs.GetNamelinkOnly()) {
  634. namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
  635. } else if (libraryArgs.GetNamelinkSkip()) {
  636. namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
  637. }
  638. // Select the mode for installing symlinks to versioned imported libraries.
  639. cmInstallTargetGenerator::NamelinkModeType importlinkMode =
  640. cmInstallTargetGenerator::NamelinkModeNone;
  641. if (archiveArgs.GetNamelinkOnly()) {
  642. importlinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
  643. } else if (archiveArgs.GetNamelinkSkip()) {
  644. importlinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
  645. }
  646. // Check if there is something to do.
  647. if (targetList.empty()) {
  648. return true;
  649. }
  650. for (std::string const& tgt : targetList) {
  651. if (helper.Makefile->IsAlias(tgt)) {
  652. status.SetError(
  653. cmStrCat("TARGETS given target \"", tgt, "\" which is an alias."));
  654. return false;
  655. }
  656. // Lookup this target in the current directory.
  657. cmTarget* target = helper.Makefile->FindLocalNonAliasTarget(tgt);
  658. if (!target) {
  659. // If no local target has been found, find it in the global scope.
  660. cmTarget* const global_target =
  661. helper.Makefile->GetGlobalGenerator()->FindTarget(
  662. tgt, { cmStateEnums::TargetDomain::NATIVE });
  663. if (global_target && !global_target->IsImported()) {
  664. target = global_target;
  665. }
  666. }
  667. if (target) {
  668. // Found the target. Check its type.
  669. if (target->GetType() != cmStateEnums::EXECUTABLE &&
  670. target->GetType() != cmStateEnums::STATIC_LIBRARY &&
  671. target->GetType() != cmStateEnums::SHARED_LIBRARY &&
  672. target->GetType() != cmStateEnums::MODULE_LIBRARY &&
  673. target->GetType() != cmStateEnums::OBJECT_LIBRARY &&
  674. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  675. status.SetError(
  676. cmStrCat("TARGETS given target \"", tgt,
  677. "\" which is not an executable, library, or module."));
  678. return false;
  679. }
  680. // Store the target in the list to be installed.
  681. targets.push_back(target);
  682. } else {
  683. // Did not find the target.
  684. status.SetError(
  685. cmStrCat("TARGETS given target \"", tgt, "\" which does not exist."));
  686. return false;
  687. }
  688. }
  689. // Keep track of whether we will be performing an installation of
  690. // any files of the given type.
  691. bool installsArchive = false;
  692. bool installsLibrary = false;
  693. bool installsNamelink = false;
  694. bool installsImportlink = false;
  695. bool installsRuntime = false;
  696. bool installsObject = false;
  697. bool installsFramework = false;
  698. bool installsBundle = false;
  699. bool installsPrivateHeader = false;
  700. bool installsPublicHeader = false;
  701. bool installsResource = false;
  702. std::vector<bool> installsFileSet(fileSetArgs.size(), false);
  703. bool installsCxxModuleBmi = false;
  704. // Generate install script code to install the given targets.
  705. for (cmTarget* ti : targets) {
  706. // Handle each target type.
  707. cmTarget& target = *ti;
  708. std::unique_ptr<cmInstallTargetGenerator> archiveGenerator;
  709. std::unique_ptr<cmInstallTargetGenerator> libraryGenerator;
  710. std::unique_ptr<cmInstallTargetGenerator> namelinkGenerator;
  711. std::unique_ptr<cmInstallTargetGenerator> importlinkGenerator;
  712. std::unique_ptr<cmInstallTargetGenerator> runtimeGenerator;
  713. std::unique_ptr<cmInstallTargetGenerator> objectGenerator;
  714. std::unique_ptr<cmInstallTargetGenerator> frameworkGenerator;
  715. std::unique_ptr<cmInstallTargetGenerator> bundleGenerator;
  716. std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator;
  717. std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator;
  718. std::unique_ptr<cmInstallFilesGenerator> resourceGenerator;
  719. std::vector<std::unique_ptr<cmInstallFileSetGenerator>> fileSetGenerators;
  720. std::unique_ptr<cmInstallCxxModuleBmiGenerator> cxxModuleBmiGenerator;
  721. // Avoid selecting default destinations for PUBLIC_HEADER and
  722. // PRIVATE_HEADER if any artifacts are specified.
  723. bool artifactsSpecified = false;
  724. // Track whether this is a namelink-only rule.
  725. bool namelinkOnly = false;
  726. auto addTargetExport = [&]() -> bool {
  727. // Add this install rule to an export if one was specified.
  728. if (!exports.empty()) {
  729. auto interfaceFileSets = target.GetAllInterfaceFileSets();
  730. if (std::any_of(
  731. interfaceFileSets.begin(), interfaceFileSets.end(),
  732. [=](std::string const& name) -> bool {
  733. return !std::any_of(
  734. fileSetArgs.begin(), fileSetArgs.end(),
  735. [=](cmInstallCommandFileSetArguments const& fileSetArg)
  736. -> bool { return fileSetArg.GetFileSet() == name; });
  737. })) {
  738. status.SetError(cmStrCat("TARGETS target ", target.GetName(),
  739. " is exported but not all of its interface "
  740. "file sets are installed"));
  741. return false;
  742. }
  743. auto te = cm::make_unique<cmTargetExport>();
  744. te->TargetName = target.GetName();
  745. te->ArchiveGenerator = archiveGenerator.get();
  746. te->BundleGenerator = bundleGenerator.get();
  747. te->FrameworkGenerator = frameworkGenerator.get();
  748. te->HeaderGenerator = publicHeaderGenerator.get();
  749. te->LibraryGenerator = libraryGenerator.get();
  750. te->RuntimeGenerator = runtimeGenerator.get();
  751. te->ObjectsGenerator = objectGenerator.get();
  752. for (auto const& gen : fileSetGenerators) {
  753. te->FileSetGenerators[gen->GetFileSetName()] = gen.get();
  754. }
  755. te->CxxModuleBmiGenerator = cxxModuleBmiGenerator.get();
  756. target.AddInstallIncludeDirectories(
  757. *te, cmMakeRange(includesArgs.GetIncludeDirs()));
  758. te->NamelinkOnly = namelinkOnly;
  759. helper.Makefile->GetGlobalGenerator()
  760. ->GetExportSets()[exports]
  761. .AddTargetExport(std::move(te));
  762. }
  763. return true;
  764. };
  765. switch (target.GetType()) {
  766. case cmStateEnums::SHARED_LIBRARY: {
  767. // Shared libraries are handled differently on DLL and non-DLL
  768. // platforms. All windows platforms are DLL platforms including
  769. // cygwin. Currently no other platform is a DLL platform.
  770. if (target.IsDLLPlatform()) {
  771. // When in namelink only mode skip all libraries on Windows.
  772. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  773. namelinkOnly = true;
  774. if (!addTargetExport()) {
  775. return false;
  776. }
  777. continue;
  778. }
  779. // This is a DLL platform.
  780. if (!archiveArgs.GetDestination().empty()) {
  781. // The import library uses the ARCHIVE properties.
  782. archiveGenerator = CreateInstallTargetGenerator(
  783. target, archiveArgs, true, helper.Makefile->GetBacktrace());
  784. artifactsSpecified = true;
  785. }
  786. if (!runtimeArgs.GetDestination().empty()) {
  787. // The DLL uses the RUNTIME properties.
  788. runtimeGenerator = CreateInstallTargetGenerator(
  789. target, runtimeArgs, false, helper.Makefile->GetBacktrace());
  790. artifactsSpecified = true;
  791. }
  792. if (!archiveGenerator && !runtimeGenerator) {
  793. archiveGenerator = CreateInstallTargetGenerator(
  794. target, archiveArgs, true, helper.Makefile->GetBacktrace(),
  795. helper.GetArchiveDestination(nullptr));
  796. runtimeGenerator = CreateInstallTargetGenerator(
  797. target, runtimeArgs, false, helper.Makefile->GetBacktrace(),
  798. helper.GetRuntimeDestination(nullptr));
  799. }
  800. if (runtimeDependencySet && runtimeGenerator) {
  801. runtimeDependencySet->AddLibrary(runtimeGenerator.get());
  802. }
  803. } else {
  804. // This is a non-DLL platform.
  805. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  806. // INSTALL properties. Otherwise, use the LIBRARY properties.
  807. if (target.IsFrameworkOnApple()) {
  808. // When in namelink only mode skip frameworks.
  809. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  810. namelinkOnly = true;
  811. if (!addTargetExport()) {
  812. return false;
  813. }
  814. continue;
  815. }
  816. // Use the FRAMEWORK properties.
  817. if (!frameworkArgs.GetDestination().empty()) {
  818. frameworkGenerator = CreateInstallTargetGenerator(
  819. target, frameworkArgs, false, helper.Makefile->GetBacktrace());
  820. } else {
  821. status.SetError(
  822. cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared "
  823. "library FRAMEWORK target \"",
  824. target.GetName(), "\"."));
  825. return false;
  826. }
  827. } else {
  828. // The shared library uses the LIBRARY properties.
  829. if (!libraryArgs.GetDestination().empty()) {
  830. artifactsSpecified = true;
  831. }
  832. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
  833. libraryGenerator = CreateInstallTargetGenerator(
  834. target, libraryArgs, false, helper.Makefile->GetBacktrace(),
  835. helper.GetLibraryDestination(&libraryArgs));
  836. libraryGenerator->SetNamelinkMode(
  837. cmInstallTargetGenerator::NamelinkModeSkip);
  838. }
  839. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) {
  840. namelinkGenerator = CreateInstallTargetGenerator(
  841. target, libraryArgs, false, helper.Makefile->GetBacktrace(),
  842. helper.GetLibraryDestination(&libraryArgs), false, true);
  843. namelinkGenerator->SetNamelinkMode(
  844. cmInstallTargetGenerator::NamelinkModeOnly);
  845. }
  846. namelinkOnly =
  847. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  848. if (target.GetMakefile()->PlatformSupportsAppleTextStubs() &&
  849. target.IsSharedLibraryWithExports()) {
  850. // Apple .tbd files use the ARCHIVE properties
  851. if (!archiveArgs.GetDestination().empty()) {
  852. artifactsSpecified = true;
  853. }
  854. if (importlinkMode !=
  855. cmInstallTargetGenerator::NamelinkModeOnly) {
  856. archiveGenerator = CreateInstallTargetGenerator(
  857. target, archiveArgs, true, helper.Makefile->GetBacktrace(),
  858. helper.GetLibraryDestination(&archiveArgs));
  859. archiveGenerator->SetImportlinkMode(
  860. cmInstallTargetGenerator::NamelinkModeSkip);
  861. }
  862. if (importlinkMode !=
  863. cmInstallTargetGenerator::NamelinkModeSkip) {
  864. importlinkGenerator = CreateInstallTargetGenerator(
  865. target, archiveArgs, true, helper.Makefile->GetBacktrace(),
  866. helper.GetLibraryDestination(&archiveArgs), false, true);
  867. importlinkGenerator->SetImportlinkMode(
  868. cmInstallTargetGenerator::NamelinkModeOnly);
  869. }
  870. namelinkOnly =
  871. (importlinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  872. }
  873. }
  874. if (runtimeDependencySet && libraryGenerator) {
  875. runtimeDependencySet->AddLibrary(libraryGenerator.get());
  876. }
  877. }
  878. } break;
  879. case cmStateEnums::STATIC_LIBRARY: {
  880. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  881. // INSTALL properties. Otherwise, use the LIBRARY properties.
  882. if (target.IsFrameworkOnApple()) {
  883. // When in namelink only mode skip frameworks.
  884. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  885. namelinkOnly = true;
  886. if (!addTargetExport()) {
  887. return false;
  888. }
  889. continue;
  890. }
  891. // Use the FRAMEWORK properties.
  892. if (!frameworkArgs.GetDestination().empty()) {
  893. frameworkGenerator = CreateInstallTargetGenerator(
  894. target, frameworkArgs, false, helper.Makefile->GetBacktrace());
  895. } else {
  896. status.SetError(
  897. cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static "
  898. "library FRAMEWORK target \"",
  899. target.GetName(), "\"."));
  900. return false;
  901. }
  902. } else {
  903. // Static libraries use ARCHIVE properties.
  904. if (!archiveArgs.GetDestination().empty()) {
  905. artifactsSpecified = true;
  906. }
  907. archiveGenerator = CreateInstallTargetGenerator(
  908. target, archiveArgs, false, helper.Makefile->GetBacktrace(),
  909. helper.GetArchiveDestination(&archiveArgs));
  910. }
  911. } break;
  912. case cmStateEnums::MODULE_LIBRARY: {
  913. // Modules use LIBRARY properties.
  914. if (!libraryArgs.GetDestination().empty()) {
  915. libraryGenerator = CreateInstallTargetGenerator(
  916. target, libraryArgs, false, helper.Makefile->GetBacktrace());
  917. libraryGenerator->SetNamelinkMode(namelinkMode);
  918. namelinkOnly =
  919. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  920. if (runtimeDependencySet) {
  921. runtimeDependencySet->AddModule(libraryGenerator.get());
  922. }
  923. } else {
  924. status.SetError(
  925. cmStrCat("TARGETS given no LIBRARY DESTINATION for module "
  926. "target \"",
  927. target.GetName(), "\"."));
  928. return false;
  929. }
  930. } break;
  931. case cmStateEnums::OBJECT_LIBRARY: {
  932. // Objects use OBJECT properties.
  933. if (!objectArgs.GetDestination().empty()) {
  934. // Verify that we know where the objects are to install them.
  935. std::string reason;
  936. if (!target.HasKnownObjectFileLocation(&reason)) {
  937. status.SetError(
  938. cmStrCat("TARGETS given OBJECT library \"", target.GetName(),
  939. "\" whose objects may not be installed", reason, '.'));
  940. return false;
  941. }
  942. objectGenerator = CreateInstallTargetGenerator(
  943. target, objectArgs, false, helper.Makefile->GetBacktrace());
  944. } else {
  945. // Installing an OBJECT library without a destination transforms
  946. // it to an INTERFACE library. It installs no files but can be
  947. // exported.
  948. }
  949. } break;
  950. case cmStateEnums::EXECUTABLE: {
  951. if (target.IsAppBundleOnApple()) {
  952. // Application bundles use the BUNDLE properties.
  953. if (!bundleArgs.GetDestination().empty()) {
  954. bundleGenerator = CreateInstallTargetGenerator(
  955. target, bundleArgs, false, helper.Makefile->GetBacktrace());
  956. }
  957. if (!bundleGenerator) {
  958. status.SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for "
  959. "MACOSX_BUNDLE executable target \"",
  960. target.GetName(), "\"."));
  961. return false;
  962. }
  963. if (runtimeDependencySet) {
  964. if (!AddBundleExecutable(helper, runtimeDependencySet,
  965. bundleGenerator.get())) {
  966. return false;
  967. }
  968. }
  969. } else {
  970. // Executables use the RUNTIME properties.
  971. if (!runtimeArgs.GetDestination().empty()) {
  972. artifactsSpecified = true;
  973. }
  974. runtimeGenerator = CreateInstallTargetGenerator(
  975. target, runtimeArgs, false, helper.Makefile->GetBacktrace(),
  976. helper.GetRuntimeDestination(&runtimeArgs));
  977. if (runtimeDependencySet) {
  978. runtimeDependencySet->AddExecutable(runtimeGenerator.get());
  979. }
  980. }
  981. // On DLL platforms an executable may also have an import
  982. // library. Install it to the archive destination if it
  983. // exists.
  984. if ((target.IsDLLPlatform() || target.IsAIX()) &&
  985. !archiveArgs.GetDestination().empty() &&
  986. target.IsExecutableWithExports()) {
  987. // The import library uses the ARCHIVE properties.
  988. artifactsSpecified = true;
  989. archiveGenerator = CreateInstallTargetGenerator(
  990. target, archiveArgs, true, helper.Makefile->GetBacktrace(), true);
  991. }
  992. } break;
  993. case cmStateEnums::INTERFACE_LIBRARY:
  994. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  995. // only effect of that is to make it exportable. It installs no
  996. // other files itself.
  997. default:
  998. // This should never happen due to the above type check.
  999. // Ignore the case.
  1000. break;
  1001. }
  1002. // These well-known sets of files are installed *automatically* for
  1003. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  1004. // FRAMEWORK. For other target types or on other platforms, they are not
  1005. // installed automatically and so we need to create install files
  1006. // generators for them.
  1007. bool createInstallGeneratorsForTargetFileSets = true;
  1008. if (target.IsFrameworkOnApple()) {
  1009. createInstallGeneratorsForTargetFileSets = false;
  1010. }
  1011. if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) {
  1012. cmValue files = target.GetProperty("PRIVATE_HEADER");
  1013. if (cmNonempty(files)) {
  1014. cmList relFiles{ *files };
  1015. std::vector<std::string> absFiles;
  1016. if (!helper.MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) {
  1017. return false;
  1018. }
  1019. // Create the files install generator.
  1020. if (!artifactsSpecified ||
  1021. !privateHeaderArgs.GetDestination().empty()) {
  1022. privateHeaderGenerator = CreateInstallFilesGenerator(
  1023. helper.Makefile, absFiles, privateHeaderArgs, false,
  1024. helper.GetIncludeDestination(&privateHeaderArgs));
  1025. } else {
  1026. std::ostringstream e;
  1027. e << "Target " << target.GetName() << " has "
  1028. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  1029. helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  1030. }
  1031. }
  1032. files = target.GetProperty("PUBLIC_HEADER");
  1033. if (cmNonempty(files)) {
  1034. cmList relFiles{ *files };
  1035. std::vector<std::string> absFiles;
  1036. if (!helper.MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) {
  1037. return false;
  1038. }
  1039. // Create the files install generator.
  1040. if (!artifactsSpecified ||
  1041. !publicHeaderArgs.GetDestination().empty()) {
  1042. publicHeaderGenerator = CreateInstallFilesGenerator(
  1043. helper.Makefile, absFiles, publicHeaderArgs, false,
  1044. helper.GetIncludeDestination(&publicHeaderArgs));
  1045. } else {
  1046. std::ostringstream e;
  1047. e << "Target " << target.GetName() << " has "
  1048. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  1049. helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  1050. }
  1051. }
  1052. files = target.GetProperty("RESOURCE");
  1053. if (cmNonempty(files)) {
  1054. cmList relFiles{ *files };
  1055. std::vector<std::string> absFiles;
  1056. if (!helper.MakeFilesFullPath("RESOURCE", relFiles, absFiles)) {
  1057. return false;
  1058. }
  1059. // Create the files install generator.
  1060. if (!resourceArgs.GetDestination().empty()) {
  1061. resourceGenerator = CreateInstallFilesGenerator(
  1062. helper.Makefile, absFiles, resourceArgs, false);
  1063. } else if (!target.IsAppBundleOnApple()) {
  1064. helper.Makefile->IssueMessage(
  1065. MessageType::AUTHOR_WARNING,
  1066. cmStrCat("Target ", target.GetName(),
  1067. " has RESOURCE files but no RESOURCE DESTINATION."));
  1068. }
  1069. }
  1070. }
  1071. if (!namelinkOnly) {
  1072. for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
  1073. cmFileSetDestinations dests;
  1074. dests.Headers = helper.GetIncludeDestination(&fileSetArgs[i]);
  1075. dests.CXXModules = fileSetArgs[i].GetDestination();
  1076. fileSetGenerators.push_back(CreateInstallFileSetGenerator(
  1077. helper, target, std::move(dests), fileSetArgs[i]));
  1078. installsFileSet[i] = true;
  1079. }
  1080. }
  1081. if (!cxxModuleBmiArgs.GetDestination().empty()) {
  1082. cxxModuleBmiGenerator = cm::make_unique<cmInstallCxxModuleBmiGenerator>(
  1083. target.GetName(),
  1084. helper.GetCxxModulesBmiDestination(&cxxModuleBmiArgs),
  1085. cxxModuleBmiArgs.GetPermissions(),
  1086. cxxModuleBmiArgs.GetConfigurations(), cxxModuleBmiArgs.GetComponent(),
  1087. cmInstallGenerator::SelectMessageLevel(target.GetMakefile()),
  1088. cxxModuleBmiArgs.GetExcludeFromAll(), cxxModuleBmiArgs.GetOptional(),
  1089. helper.Makefile->GetBacktrace());
  1090. target.SetHaveInstallRule(true);
  1091. }
  1092. // Add this install rule to an export if one was specified.
  1093. if (!addTargetExport()) {
  1094. return false;
  1095. }
  1096. // Keep track of whether we're installing anything in each category
  1097. installsArchive = installsArchive || archiveGenerator;
  1098. installsLibrary = installsLibrary || libraryGenerator;
  1099. installsNamelink = installsNamelink || namelinkGenerator;
  1100. installsImportlink = installsImportlink || importlinkGenerator;
  1101. installsRuntime = installsRuntime || runtimeGenerator;
  1102. installsObject = installsObject || objectGenerator;
  1103. installsFramework = installsFramework || frameworkGenerator;
  1104. installsBundle = installsBundle || bundleGenerator;
  1105. installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator;
  1106. installsPublicHeader = installsPublicHeader || publicHeaderGenerator;
  1107. installsResource = installsResource || resourceGenerator;
  1108. installsCxxModuleBmi = installsCxxModuleBmi || cxxModuleBmiGenerator;
  1109. helper.Makefile->AddInstallGenerator(std::move(archiveGenerator));
  1110. helper.Makefile->AddInstallGenerator(std::move(libraryGenerator));
  1111. helper.Makefile->AddInstallGenerator(std::move(namelinkGenerator));
  1112. helper.Makefile->AddInstallGenerator(std::move(importlinkGenerator));
  1113. helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator));
  1114. helper.Makefile->AddInstallGenerator(std::move(objectGenerator));
  1115. helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator));
  1116. helper.Makefile->AddInstallGenerator(std::move(bundleGenerator));
  1117. helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator));
  1118. helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator));
  1119. helper.Makefile->AddInstallGenerator(std::move(resourceGenerator));
  1120. for (auto& gen : fileSetGenerators) {
  1121. helper.Makefile->AddInstallGenerator(std::move(gen));
  1122. }
  1123. helper.Makefile->AddInstallGenerator(std::move(cxxModuleBmiGenerator));
  1124. }
  1125. if (runtimeDependenciesArgVector && !runtimeDependencySet->Empty()) {
  1126. AddInstallRuntimeDependenciesGenerator(
  1127. helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs,
  1128. std::move(runtimeDependenciesArgs), installsRuntime, installsLibrary,
  1129. installsFramework);
  1130. }
  1131. // Tell the global generator about any installation component names
  1132. // specified
  1133. if (installsArchive) {
  1134. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1135. archiveArgs.GetComponent());
  1136. }
  1137. if (installsLibrary) {
  1138. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1139. libraryArgs.GetComponent());
  1140. }
  1141. if (installsNamelink) {
  1142. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1143. libraryArgs.GetNamelinkComponent());
  1144. }
  1145. if (installsImportlink) {
  1146. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1147. archiveArgs.GetNamelinkComponent());
  1148. }
  1149. if (installsRuntime) {
  1150. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1151. runtimeArgs.GetComponent());
  1152. }
  1153. if (installsObject) {
  1154. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1155. objectArgs.GetComponent());
  1156. }
  1157. if (installsFramework) {
  1158. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1159. frameworkArgs.GetComponent());
  1160. }
  1161. if (installsBundle) {
  1162. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1163. bundleArgs.GetComponent());
  1164. }
  1165. if (installsPrivateHeader) {
  1166. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1167. privateHeaderArgs.GetComponent());
  1168. }
  1169. if (installsPublicHeader) {
  1170. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1171. publicHeaderArgs.GetComponent());
  1172. }
  1173. if (installsResource) {
  1174. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1175. resourceArgs.GetComponent());
  1176. }
  1177. for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
  1178. if (installsFileSet[i]) {
  1179. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1180. fileSetArgs[i].GetComponent());
  1181. }
  1182. }
  1183. if (installsCxxModuleBmi) {
  1184. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1185. cxxModuleBmiArgs.GetComponent());
  1186. }
  1187. return true;
  1188. }
  1189. bool HandleImportedRuntimeArtifactsMode(std::vector<std::string> const& args,
  1190. cmExecutionStatus& status)
  1191. {
  1192. Helper helper(status);
  1193. // This is the IMPORTED_RUNTIME_ARTIFACTS mode.
  1194. std::vector<cmTarget*> targets;
  1195. struct ArgVectors
  1196. {
  1197. ArgumentParser::MaybeEmpty<std::vector<std::string>> Library;
  1198. ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime;
  1199. ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework;
  1200. ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle;
  1201. };
  1202. static auto const argHelper = cmArgumentParser<ArgVectors>{}
  1203. .Bind("LIBRARY"_s, &ArgVectors::Library)
  1204. .Bind("RUNTIME"_s, &ArgVectors::Runtime)
  1205. .Bind("FRAMEWORK"_s, &ArgVectors::Framework)
  1206. .Bind("BUNDLE"_s, &ArgVectors::Bundle);
  1207. std::vector<std::string> genericArgVector;
  1208. ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
  1209. // now parse the generic args (i.e. the ones not specialized on LIBRARY,
  1210. // RUNTIME etc. (see above)
  1211. ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList;
  1212. std::string runtimeDependencySetArg;
  1213. std::vector<std::string> unknownArgs;
  1214. cmInstallCommandArguments genericArgs(helper.DefaultComponentName,
  1215. *helper.Makefile);
  1216. genericArgs.Bind("IMPORTED_RUNTIME_ARTIFACTS"_s, targetList)
  1217. .Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg);
  1218. genericArgs.Parse(genericArgVector, &unknownArgs);
  1219. bool success = genericArgs.Finalize();
  1220. cmInstallCommandArguments libraryArgs(helper.DefaultComponentName,
  1221. *helper.Makefile);
  1222. cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName,
  1223. *helper.Makefile);
  1224. cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName,
  1225. *helper.Makefile);
  1226. cmInstallCommandArguments bundleArgs(helper.DefaultComponentName,
  1227. *helper.Makefile);
  1228. // now parse the args for specific parts of the target (e.g. LIBRARY,
  1229. // RUNTIME etc.
  1230. libraryArgs.Parse(argVectors.Library, &unknownArgs);
  1231. runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
  1232. frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
  1233. bundleArgs.Parse(argVectors.Bundle, &unknownArgs);
  1234. if (!unknownArgs.empty()) {
  1235. // Unknown argument.
  1236. status.SetError(
  1237. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given unknown argument \"",
  1238. unknownArgs[0], "\"."));
  1239. return false;
  1240. }
  1241. // apply generic args
  1242. libraryArgs.SetGenericArguments(&genericArgs);
  1243. runtimeArgs.SetGenericArguments(&genericArgs);
  1244. frameworkArgs.SetGenericArguments(&genericArgs);
  1245. bundleArgs.SetGenericArguments(&genericArgs);
  1246. success = success && libraryArgs.Finalize();
  1247. success = success && runtimeArgs.Finalize();
  1248. success = success && frameworkArgs.Finalize();
  1249. success = success && bundleArgs.Finalize();
  1250. if (!success) {
  1251. return false;
  1252. }
  1253. cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr;
  1254. if (!runtimeDependencySetArg.empty()) {
  1255. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  1256. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  1257. system)) {
  1258. status.SetError(
  1259. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS RUNTIME_DEPENDENCY_SET is not "
  1260. "supported on system \"",
  1261. system, '"'));
  1262. return false;
  1263. }
  1264. runtimeDependencySet =
  1265. helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet(
  1266. runtimeDependencySetArg);
  1267. }
  1268. // Check if there is something to do.
  1269. if (targetList.empty()) {
  1270. return true;
  1271. }
  1272. for (std::string const& tgt : targetList) {
  1273. if (helper.Makefile->IsAlias(tgt)) {
  1274. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"",
  1275. tgt, "\" which is an alias."));
  1276. return false;
  1277. }
  1278. // Lookup this target in the current directory.
  1279. cmTarget* target = helper.Makefile->FindTargetToUse(tgt);
  1280. if (!target || !target->IsImported()) {
  1281. // If no local target has been found, find it in the global scope.
  1282. cmTarget* const global_target =
  1283. helper.Makefile->GetGlobalGenerator()->FindTarget(
  1284. tgt, { cmStateEnums::TargetDomain::NATIVE });
  1285. if (global_target && global_target->IsImported()) {
  1286. target = global_target;
  1287. }
  1288. }
  1289. if (target) {
  1290. // Found the target. Check its type.
  1291. if (target->GetType() != cmStateEnums::EXECUTABLE &&
  1292. target->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1293. target->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1294. status.SetError(
  1295. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"", tgt,
  1296. "\" which is not an executable, library, or module."));
  1297. return false;
  1298. }
  1299. // Store the target in the list to be installed.
  1300. targets.push_back(target);
  1301. } else {
  1302. // Did not find the target.
  1303. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"",
  1304. tgt, "\" which does not exist."));
  1305. return false;
  1306. }
  1307. }
  1308. // Keep track of whether we will be performing an installation of
  1309. // any files of the given type.
  1310. bool installsLibrary = false;
  1311. bool installsRuntime = false;
  1312. bool installsFramework = false;
  1313. bool installsBundle = false;
  1314. auto const createInstallGenerator =
  1315. [helper](cmTarget& target, cmInstallCommandArguments const& typeArgs,
  1316. std::string const& destination)
  1317. -> std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> {
  1318. return cm::make_unique<cmInstallImportedRuntimeArtifactsGenerator>(
  1319. target.GetName(), destination, typeArgs.GetPermissions(),
  1320. typeArgs.GetConfigurations(), typeArgs.GetComponent(),
  1321. cmInstallGenerator::SelectMessageLevel(helper.Makefile),
  1322. typeArgs.GetExcludeFromAll(), typeArgs.GetOptional(),
  1323. helper.Makefile->GetBacktrace());
  1324. };
  1325. // Generate install script code to install the given targets.
  1326. for (cmTarget* ti : targets) {
  1327. // Handle each target type.
  1328. cmTarget& target = *ti;
  1329. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1330. libraryGenerator;
  1331. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1332. runtimeGenerator;
  1333. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1334. frameworkGenerator;
  1335. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1336. bundleGenerator;
  1337. switch (target.GetType()) {
  1338. case cmStateEnums::SHARED_LIBRARY:
  1339. if (target.IsDLLPlatform()) {
  1340. runtimeGenerator = createInstallGenerator(
  1341. target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs));
  1342. if (runtimeDependencySet) {
  1343. runtimeDependencySet->AddLibrary(runtimeGenerator.get());
  1344. }
  1345. } else if (target.IsFrameworkOnApple()) {
  1346. if (frameworkArgs.GetDestination().empty()) {
  1347. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no "
  1348. "FRAMEWORK DESTINATION for shared "
  1349. "library FRAMEWORK target \"",
  1350. target.GetName(), "\"."));
  1351. return false;
  1352. }
  1353. frameworkGenerator = createInstallGenerator(
  1354. target, frameworkArgs, frameworkArgs.GetDestination());
  1355. if (runtimeDependencySet) {
  1356. runtimeDependencySet->AddLibrary(frameworkGenerator.get());
  1357. }
  1358. } else {
  1359. libraryGenerator = createInstallGenerator(
  1360. target, libraryArgs, helper.GetLibraryDestination(&libraryArgs));
  1361. if (runtimeDependencySet) {
  1362. runtimeDependencySet->AddLibrary(libraryGenerator.get());
  1363. }
  1364. }
  1365. break;
  1366. case cmStateEnums::MODULE_LIBRARY:
  1367. libraryGenerator = createInstallGenerator(
  1368. target, libraryArgs, helper.GetLibraryDestination(&libraryArgs));
  1369. if (runtimeDependencySet) {
  1370. runtimeDependencySet->AddModule(libraryGenerator.get());
  1371. }
  1372. break;
  1373. case cmStateEnums::EXECUTABLE:
  1374. if (target.IsAppBundleOnApple()) {
  1375. if (bundleArgs.GetDestination().empty()) {
  1376. status.SetError(
  1377. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no BUNDLE "
  1378. "DESTINATION for MACOSX_BUNDLE executable target \"",
  1379. target.GetName(), "\"."));
  1380. return false;
  1381. }
  1382. bundleGenerator = createInstallGenerator(
  1383. target, bundleArgs, bundleArgs.GetDestination());
  1384. if (runtimeDependencySet) {
  1385. if (!AddBundleExecutable(helper, runtimeDependencySet,
  1386. bundleGenerator.get())) {
  1387. return false;
  1388. }
  1389. }
  1390. } else {
  1391. runtimeGenerator = createInstallGenerator(
  1392. target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs));
  1393. if (runtimeDependencySet) {
  1394. runtimeDependencySet->AddExecutable(runtimeGenerator.get());
  1395. }
  1396. }
  1397. break;
  1398. default:
  1399. assert(false && "This should never happen");
  1400. break;
  1401. }
  1402. // Keep track of whether we're installing anything in each category
  1403. installsLibrary = installsLibrary || libraryGenerator;
  1404. installsRuntime = installsRuntime || runtimeGenerator;
  1405. installsFramework = installsFramework || frameworkGenerator;
  1406. installsBundle = installsBundle || bundleGenerator;
  1407. helper.Makefile->AddInstallGenerator(std::move(libraryGenerator));
  1408. helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator));
  1409. helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator));
  1410. helper.Makefile->AddInstallGenerator(std::move(bundleGenerator));
  1411. }
  1412. // Tell the global generator about any installation component names
  1413. // specified
  1414. if (installsLibrary) {
  1415. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1416. libraryArgs.GetComponent());
  1417. }
  1418. if (installsRuntime) {
  1419. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1420. runtimeArgs.GetComponent());
  1421. }
  1422. if (installsFramework) {
  1423. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1424. frameworkArgs.GetComponent());
  1425. }
  1426. if (installsBundle) {
  1427. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1428. bundleArgs.GetComponent());
  1429. }
  1430. return true;
  1431. }
  1432. bool HandleFilesMode(std::vector<std::string> const& args,
  1433. cmExecutionStatus& status)
  1434. {
  1435. Helper helper(status);
  1436. // This is the FILES mode.
  1437. bool programs = (args[0] == "PROGRAMS");
  1438. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1439. ArgumentParser::MaybeEmpty<std::vector<std::string>> files;
  1440. ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files);
  1441. std::vector<std::string> unknownArgs;
  1442. ica.Parse(args, &unknownArgs);
  1443. if (!unknownArgs.empty()) {
  1444. // Unknown argument.
  1445. status.SetError(
  1446. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1447. return false;
  1448. }
  1449. std::string type = ica.GetType();
  1450. if (!type.empty() && allowedTypes.count(type) == 0) {
  1451. status.SetError(
  1452. cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument."));
  1453. return false;
  1454. }
  1455. std::vector<std::string> const& filesVector = files;
  1456. // Check if there is something to do.
  1457. if (filesVector.empty()) {
  1458. return true;
  1459. }
  1460. if (!ica.GetRename().empty() && filesVector.size() > 1) {
  1461. // The rename option works only with one file.
  1462. status.SetError(
  1463. cmStrCat(args[0], " given RENAME option with more than one file."));
  1464. return false;
  1465. }
  1466. std::vector<std::string> absFiles;
  1467. if (!helper.MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) {
  1468. return false;
  1469. }
  1470. cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator();
  1471. for (std::string const& file : filesVector) {
  1472. if (gg->IsExportedTargetsFile(file)) {
  1473. helper.Makefile->IssueMessage(
  1474. MessageType::FATAL_ERROR,
  1475. cmStrCat("The file\n ", file,
  1476. "\n"
  1477. "was generated by the export() command. "
  1478. "It may not be installed with the install() command. "
  1479. "Use the install(EXPORT) mechanism instead. "
  1480. "See the cmake-packages(7) manual for more."));
  1481. return false;
  1482. }
  1483. }
  1484. if (!ica.Finalize()) {
  1485. return false;
  1486. }
  1487. if (!type.empty() && !ica.GetDestination().empty()) {
  1488. status.SetError(cmStrCat(args[0],
  1489. " given both TYPE and DESTINATION arguments. "
  1490. "You may only specify one."));
  1491. return false;
  1492. }
  1493. std::string destination = helper.GetDestinationForType(&ica, type);
  1494. if (destination.empty()) {
  1495. // A destination is required.
  1496. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1497. return false;
  1498. }
  1499. // Create the files install generator.
  1500. helper.Makefile->AddInstallGenerator(CreateInstallFilesGenerator(
  1501. helper.Makefile, absFiles, ica, programs, destination));
  1502. // Tell the global generator about any installation component names
  1503. // specified.
  1504. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1505. ica.GetComponent());
  1506. return true;
  1507. }
  1508. bool HandleDirectoryMode(std::vector<std::string> const& args,
  1509. cmExecutionStatus& status)
  1510. {
  1511. Helper helper(status);
  1512. enum Doing
  1513. {
  1514. DoingNone,
  1515. DoingDirs,
  1516. DoingDestination,
  1517. DoingPattern,
  1518. DoingRegex,
  1519. DoingPermsFile,
  1520. DoingPermsDir,
  1521. DoingPermsMatch,
  1522. DoingConfigurations,
  1523. DoingComponent,
  1524. DoingType
  1525. };
  1526. Doing doing = DoingDirs;
  1527. bool in_match_mode = false;
  1528. bool optional = false;
  1529. bool exclude_from_all = false;
  1530. bool message_never = false;
  1531. std::vector<std::string> dirs;
  1532. cm::optional<std::string> destination;
  1533. std::string permissions_file;
  1534. std::string permissions_dir;
  1535. std::vector<std::string> configurations;
  1536. std::string component = helper.DefaultComponentName;
  1537. std::string literal_args;
  1538. std::string type;
  1539. for (unsigned int i = 1; i < args.size(); ++i) {
  1540. if (args[i] == "DESTINATION") {
  1541. if (in_match_mode) {
  1542. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1543. "\" after PATTERN or REGEX."));
  1544. return false;
  1545. }
  1546. // Switch to setting the destination property.
  1547. doing = DoingDestination;
  1548. } else if (args[i] == "TYPE") {
  1549. if (in_match_mode) {
  1550. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1551. "\" after PATTERN or REGEX."));
  1552. return false;
  1553. }
  1554. // Switch to setting the type.
  1555. doing = DoingType;
  1556. } else if (args[i] == "OPTIONAL") {
  1557. if (in_match_mode) {
  1558. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1559. "\" after PATTERN or REGEX."));
  1560. return false;
  1561. }
  1562. // Mark the rule as optional.
  1563. optional = true;
  1564. doing = DoingNone;
  1565. } else if (args[i] == "MESSAGE_NEVER") {
  1566. if (in_match_mode) {
  1567. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1568. "\" after PATTERN or REGEX."));
  1569. return false;
  1570. }
  1571. // Mark the rule as quiet.
  1572. message_never = true;
  1573. doing = DoingNone;
  1574. } else if (args[i] == "PATTERN") {
  1575. // Switch to a new pattern match rule.
  1576. doing = DoingPattern;
  1577. in_match_mode = true;
  1578. } else if (args[i] == "REGEX") {
  1579. // Switch to a new regex match rule.
  1580. doing = DoingRegex;
  1581. in_match_mode = true;
  1582. } else if (args[i] == "EXCLUDE") {
  1583. // Add this property to the current match rule.
  1584. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
  1585. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1586. "\" before a PATTERN or REGEX is given."));
  1587. return false;
  1588. }
  1589. literal_args += " EXCLUDE";
  1590. doing = DoingNone;
  1591. } else if (args[i] == "PERMISSIONS") {
  1592. if (!in_match_mode) {
  1593. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1594. "\" before a PATTERN or REGEX is given."));
  1595. return false;
  1596. }
  1597. // Switch to setting the current match permissions property.
  1598. literal_args += " PERMISSIONS";
  1599. doing = DoingPermsMatch;
  1600. } else if (args[i] == "FILE_PERMISSIONS") {
  1601. if (in_match_mode) {
  1602. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1603. "\" after PATTERN or REGEX."));
  1604. return false;
  1605. }
  1606. // Switch to setting the file permissions property.
  1607. doing = DoingPermsFile;
  1608. } else if (args[i] == "DIRECTORY_PERMISSIONS") {
  1609. if (in_match_mode) {
  1610. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1611. "\" after PATTERN or REGEX."));
  1612. return false;
  1613. }
  1614. // Switch to setting the directory permissions property.
  1615. doing = DoingPermsDir;
  1616. } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
  1617. if (in_match_mode) {
  1618. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1619. "\" after PATTERN or REGEX."));
  1620. return false;
  1621. }
  1622. // Add this option literally.
  1623. literal_args += " USE_SOURCE_PERMISSIONS";
  1624. doing = DoingNone;
  1625. } else if (args[i] == "FILES_MATCHING") {
  1626. if (in_match_mode) {
  1627. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1628. "\" after PATTERN or REGEX."));
  1629. return false;
  1630. }
  1631. // Add this option literally.
  1632. literal_args += " FILES_MATCHING";
  1633. doing = DoingNone;
  1634. } else if (args[i] == "CONFIGURATIONS") {
  1635. if (in_match_mode) {
  1636. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1637. "\" after PATTERN or REGEX."));
  1638. return false;
  1639. }
  1640. // Switch to setting the configurations property.
  1641. doing = DoingConfigurations;
  1642. } else if (args[i] == "COMPONENT") {
  1643. if (in_match_mode) {
  1644. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1645. "\" after PATTERN or REGEX."));
  1646. return false;
  1647. }
  1648. // Switch to setting the component property.
  1649. doing = DoingComponent;
  1650. } else if (args[i] == "EXCLUDE_FROM_ALL") {
  1651. if (in_match_mode) {
  1652. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1653. "\" after PATTERN or REGEX."));
  1654. return false;
  1655. }
  1656. exclude_from_all = true;
  1657. doing = DoingNone;
  1658. } else if (doing == DoingDirs) {
  1659. // Convert this directory to a full path.
  1660. std::string dir = args[i];
  1661. std::string::size_type gpos = cmGeneratorExpression::Find(dir);
  1662. if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
  1663. dir =
  1664. cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', args[i]);
  1665. }
  1666. // Make sure the name is a directory.
  1667. if (cmSystemTools::FileExists(dir, true)) {
  1668. status.SetError(cmStrCat(args[0], " given non-directory \"", args[i],
  1669. "\" to install."));
  1670. return false;
  1671. }
  1672. // Store the directory for installation.
  1673. dirs.push_back(std::move(dir));
  1674. } else if (doing == DoingConfigurations) {
  1675. configurations.push_back(args[i]);
  1676. } else if (doing == DoingDestination) {
  1677. // A trailing slash is meaningful for this form, but normalization
  1678. // preserves it if present
  1679. switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0177)) {
  1680. case cmPolicies::NEW:
  1681. destination = cmCMakePath(args[i]).Normal().String();
  1682. break;
  1683. case cmPolicies::WARN:
  1684. // We can't be certain if a warning is appropriate if there are any
  1685. // generator expressions
  1686. if (cmGeneratorExpression::Find(args[i]) == cm::string_view::npos &&
  1687. args[i] != cmCMakePath(args[i]).Normal().String()) {
  1688. status.GetMakefile().IssueMessage(
  1689. MessageType::AUTHOR_WARNING,
  1690. cmPolicies::GetPolicyWarning(cmPolicies::CMP0177));
  1691. }
  1692. CM_FALLTHROUGH;
  1693. case cmPolicies::OLD:
  1694. destination = args[i];
  1695. break;
  1696. }
  1697. doing = DoingNone;
  1698. } else if (doing == DoingType) {
  1699. if (allowedTypes.count(args[i]) == 0) {
  1700. status.SetError(cmStrCat(args[0], " given non-type \"", args[i],
  1701. "\" with TYPE argument."));
  1702. return false;
  1703. }
  1704. type = args[i];
  1705. doing = DoingNone;
  1706. } else if (doing == DoingPattern) {
  1707. // Convert the pattern to a regular expression. Require a
  1708. // leading slash and trailing end-of-string in the matched
  1709. // string to make sure the pattern matches only whole file
  1710. // names.
  1711. literal_args += " REGEX \"/";
  1712. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1713. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1714. literal_args += regex;
  1715. literal_args += "$\"";
  1716. doing = DoingNone;
  1717. } else if (doing == DoingRegex) {
  1718. literal_args += " REGEX \"";
  1719. // Match rules are case-insensitive on some platforms.
  1720. #if defined(_WIN32) || defined(__APPLE__)
  1721. std::string regex = cmSystemTools::LowerCase(args[i]);
  1722. #else
  1723. std::string regex = args[i];
  1724. #endif
  1725. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1726. literal_args += regex;
  1727. literal_args += "\"";
  1728. doing = DoingNone;
  1729. } else if (doing == DoingComponent) {
  1730. component = args[i];
  1731. doing = DoingNone;
  1732. } else if (doing == DoingPermsFile) {
  1733. // Check the requested permission.
  1734. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1735. permissions_file)) {
  1736. status.SetError(cmStrCat(args[0], " given invalid file permission \"",
  1737. args[i], "\"."));
  1738. return false;
  1739. }
  1740. } else if (doing == DoingPermsDir) {
  1741. // Check the requested permission.
  1742. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1743. permissions_dir)) {
  1744. status.SetError(cmStrCat(
  1745. args[0], " given invalid directory permission \"", args[i], "\"."));
  1746. return false;
  1747. }
  1748. } else if (doing == DoingPermsMatch) {
  1749. // Check the requested permission.
  1750. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1751. literal_args)) {
  1752. status.SetError(
  1753. cmStrCat(args[0], " given invalid permission \"", args[i], "\"."));
  1754. return false;
  1755. }
  1756. } else {
  1757. // Unknown argument.
  1758. status.SetError(
  1759. cmStrCat(args[0], " given unknown argument \"", args[i], "\"."));
  1760. return false;
  1761. }
  1762. }
  1763. // Support installing an empty directory.
  1764. if (dirs.empty() && destination.has_value()) {
  1765. dirs.emplace_back();
  1766. }
  1767. // Check if there is something to do.
  1768. if (dirs.empty()) {
  1769. return true;
  1770. }
  1771. if (!destination.has_value()) {
  1772. if (type.empty()) {
  1773. // A destination is required.
  1774. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1775. return false;
  1776. }
  1777. destination = helper.GetDestinationForType(nullptr, type);
  1778. } else if (!type.empty()) {
  1779. status.SetError(cmStrCat(args[0],
  1780. " given both TYPE and DESTINATION "
  1781. "arguments. You may only specify one."));
  1782. return false;
  1783. }
  1784. cmInstallGenerator::MessageLevel message =
  1785. cmInstallGenerator::SelectMessageLevel(helper.Makefile, message_never);
  1786. // Create the directory install generator.
  1787. helper.Makefile->AddInstallGenerator(
  1788. cm::make_unique<cmInstallDirectoryGenerator>(
  1789. dirs, *destination, permissions_file, permissions_dir, configurations,
  1790. component, message, exclude_from_all, literal_args, optional,
  1791. helper.Makefile->GetBacktrace()));
  1792. // Tell the global generator about any installation component names
  1793. // specified.
  1794. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component);
  1795. return true;
  1796. }
  1797. bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
  1798. cmExecutionStatus& status)
  1799. {
  1800. #ifndef CMAKE_BOOTSTRAP
  1801. Helper helper(status);
  1802. // This is the EXPORT mode.
  1803. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1804. std::string exp;
  1805. std::string name_space;
  1806. bool exportOld = false;
  1807. std::string filename;
  1808. ica.Bind("EXPORT_ANDROID_MK"_s, exp);
  1809. ica.Bind("NAMESPACE"_s, name_space);
  1810. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1811. ica.Bind("FILE"_s, filename);
  1812. std::vector<std::string> unknownArgs;
  1813. ica.Parse(args, &unknownArgs);
  1814. if (!unknownArgs.empty()) {
  1815. // Unknown argument.
  1816. status.SetError(
  1817. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1818. return false;
  1819. }
  1820. if (!ica.Finalize()) {
  1821. return false;
  1822. }
  1823. // Make sure there is a destination.
  1824. if (ica.GetDestination().empty()) {
  1825. // A destination is required.
  1826. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1827. return false;
  1828. }
  1829. // Check the file name.
  1830. std::string fname = filename;
  1831. if (fname.find_first_of(":/\\") != std::string::npos) {
  1832. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1833. fname,
  1834. "\". The FILE argument may not contain a path. "
  1835. "Specify the path in the DESTINATION argument."));
  1836. return false;
  1837. }
  1838. // Check the file extension.
  1839. if (!fname.empty() &&
  1840. cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
  1841. status.SetError(cmStrCat(
  1842. args[0], " given invalid export file name \"", fname,
  1843. R"(". The FILE argument must specify a name ending in ".mk".)"));
  1844. return false;
  1845. }
  1846. if (fname.find_first_of(":/\\") != std::string::npos) {
  1847. status.SetError(
  1848. cmStrCat(args[0], " given export name \"", exp,
  1849. "\". "
  1850. "This name cannot be safely converted to a file name. "
  1851. "Specify a different export name or use the FILE option to set "
  1852. "a file name explicitly."));
  1853. return false;
  1854. }
  1855. // Use the default name
  1856. if (fname.empty()) {
  1857. fname = "Android.mk";
  1858. }
  1859. cmExportSet& exportSet =
  1860. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1861. cmInstallGenerator::MessageLevel message =
  1862. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  1863. // Tell the global generator about any installation component names
  1864. // specified
  1865. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1866. ica.GetComponent());
  1867. // Create the export install generator.
  1868. helper.Makefile->AddInstallGenerator(
  1869. cm::make_unique<cmInstallAndroidMKExportGenerator>(
  1870. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  1871. ica.GetConfigurations(), ica.GetComponent(), message,
  1872. ica.GetExcludeFromAll(), std::move(fname), std::move(name_space),
  1873. helper.Makefile->GetBacktrace()));
  1874. return true;
  1875. #else
  1876. static_cast<void>(args);
  1877. status.SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake");
  1878. return false;
  1879. #endif
  1880. }
  1881. bool HandleExportMode(std::vector<std::string> const& args,
  1882. cmExecutionStatus& status)
  1883. {
  1884. Helper helper(status);
  1885. // This is the EXPORT mode.
  1886. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1887. std::string exp;
  1888. std::string name_space;
  1889. bool exportOld = false;
  1890. std::string filename;
  1891. std::string cxx_modules_directory;
  1892. bool exportPackageDependencies = false;
  1893. ica.Bind("EXPORT"_s, exp);
  1894. ica.Bind("NAMESPACE"_s, name_space);
  1895. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1896. ica.Bind("FILE"_s, filename);
  1897. ica.Bind("CXX_MODULES_DIRECTORY"_s, cxx_modules_directory);
  1898. if (cmExperimental::HasSupportEnabled(
  1899. status.GetMakefile(),
  1900. cmExperimental::Feature::ExportPackageDependencies)) {
  1901. ica.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s, exportPackageDependencies);
  1902. }
  1903. std::vector<std::string> unknownArgs;
  1904. ica.Parse(args, &unknownArgs);
  1905. if (!unknownArgs.empty()) {
  1906. // Unknown argument.
  1907. status.SetError(
  1908. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1909. return false;
  1910. }
  1911. if (!ica.Finalize()) {
  1912. return false;
  1913. }
  1914. if (exp.empty()) {
  1915. status.SetError(cmStrCat(args[0], " missing EXPORT."));
  1916. return false;
  1917. }
  1918. // Make sure there is a destination.
  1919. if (ica.GetDestination().empty()) {
  1920. // A destination is required.
  1921. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1922. return false;
  1923. }
  1924. // Check the file name.
  1925. std::string fname = filename;
  1926. if (fname.find_first_of(":/\\") != std::string::npos) {
  1927. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1928. fname,
  1929. "\". "
  1930. "The FILE argument may not contain a path. "
  1931. "Specify the path in the DESTINATION argument."));
  1932. return false;
  1933. }
  1934. // Check the file extension.
  1935. if (!fname.empty() &&
  1936. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
  1937. status.SetError(
  1938. cmStrCat(args[0], " given invalid export file name \"", fname,
  1939. "\". "
  1940. "The FILE argument must specify a name ending in \".cmake\"."));
  1941. return false;
  1942. }
  1943. // Construct the file name.
  1944. if (fname.empty()) {
  1945. fname = cmStrCat(exp, ".cmake");
  1946. if (fname.find_first_of(":/\\") != std::string::npos) {
  1947. status.SetError(cmStrCat(
  1948. args[0], " given export name \"", exp,
  1949. "\". "
  1950. "This name cannot be safely converted to a file name. "
  1951. "Specify a different export name or use the FILE option to set "
  1952. "a file name explicitly."));
  1953. return false;
  1954. }
  1955. }
  1956. cmExportSet& exportSet =
  1957. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1958. cmInstallGenerator::MessageLevel message =
  1959. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  1960. // Tell the global generator about any installation component names
  1961. // specified
  1962. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1963. ica.GetComponent());
  1964. // Create the export install generator.
  1965. helper.Makefile->AddInstallGenerator(
  1966. cm::make_unique<cmInstallCMakeConfigExportGenerator>(
  1967. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  1968. ica.GetConfigurations(), ica.GetComponent(), message,
  1969. ica.GetExcludeFromAll(), std::move(fname), std::move(name_space),
  1970. std::move(cxx_modules_directory), exportOld, exportPackageDependencies,
  1971. helper.Makefile->GetBacktrace()));
  1972. return true;
  1973. }
  1974. bool HandlePackageInfoMode(std::vector<std::string> const& args,
  1975. cmExecutionStatus& status)
  1976. {
  1977. #ifndef CMAKE_BOOTSTRAP
  1978. if (!cmExperimental::HasSupportEnabled(
  1979. status.GetMakefile(), cmExperimental::Feature::ExportPackageInfo)) {
  1980. status.SetError("does not recognize sub-command PACKAGE_INFO");
  1981. return false;
  1982. }
  1983. Helper helper(status);
  1984. // This is the PACKAGE_INFO mode.
  1985. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1986. cmPackageInfoArguments arguments;
  1987. ArgumentParser::NonEmpty<std::string> exportName;
  1988. ArgumentParser::NonEmpty<std::string> cxxModulesDirectory;
  1989. arguments.Bind(ica);
  1990. ica.Bind("EXPORT"_s, exportName);
  1991. // ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); TODO?
  1992. std::vector<std::string> unknownArgs;
  1993. ica.Parse(args, &unknownArgs);
  1994. if (!unknownArgs.empty()) {
  1995. // Unknown argument.
  1996. status.SetError(
  1997. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1998. return false;
  1999. }
  2000. if (!ica.Finalize()) {
  2001. return false;
  2002. }
  2003. if (exportName.empty()) {
  2004. status.SetError(cmStrCat(args[0], " missing EXPORT."));
  2005. return false;
  2006. }
  2007. if (!arguments.Check(status) || !arguments.SetMetadataFromProject(status)) {
  2008. return false;
  2009. }
  2010. // Get or construct the destination path.
  2011. std::string dest = ica.GetDestination();
  2012. if (dest.empty()) {
  2013. if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") {
  2014. dest = std::string{ "cps"_s };
  2015. } else {
  2016. dest = cmStrCat(helper.GetLibraryDestination(nullptr), "/cps/",
  2017. arguments.GetPackageDirName());
  2018. }
  2019. }
  2020. cmExportSet& exportSet =
  2021. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName];
  2022. cmInstallGenerator::MessageLevel message =
  2023. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  2024. // Tell the global generator about any installation component names
  2025. // specified
  2026. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2027. ica.GetComponent());
  2028. // Create the export install generator.
  2029. helper.Makefile->AddInstallGenerator(
  2030. cm::make_unique<cmInstallPackageInfoExportGenerator>(
  2031. &exportSet, dest, ica.GetPermissions(), ica.GetConfigurations(),
  2032. ica.GetComponent(), message, ica.GetExcludeFromAll(),
  2033. std::move(arguments), std::move(cxxModulesDirectory),
  2034. helper.Makefile->GetBacktrace()));
  2035. return true;
  2036. #else
  2037. static_cast<void>(args);
  2038. status.SetError("PACKAGE_INFO not supported in bootstrap cmake");
  2039. return false;
  2040. #endif
  2041. }
  2042. bool HandleRuntimeDependencySetMode(std::vector<std::string> const& args,
  2043. cmExecutionStatus& status)
  2044. {
  2045. Helper helper(status);
  2046. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  2047. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  2048. system)) {
  2049. status.SetError(cmStrCat(
  2050. "RUNTIME_DEPENDENCY_SET is not supported on system \"", system, '"'));
  2051. return false;
  2052. }
  2053. // This is the RUNTIME_DEPENDENCY_SET mode.
  2054. cmInstallRuntimeDependencySet* runtimeDependencySet;
  2055. struct ArgVectors
  2056. {
  2057. ArgumentParser::MaybeEmpty<std::vector<std::string>> Library;
  2058. ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime;
  2059. ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework;
  2060. };
  2061. static auto const argHelper = cmArgumentParser<ArgVectors>{}
  2062. .Bind("LIBRARY"_s, &ArgVectors::Library)
  2063. .Bind("RUNTIME"_s, &ArgVectors::Runtime)
  2064. .Bind("FRAMEWORK"_s, &ArgVectors::Framework);
  2065. std::vector<std::string> genericArgVector;
  2066. ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
  2067. // now parse the generic args (i.e. the ones not specialized on LIBRARY,
  2068. // RUNTIME, FRAMEWORK etc. (see above)
  2069. // These generic args also contain the runtime dependency set
  2070. std::string runtimeDependencySetArg;
  2071. std::vector<std::string> runtimeDependencyArgVector;
  2072. cmInstallCommandArguments genericArgs(helper.DefaultComponentName,
  2073. *helper.Makefile);
  2074. genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg);
  2075. genericArgs.Parse(genericArgVector, &runtimeDependencyArgVector);
  2076. bool success = genericArgs.Finalize();
  2077. cmInstallCommandArguments libraryArgs(helper.DefaultComponentName,
  2078. *helper.Makefile);
  2079. cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName,
  2080. *helper.Makefile);
  2081. cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName,
  2082. *helper.Makefile);
  2083. // Now also parse the file(GET_RUNTIME_DEPENDENCY) args
  2084. std::vector<std::string> unknownArgs;
  2085. auto runtimeDependencyArgs = RuntimeDependenciesArgHelper.Parse(
  2086. runtimeDependencyArgVector, &unknownArgs);
  2087. // now parse the args for specific parts of the target (e.g. LIBRARY,
  2088. // RUNTIME, FRAMEWORK etc.
  2089. libraryArgs.Parse(argVectors.Library, &unknownArgs);
  2090. runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
  2091. frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
  2092. libraryArgs.SetGenericArguments(&genericArgs);
  2093. runtimeArgs.SetGenericArguments(&genericArgs);
  2094. frameworkArgs.SetGenericArguments(&genericArgs);
  2095. success = success && libraryArgs.Finalize();
  2096. success = success && runtimeArgs.Finalize();
  2097. success = success && frameworkArgs.Finalize();
  2098. if (!success) {
  2099. return false;
  2100. }
  2101. if (!unknownArgs.empty()) {
  2102. helper.SetError(
  2103. cmStrCat("RUNTIME_DEPENDENCY_SET given unknown argument \"",
  2104. unknownArgs.front(), "\"."));
  2105. return false;
  2106. }
  2107. if (runtimeDependencySetArg.empty()) {
  2108. helper.SetError(
  2109. "RUNTIME_DEPENDENCY_SET not given a runtime dependency set.");
  2110. return false;
  2111. }
  2112. runtimeDependencySet =
  2113. helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet(
  2114. runtimeDependencySetArg);
  2115. bool installsRuntime = false;
  2116. bool installsLibrary = false;
  2117. bool installsFramework = false;
  2118. AddInstallRuntimeDependenciesGenerator(
  2119. helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs,
  2120. std::move(runtimeDependencyArgs), installsRuntime, installsLibrary,
  2121. installsFramework);
  2122. // Tell the global generator about any installation component names
  2123. // specified
  2124. if (installsLibrary) {
  2125. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2126. libraryArgs.GetComponent());
  2127. }
  2128. if (installsRuntime) {
  2129. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2130. runtimeArgs.GetComponent());
  2131. }
  2132. if (installsFramework) {
  2133. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2134. frameworkArgs.GetComponent());
  2135. }
  2136. return true;
  2137. }
  2138. bool Helper::MakeFilesFullPath(char const* modeName,
  2139. std::vector<std::string> const& relFiles,
  2140. std::vector<std::string>& absFiles)
  2141. {
  2142. return this->MakeFilesFullPath(
  2143. modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles);
  2144. }
  2145. bool Helper::MakeFilesFullPath(char const* modeName,
  2146. std::string const& basePath,
  2147. std::vector<std::string> const& relFiles,
  2148. std::vector<std::string>& absFiles)
  2149. {
  2150. for (std::string const& relFile : relFiles) {
  2151. std::string file = relFile;
  2152. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  2153. if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
  2154. file = cmStrCat(basePath, '/', relFile);
  2155. }
  2156. // Make sure the file is not a directory.
  2157. if (gpos == std::string::npos && !cmSystemTools::FileIsSymlink(file) &&
  2158. cmSystemTools::FileIsDirectory(file)) {
  2159. this->SetError(
  2160. cmStrCat(modeName, " given directory \"", relFile, "\" to install."));
  2161. return false;
  2162. }
  2163. // Store the file for installation.
  2164. absFiles.push_back(std::move(file));
  2165. }
  2166. return true;
  2167. }
  2168. std::string Helper::GetDestination(cmInstallCommandArguments const* args,
  2169. std::string const& varName,
  2170. std::string const& guess) const
  2171. {
  2172. if (args && !args->GetDestination().empty()) {
  2173. return args->GetDestination();
  2174. }
  2175. std::string val = this->Makefile->GetSafeDefinition(varName);
  2176. if (!val.empty()) {
  2177. return val;
  2178. }
  2179. return guess;
  2180. }
  2181. std::string Helper::GetRuntimeDestination(
  2182. cmInstallCommandArguments const* args) const
  2183. {
  2184. return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin");
  2185. }
  2186. std::string Helper::GetSbinDestination(
  2187. cmInstallCommandArguments const* args) const
  2188. {
  2189. return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin");
  2190. }
  2191. std::string Helper::GetArchiveDestination(
  2192. cmInstallCommandArguments const* args) const
  2193. {
  2194. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  2195. }
  2196. std::string Helper::GetLibraryDestination(
  2197. cmInstallCommandArguments const* args) const
  2198. {
  2199. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  2200. }
  2201. std::string Helper::GetCxxModulesBmiDestination(
  2202. cmInstallCommandArguments const* args) const
  2203. {
  2204. if (args) {
  2205. return args->GetDestination();
  2206. }
  2207. return {};
  2208. }
  2209. std::string Helper::GetIncludeDestination(
  2210. cmInstallCommandArguments const* args) const
  2211. {
  2212. return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include");
  2213. }
  2214. std::string Helper::GetSysconfDestination(
  2215. cmInstallCommandArguments const* args) const
  2216. {
  2217. return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc");
  2218. }
  2219. std::string Helper::GetSharedStateDestination(
  2220. cmInstallCommandArguments const* args) const
  2221. {
  2222. return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com");
  2223. }
  2224. std::string Helper::GetLocalStateDestination(
  2225. cmInstallCommandArguments const* args) const
  2226. {
  2227. return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var");
  2228. }
  2229. std::string Helper::GetRunStateDestination(
  2230. cmInstallCommandArguments const* args) const
  2231. {
  2232. return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR",
  2233. this->GetLocalStateDestination(nullptr) +
  2234. "/run");
  2235. }
  2236. std::string Helper::GetDataRootDestination(
  2237. cmInstallCommandArguments const* args) const
  2238. {
  2239. return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share");
  2240. }
  2241. std::string Helper::GetDataDestination(
  2242. cmInstallCommandArguments const* args) const
  2243. {
  2244. return this->GetDestination(args, "CMAKE_INSTALL_DATADIR",
  2245. this->GetDataRootDestination(nullptr));
  2246. }
  2247. std::string Helper::GetInfoDestination(
  2248. cmInstallCommandArguments const* args) const
  2249. {
  2250. return this->GetDestination(args, "CMAKE_INSTALL_INFODIR",
  2251. this->GetDataRootDestination(nullptr) + "/info");
  2252. }
  2253. std::string Helper::GetLocaleDestination(
  2254. cmInstallCommandArguments const* args) const
  2255. {
  2256. return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR",
  2257. this->GetDataRootDestination(nullptr) +
  2258. "/locale");
  2259. }
  2260. std::string Helper::GetManDestination(
  2261. cmInstallCommandArguments const* args) const
  2262. {
  2263. return this->GetDestination(args, "CMAKE_INSTALL_MANDIR",
  2264. this->GetDataRootDestination(nullptr) + "/man");
  2265. }
  2266. std::string Helper::GetDocDestination(
  2267. cmInstallCommandArguments const* args) const
  2268. {
  2269. return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR",
  2270. this->GetDataRootDestination(nullptr) + "/doc");
  2271. }
  2272. std::string Helper::GetProgramExecutablesDestination(
  2273. cmInstallCommandArguments const* args) const
  2274. {
  2275. return this->GetDestination(args, "CMAKE_INSTALL_LIBEXECDIR", "libexec");
  2276. }
  2277. std::string Helper::GetDestinationForType(
  2278. cmInstallCommandArguments const* args, std::string const& type) const
  2279. {
  2280. if (args && !args->GetDestination().empty()) {
  2281. return args->GetDestination();
  2282. }
  2283. if (type == "BIN") {
  2284. return this->GetRuntimeDestination(nullptr);
  2285. }
  2286. if (type == "SBIN") {
  2287. return this->GetSbinDestination(nullptr);
  2288. }
  2289. if (type == "SYSCONF") {
  2290. return this->GetSysconfDestination(nullptr);
  2291. }
  2292. if (type == "SHAREDSTATE") {
  2293. return this->GetSharedStateDestination(nullptr);
  2294. }
  2295. if (type == "LOCALSTATE") {
  2296. return this->GetLocalStateDestination(nullptr);
  2297. }
  2298. if (type == "RUNSTATE") {
  2299. return this->GetRunStateDestination(nullptr);
  2300. }
  2301. if (type == "LIB") {
  2302. return this->GetLibraryDestination(nullptr);
  2303. }
  2304. if (type == "INCLUDE") {
  2305. return this->GetIncludeDestination(nullptr);
  2306. }
  2307. if (type == "DATA") {
  2308. return this->GetDataDestination(nullptr);
  2309. }
  2310. if (type == "INFO") {
  2311. return this->GetInfoDestination(nullptr);
  2312. }
  2313. if (type == "LOCALE") {
  2314. return this->GetLocaleDestination(nullptr);
  2315. }
  2316. if (type == "MAN") {
  2317. return this->GetManDestination(nullptr);
  2318. }
  2319. if (type == "DOC") {
  2320. return this->GetDocDestination(nullptr);
  2321. }
  2322. if (type == "LIBEXEC") {
  2323. return this->GetProgramExecutablesDestination(nullptr);
  2324. }
  2325. return "";
  2326. }
  2327. } // namespace
  2328. bool cmInstallCommand(std::vector<std::string> const& args,
  2329. cmExecutionStatus& status)
  2330. {
  2331. // Allow calling with no arguments so that arguments may be built up
  2332. // using a variable that may be left empty.
  2333. if (args.empty()) {
  2334. return true;
  2335. }
  2336. // Enable the install target.
  2337. status.GetMakefile().GetGlobalGenerator()->EnableInstallTarget();
  2338. static cmSubcommandTable const subcommand{
  2339. { "SCRIPT"_s, HandleScriptMode },
  2340. { "CODE"_s, HandleScriptMode },
  2341. { "TARGETS"_s, HandleTargetsMode },
  2342. { "IMPORTED_RUNTIME_ARTIFACTS"_s, HandleImportedRuntimeArtifactsMode },
  2343. { "FILES"_s, HandleFilesMode },
  2344. { "PROGRAMS"_s, HandleFilesMode },
  2345. { "DIRECTORY"_s, HandleDirectoryMode },
  2346. { "EXPORT"_s, HandleExportMode },
  2347. { "EXPORT_ANDROID_MK"_s, HandleExportAndroidMKMode },
  2348. { "PACKAGE_INFO"_s, HandlePackageInfoMode },
  2349. { "RUNTIME_DEPENDENCY_SET"_s, HandleRuntimeDependencySetMode },
  2350. };
  2351. return subcommand(args[0], args, status);
  2352. }