cmInstallCommand.cxx 98 KB

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