cmInstallCommand.cxx 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstallCommand.h"
  4. #include <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 "cmPolicies.h"
  45. #include "cmRange.h"
  46. #include "cmRuntimeDependencyArchive.h"
  47. #include "cmStateTypes.h"
  48. #include "cmStringAlgorithms.h"
  49. #include "cmSubcommandTable.h"
  50. #include "cmSystemTools.h"
  51. #include "cmTarget.h"
  52. #include "cmTargetExport.h"
  53. #include "cmValue.h"
  54. class cmListFileBacktrace;
  55. namespace {
  56. struct RuntimeDependenciesArgs
  57. {
  58. ArgumentParser::MaybeEmpty<std::vector<std::string>> Directories;
  59. ArgumentParser::MaybeEmpty<std::vector<std::string>> PreIncludeRegexes;
  60. ArgumentParser::MaybeEmpty<std::vector<std::string>> PreExcludeRegexes;
  61. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeRegexes;
  62. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeRegexes;
  63. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeFiles;
  64. ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeFiles;
  65. };
  66. auto const RuntimeDependenciesArgHelper =
  67. cmArgumentParser<RuntimeDependenciesArgs>{}
  68. .Bind("DIRECTORIES"_s, &RuntimeDependenciesArgs::Directories)
  69. .Bind("PRE_INCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreIncludeRegexes)
  70. .Bind("PRE_EXCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreExcludeRegexes)
  71. .Bind("POST_INCLUDE_REGEXES"_s,
  72. &RuntimeDependenciesArgs::PostIncludeRegexes)
  73. .Bind("POST_EXCLUDE_REGEXES"_s,
  74. &RuntimeDependenciesArgs::PostExcludeRegexes)
  75. .Bind("POST_INCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostIncludeFiles)
  76. .Bind("POST_EXCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostExcludeFiles);
  77. class Helper
  78. {
  79. public:
  80. Helper(cmExecutionStatus& status)
  81. : Status(status)
  82. , Makefile(&status.GetMakefile())
  83. {
  84. this->DefaultComponentName = this->Makefile->GetSafeDefinition(
  85. "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
  86. if (this->DefaultComponentName.empty()) {
  87. this->DefaultComponentName = "Unspecified";
  88. }
  89. }
  90. void SetError(std::string const& err) { this->Status.SetError(err); }
  91. bool MakeFilesFullPath(const char* modeName,
  92. const std::vector<std::string>& relFiles,
  93. std::vector<std::string>& absFiles);
  94. bool MakeFilesFullPath(const char* modeName, const std::string& basePath,
  95. const std::vector<std::string>& relFiles,
  96. std::vector<std::string>& absFiles);
  97. bool CheckCMP0006() const;
  98. std::string GetDestination(const cmInstallCommandArguments* args,
  99. const std::string& varName,
  100. const std::string& guess) const;
  101. std::string GetRuntimeDestination(
  102. const cmInstallCommandArguments* args) const;
  103. std::string GetSbinDestination(const cmInstallCommandArguments* args) const;
  104. std::string GetArchiveDestination(
  105. const cmInstallCommandArguments* args) const;
  106. std::string GetLibraryDestination(
  107. const cmInstallCommandArguments* args) const;
  108. std::string GetCxxModulesBmiDestination(
  109. const cmInstallCommandArguments* args) const;
  110. std::string GetIncludeDestination(
  111. const cmInstallCommandArguments* args) const;
  112. std::string GetSysconfDestination(
  113. const cmInstallCommandArguments* args) const;
  114. std::string GetSharedStateDestination(
  115. const cmInstallCommandArguments* args) const;
  116. std::string GetLocalStateDestination(
  117. const cmInstallCommandArguments* args) const;
  118. std::string GetRunStateDestination(
  119. const cmInstallCommandArguments* args) const;
  120. std::string GetDataRootDestination(
  121. const cmInstallCommandArguments* args) const;
  122. std::string GetDataDestination(const cmInstallCommandArguments* args) const;
  123. std::string GetInfoDestination(const cmInstallCommandArguments* args) const;
  124. std::string GetLocaleDestination(
  125. const cmInstallCommandArguments* args) const;
  126. std::string GetManDestination(const cmInstallCommandArguments* args) const;
  127. std::string GetDocDestination(const cmInstallCommandArguments* args) const;
  128. std::string GetProgramExecutablesDestination(
  129. const cmInstallCommandArguments* args) const;
  130. std::string GetDestinationForType(const cmInstallCommandArguments* args,
  131. const std::string& type) const;
  132. cmExecutionStatus& Status;
  133. cmMakefile* Makefile;
  134. std::string DefaultComponentName;
  135. };
  136. std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator(
  137. cmTarget& target, const cmInstallCommandArguments& args, bool impLib,
  138. cmListFileBacktrace const& backtrace, const std::string& destination,
  139. bool forceOpt = false, bool namelink = false)
  140. {
  141. cmInstallGenerator::MessageLevel message =
  142. cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
  143. target.SetHaveInstallRule(true);
  144. const std::string& 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, const cmInstallCommandArguments& 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, const std::vector<std::string>& absFiles,
  164. const cmInstallCommandArguments& args, bool programs,
  165. const std::string& 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, const std::vector<std::string>& absFiles,
  177. const cmInstallCommandArguments& 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. const std::string& destination, const cmInstallCommandArguments& 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. const cmInstallCommandArguments& runtimeArgs,
  197. const cmInstallCommandArguments& libraryArgs,
  198. const cmInstallCommandArguments& 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. [](const cmInstallCommandFileSetArguments& 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. [](const cmInstallCommandFileSetArguments& 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. [](const cmInstallCommandFileSetArguments& 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. [](const cmInstallCommandFileSetArguments& 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. [](const cmInstallCommandFileSetArguments& 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. [=](const std::string& name) -> bool {
  734. return !std::any_of(
  735. fileSetArgs.begin(), fileSetArgs.end(),
  736. [=](const cmInstallCommandFileSetArguments& 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. } else if (!runtimeArgs.GetDestination().empty()) {
  958. if (helper.CheckCMP0006()) {
  959. // For CMake 2.4 compatibility fallback to the RUNTIME
  960. // properties.
  961. bundleGenerator = CreateInstallTargetGenerator(
  962. target, runtimeArgs, false, helper.Makefile->GetBacktrace());
  963. }
  964. }
  965. if (!bundleGenerator) {
  966. status.SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for "
  967. "MACOSX_BUNDLE executable target \"",
  968. target.GetName(), "\"."));
  969. return false;
  970. }
  971. if (runtimeDependencySet) {
  972. if (!AddBundleExecutable(helper, runtimeDependencySet,
  973. bundleGenerator.get())) {
  974. return false;
  975. }
  976. }
  977. } else {
  978. // Executables use the RUNTIME properties.
  979. if (!runtimeArgs.GetDestination().empty()) {
  980. artifactsSpecified = true;
  981. }
  982. runtimeGenerator = CreateInstallTargetGenerator(
  983. target, runtimeArgs, false, helper.Makefile->GetBacktrace(),
  984. helper.GetRuntimeDestination(&runtimeArgs));
  985. if (runtimeDependencySet) {
  986. runtimeDependencySet->AddExecutable(runtimeGenerator.get());
  987. }
  988. }
  989. // On DLL platforms an executable may also have an import
  990. // library. Install it to the archive destination if it
  991. // exists.
  992. if ((target.IsDLLPlatform() || target.IsAIX()) &&
  993. !archiveArgs.GetDestination().empty() &&
  994. target.IsExecutableWithExports()) {
  995. // The import library uses the ARCHIVE properties.
  996. artifactsSpecified = true;
  997. archiveGenerator = CreateInstallTargetGenerator(
  998. target, archiveArgs, true, helper.Makefile->GetBacktrace(), true);
  999. }
  1000. } break;
  1001. case cmStateEnums::INTERFACE_LIBRARY:
  1002. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  1003. // only effect of that is to make it exportable. It installs no
  1004. // other files itself.
  1005. default:
  1006. // This should never happen due to the above type check.
  1007. // Ignore the case.
  1008. break;
  1009. }
  1010. // These well-known sets of files are installed *automatically* for
  1011. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  1012. // FRAMEWORK. For other target types or on other platforms, they are not
  1013. // installed automatically and so we need to create install files
  1014. // generators for them.
  1015. bool createInstallGeneratorsForTargetFileSets = true;
  1016. if (target.IsFrameworkOnApple()) {
  1017. createInstallGeneratorsForTargetFileSets = false;
  1018. }
  1019. if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) {
  1020. cmValue files = target.GetProperty("PRIVATE_HEADER");
  1021. if (cmNonempty(files)) {
  1022. cmList relFiles{ *files };
  1023. std::vector<std::string> absFiles;
  1024. if (!helper.MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) {
  1025. return false;
  1026. }
  1027. // Create the files install generator.
  1028. if (!artifactsSpecified ||
  1029. !privateHeaderArgs.GetDestination().empty()) {
  1030. privateHeaderGenerator = CreateInstallFilesGenerator(
  1031. helper.Makefile, absFiles, privateHeaderArgs, false,
  1032. helper.GetIncludeDestination(&privateHeaderArgs));
  1033. } else {
  1034. std::ostringstream e;
  1035. e << "Target " << target.GetName() << " has "
  1036. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  1037. helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  1038. }
  1039. }
  1040. files = target.GetProperty("PUBLIC_HEADER");
  1041. if (cmNonempty(files)) {
  1042. cmList relFiles{ *files };
  1043. std::vector<std::string> absFiles;
  1044. if (!helper.MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) {
  1045. return false;
  1046. }
  1047. // Create the files install generator.
  1048. if (!artifactsSpecified ||
  1049. !publicHeaderArgs.GetDestination().empty()) {
  1050. publicHeaderGenerator = CreateInstallFilesGenerator(
  1051. helper.Makefile, absFiles, publicHeaderArgs, false,
  1052. helper.GetIncludeDestination(&publicHeaderArgs));
  1053. } else {
  1054. std::ostringstream e;
  1055. e << "Target " << target.GetName() << " has "
  1056. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  1057. helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  1058. }
  1059. }
  1060. files = target.GetProperty("RESOURCE");
  1061. if (cmNonempty(files)) {
  1062. cmList relFiles{ *files };
  1063. std::vector<std::string> absFiles;
  1064. if (!helper.MakeFilesFullPath("RESOURCE", relFiles, absFiles)) {
  1065. return false;
  1066. }
  1067. // Create the files install generator.
  1068. if (!resourceArgs.GetDestination().empty()) {
  1069. resourceGenerator = CreateInstallFilesGenerator(
  1070. helper.Makefile, absFiles, resourceArgs, false);
  1071. } else if (!target.IsAppBundleOnApple()) {
  1072. helper.Makefile->IssueMessage(
  1073. MessageType::AUTHOR_WARNING,
  1074. cmStrCat("Target ", target.GetName(),
  1075. " has RESOURCE files but no RESOURCE DESTINATION."));
  1076. }
  1077. }
  1078. }
  1079. if (!namelinkOnly) {
  1080. for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
  1081. if (auto* fileSet = target.GetFileSet(fileSetArgs[i].GetFileSet())) {
  1082. cmList interfaceFileSetEntries{ target.GetSafeProperty(
  1083. cmTarget::GetInterfaceFileSetsPropertyName(fileSet->GetType())) };
  1084. if (std::find(interfaceFileSetEntries.begin(),
  1085. interfaceFileSetEntries.end(),
  1086. fileSetArgs[i].GetFileSet()) !=
  1087. interfaceFileSetEntries.end()) {
  1088. std::string destination;
  1089. if (fileSet->GetType() == "HEADERS"_s) {
  1090. destination = helper.GetIncludeDestination(&fileSetArgs[i]);
  1091. } else {
  1092. destination = fileSetArgs[i].GetDestination();
  1093. if (destination.empty()) {
  1094. status.SetError(cmStrCat(
  1095. "TARGETS given no FILE_SET DESTINATION for target \"",
  1096. target.GetName(), "\" file set \"", fileSet->GetName(),
  1097. "\"."));
  1098. return false;
  1099. }
  1100. }
  1101. fileSetGenerators.push_back(CreateInstallFileSetGenerator(
  1102. helper, target, fileSet, destination, fileSetArgs[i]));
  1103. installsFileSet[i] = true;
  1104. }
  1105. }
  1106. }
  1107. }
  1108. if (!cxxModuleBmiArgs.GetDestination().empty()) {
  1109. cxxModuleBmiGenerator = cm::make_unique<cmInstallCxxModuleBmiGenerator>(
  1110. target.GetName(),
  1111. helper.GetCxxModulesBmiDestination(&cxxModuleBmiArgs),
  1112. cxxModuleBmiArgs.GetPermissions(),
  1113. cxxModuleBmiArgs.GetConfigurations(), cxxModuleBmiArgs.GetComponent(),
  1114. cmInstallGenerator::SelectMessageLevel(target.GetMakefile()),
  1115. cxxModuleBmiArgs.GetExcludeFromAll(), cxxModuleBmiArgs.GetOptional(),
  1116. helper.Makefile->GetBacktrace());
  1117. target.SetHaveInstallRule(true);
  1118. }
  1119. // Add this install rule to an export if one was specified.
  1120. if (!addTargetExport()) {
  1121. return false;
  1122. }
  1123. // Keep track of whether we're installing anything in each category
  1124. installsArchive = installsArchive || archiveGenerator;
  1125. installsLibrary = installsLibrary || libraryGenerator;
  1126. installsNamelink = installsNamelink || namelinkGenerator;
  1127. installsImportlink = installsImportlink || importlinkGenerator;
  1128. installsRuntime = installsRuntime || runtimeGenerator;
  1129. installsObject = installsObject || objectGenerator;
  1130. installsFramework = installsFramework || frameworkGenerator;
  1131. installsBundle = installsBundle || bundleGenerator;
  1132. installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator;
  1133. installsPublicHeader = installsPublicHeader || publicHeaderGenerator;
  1134. installsResource = installsResource || resourceGenerator;
  1135. installsCxxModuleBmi = installsCxxModuleBmi || cxxModuleBmiGenerator;
  1136. helper.Makefile->AddInstallGenerator(std::move(archiveGenerator));
  1137. helper.Makefile->AddInstallGenerator(std::move(libraryGenerator));
  1138. helper.Makefile->AddInstallGenerator(std::move(namelinkGenerator));
  1139. helper.Makefile->AddInstallGenerator(std::move(importlinkGenerator));
  1140. helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator));
  1141. helper.Makefile->AddInstallGenerator(std::move(objectGenerator));
  1142. helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator));
  1143. helper.Makefile->AddInstallGenerator(std::move(bundleGenerator));
  1144. helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator));
  1145. helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator));
  1146. helper.Makefile->AddInstallGenerator(std::move(resourceGenerator));
  1147. for (auto& gen : fileSetGenerators) {
  1148. helper.Makefile->AddInstallGenerator(std::move(gen));
  1149. }
  1150. helper.Makefile->AddInstallGenerator(std::move(cxxModuleBmiGenerator));
  1151. }
  1152. if (runtimeDependenciesArgVector && !runtimeDependencySet->Empty()) {
  1153. AddInstallRuntimeDependenciesGenerator(
  1154. helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs,
  1155. std::move(runtimeDependenciesArgs), installsRuntime, installsLibrary,
  1156. installsFramework);
  1157. }
  1158. // Tell the global generator about any installation component names
  1159. // specified
  1160. if (installsArchive) {
  1161. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1162. archiveArgs.GetComponent());
  1163. }
  1164. if (installsLibrary) {
  1165. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1166. libraryArgs.GetComponent());
  1167. }
  1168. if (installsNamelink) {
  1169. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1170. libraryArgs.GetNamelinkComponent());
  1171. }
  1172. if (installsImportlink) {
  1173. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1174. archiveArgs.GetNamelinkComponent());
  1175. }
  1176. if (installsRuntime) {
  1177. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1178. runtimeArgs.GetComponent());
  1179. }
  1180. if (installsObject) {
  1181. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1182. objectArgs.GetComponent());
  1183. }
  1184. if (installsFramework) {
  1185. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1186. frameworkArgs.GetComponent());
  1187. }
  1188. if (installsBundle) {
  1189. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1190. bundleArgs.GetComponent());
  1191. }
  1192. if (installsPrivateHeader) {
  1193. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1194. privateHeaderArgs.GetComponent());
  1195. }
  1196. if (installsPublicHeader) {
  1197. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1198. publicHeaderArgs.GetComponent());
  1199. }
  1200. if (installsResource) {
  1201. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1202. resourceArgs.GetComponent());
  1203. }
  1204. for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
  1205. if (installsFileSet[i]) {
  1206. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1207. fileSetArgs[i].GetComponent());
  1208. }
  1209. }
  1210. if (installsCxxModuleBmi) {
  1211. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1212. cxxModuleBmiArgs.GetComponent());
  1213. }
  1214. return true;
  1215. }
  1216. bool HandleImportedRuntimeArtifactsMode(std::vector<std::string> const& args,
  1217. cmExecutionStatus& status)
  1218. {
  1219. Helper helper(status);
  1220. // This is the IMPORTED_RUNTIME_ARTIFACTS mode.
  1221. std::vector<cmTarget*> targets;
  1222. struct ArgVectors
  1223. {
  1224. ArgumentParser::MaybeEmpty<std::vector<std::string>> Library;
  1225. ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime;
  1226. ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework;
  1227. ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle;
  1228. };
  1229. static auto const argHelper = cmArgumentParser<ArgVectors>{}
  1230. .Bind("LIBRARY"_s, &ArgVectors::Library)
  1231. .Bind("RUNTIME"_s, &ArgVectors::Runtime)
  1232. .Bind("FRAMEWORK"_s, &ArgVectors::Framework)
  1233. .Bind("BUNDLE"_s, &ArgVectors::Bundle);
  1234. std::vector<std::string> genericArgVector;
  1235. ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
  1236. // now parse the generic args (i.e. the ones not specialized on LIBRARY,
  1237. // RUNTIME etc. (see above)
  1238. ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList;
  1239. std::string runtimeDependencySetArg;
  1240. std::vector<std::string> unknownArgs;
  1241. cmInstallCommandArguments genericArgs(helper.DefaultComponentName,
  1242. *helper.Makefile);
  1243. genericArgs.Bind("IMPORTED_RUNTIME_ARTIFACTS"_s, targetList)
  1244. .Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg);
  1245. genericArgs.Parse(genericArgVector, &unknownArgs);
  1246. bool success = genericArgs.Finalize();
  1247. cmInstallCommandArguments libraryArgs(helper.DefaultComponentName,
  1248. *helper.Makefile);
  1249. cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName,
  1250. *helper.Makefile);
  1251. cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName,
  1252. *helper.Makefile);
  1253. cmInstallCommandArguments bundleArgs(helper.DefaultComponentName,
  1254. *helper.Makefile);
  1255. // now parse the args for specific parts of the target (e.g. LIBRARY,
  1256. // RUNTIME etc.
  1257. libraryArgs.Parse(argVectors.Library, &unknownArgs);
  1258. runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
  1259. frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
  1260. bundleArgs.Parse(argVectors.Bundle, &unknownArgs);
  1261. if (!unknownArgs.empty()) {
  1262. // Unknown argument.
  1263. status.SetError(
  1264. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given unknown argument \"",
  1265. unknownArgs[0], "\"."));
  1266. return false;
  1267. }
  1268. // apply generic args
  1269. libraryArgs.SetGenericArguments(&genericArgs);
  1270. runtimeArgs.SetGenericArguments(&genericArgs);
  1271. frameworkArgs.SetGenericArguments(&genericArgs);
  1272. bundleArgs.SetGenericArguments(&genericArgs);
  1273. success = success && libraryArgs.Finalize();
  1274. success = success && runtimeArgs.Finalize();
  1275. success = success && frameworkArgs.Finalize();
  1276. success = success && bundleArgs.Finalize();
  1277. if (!success) {
  1278. return false;
  1279. }
  1280. cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr;
  1281. if (!runtimeDependencySetArg.empty()) {
  1282. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  1283. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  1284. system)) {
  1285. status.SetError(
  1286. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS RUNTIME_DEPENDENCY_SET is not "
  1287. "supported on system \"",
  1288. system, '"'));
  1289. return false;
  1290. }
  1291. runtimeDependencySet =
  1292. helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet(
  1293. runtimeDependencySetArg);
  1294. }
  1295. // Check if there is something to do.
  1296. if (targetList.empty()) {
  1297. return true;
  1298. }
  1299. for (std::string const& tgt : targetList) {
  1300. if (helper.Makefile->IsAlias(tgt)) {
  1301. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"",
  1302. tgt, "\" which is an alias."));
  1303. return false;
  1304. }
  1305. // Lookup this target in the current directory.
  1306. cmTarget* target = helper.Makefile->FindTargetToUse(tgt);
  1307. if (!target || !target->IsImported()) {
  1308. // If no local target has been found, find it in the global scope.
  1309. cmTarget* const global_target =
  1310. helper.Makefile->GetGlobalGenerator()->FindTarget(
  1311. tgt, { cmStateEnums::TargetDomain::NATIVE });
  1312. if (global_target && global_target->IsImported()) {
  1313. target = global_target;
  1314. }
  1315. }
  1316. if (target) {
  1317. // Found the target. Check its type.
  1318. if (target->GetType() != cmStateEnums::EXECUTABLE &&
  1319. target->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1320. target->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1321. status.SetError(
  1322. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"", tgt,
  1323. "\" which is not an executable, library, or module."));
  1324. return false;
  1325. }
  1326. // Store the target in the list to be installed.
  1327. targets.push_back(target);
  1328. } else {
  1329. // Did not find the target.
  1330. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"",
  1331. tgt, "\" which does not exist."));
  1332. return false;
  1333. }
  1334. }
  1335. // Keep track of whether we will be performing an installation of
  1336. // any files of the given type.
  1337. bool installsLibrary = false;
  1338. bool installsRuntime = false;
  1339. bool installsFramework = false;
  1340. bool installsBundle = false;
  1341. auto const createInstallGenerator =
  1342. [helper](cmTarget& target, const cmInstallCommandArguments& typeArgs,
  1343. const std::string& destination)
  1344. -> std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> {
  1345. return cm::make_unique<cmInstallImportedRuntimeArtifactsGenerator>(
  1346. target.GetName(), destination, typeArgs.GetPermissions(),
  1347. typeArgs.GetConfigurations(), typeArgs.GetComponent(),
  1348. cmInstallGenerator::SelectMessageLevel(helper.Makefile),
  1349. typeArgs.GetExcludeFromAll(), typeArgs.GetOptional(),
  1350. helper.Makefile->GetBacktrace());
  1351. };
  1352. // Generate install script code to install the given targets.
  1353. for (cmTarget* ti : targets) {
  1354. // Handle each target type.
  1355. cmTarget& target = *ti;
  1356. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1357. libraryGenerator;
  1358. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1359. runtimeGenerator;
  1360. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1361. frameworkGenerator;
  1362. std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator>
  1363. bundleGenerator;
  1364. switch (target.GetType()) {
  1365. case cmStateEnums::SHARED_LIBRARY:
  1366. if (target.IsDLLPlatform()) {
  1367. runtimeGenerator = createInstallGenerator(
  1368. target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs));
  1369. if (runtimeDependencySet) {
  1370. runtimeDependencySet->AddLibrary(runtimeGenerator.get());
  1371. }
  1372. } else if (target.IsFrameworkOnApple()) {
  1373. if (frameworkArgs.GetDestination().empty()) {
  1374. status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no "
  1375. "FRAMEWORK DESTINATION for shared "
  1376. "library FRAMEWORK target \"",
  1377. target.GetName(), "\"."));
  1378. return false;
  1379. }
  1380. frameworkGenerator = createInstallGenerator(
  1381. target, frameworkArgs, frameworkArgs.GetDestination());
  1382. if (runtimeDependencySet) {
  1383. runtimeDependencySet->AddLibrary(frameworkGenerator.get());
  1384. }
  1385. } else {
  1386. libraryGenerator = createInstallGenerator(
  1387. target, libraryArgs, helper.GetLibraryDestination(&libraryArgs));
  1388. if (runtimeDependencySet) {
  1389. runtimeDependencySet->AddLibrary(libraryGenerator.get());
  1390. }
  1391. }
  1392. break;
  1393. case cmStateEnums::MODULE_LIBRARY:
  1394. libraryGenerator = createInstallGenerator(
  1395. target, libraryArgs, helper.GetLibraryDestination(&libraryArgs));
  1396. if (runtimeDependencySet) {
  1397. runtimeDependencySet->AddModule(libraryGenerator.get());
  1398. }
  1399. break;
  1400. case cmStateEnums::EXECUTABLE:
  1401. if (target.IsAppBundleOnApple()) {
  1402. if (bundleArgs.GetDestination().empty()) {
  1403. status.SetError(
  1404. cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no BUNDLE "
  1405. "DESTINATION for MACOSX_BUNDLE executable target \"",
  1406. target.GetName(), "\"."));
  1407. return false;
  1408. }
  1409. bundleGenerator = createInstallGenerator(
  1410. target, bundleArgs, bundleArgs.GetDestination());
  1411. if (runtimeDependencySet) {
  1412. if (!AddBundleExecutable(helper, runtimeDependencySet,
  1413. bundleGenerator.get())) {
  1414. return false;
  1415. }
  1416. }
  1417. } else {
  1418. runtimeGenerator = createInstallGenerator(
  1419. target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs));
  1420. if (runtimeDependencySet) {
  1421. runtimeDependencySet->AddExecutable(runtimeGenerator.get());
  1422. }
  1423. }
  1424. break;
  1425. default:
  1426. assert(false && "This should never happen");
  1427. break;
  1428. }
  1429. // Keep track of whether we're installing anything in each category
  1430. installsLibrary = installsLibrary || libraryGenerator;
  1431. installsRuntime = installsRuntime || runtimeGenerator;
  1432. installsFramework = installsFramework || frameworkGenerator;
  1433. installsBundle = installsBundle || bundleGenerator;
  1434. helper.Makefile->AddInstallGenerator(std::move(libraryGenerator));
  1435. helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator));
  1436. helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator));
  1437. helper.Makefile->AddInstallGenerator(std::move(bundleGenerator));
  1438. }
  1439. // Tell the global generator about any installation component names
  1440. // specified
  1441. if (installsLibrary) {
  1442. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1443. libraryArgs.GetComponent());
  1444. }
  1445. if (installsRuntime) {
  1446. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1447. runtimeArgs.GetComponent());
  1448. }
  1449. if (installsFramework) {
  1450. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1451. frameworkArgs.GetComponent());
  1452. }
  1453. if (installsBundle) {
  1454. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1455. bundleArgs.GetComponent());
  1456. }
  1457. return true;
  1458. }
  1459. bool HandleFilesMode(std::vector<std::string> const& args,
  1460. cmExecutionStatus& status)
  1461. {
  1462. Helper helper(status);
  1463. // This is the FILES mode.
  1464. bool programs = (args[0] == "PROGRAMS");
  1465. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1466. ArgumentParser::MaybeEmpty<std::vector<std::string>> files;
  1467. ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files);
  1468. std::vector<std::string> unknownArgs;
  1469. ica.Parse(args, &unknownArgs);
  1470. if (!unknownArgs.empty()) {
  1471. // Unknown argument.
  1472. status.SetError(
  1473. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1474. return false;
  1475. }
  1476. std::string type = ica.GetType();
  1477. if (!type.empty() && allowedTypes.count(type) == 0) {
  1478. status.SetError(
  1479. cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument."));
  1480. return false;
  1481. }
  1482. const std::vector<std::string>& filesVector = files;
  1483. // Check if there is something to do.
  1484. if (filesVector.empty()) {
  1485. return true;
  1486. }
  1487. if (!ica.GetRename().empty() && filesVector.size() > 1) {
  1488. // The rename option works only with one file.
  1489. status.SetError(
  1490. cmStrCat(args[0], " given RENAME option with more than one file."));
  1491. return false;
  1492. }
  1493. std::vector<std::string> absFiles;
  1494. if (!helper.MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) {
  1495. return false;
  1496. }
  1497. cmPolicies::PolicyStatus policyStatus =
  1498. helper.Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  1499. cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator();
  1500. for (std::string const& file : filesVector) {
  1501. if (gg->IsExportedTargetsFile(file)) {
  1502. const char* modal = nullptr;
  1503. std::ostringstream e;
  1504. MessageType messageType = MessageType::AUTHOR_WARNING;
  1505. switch (policyStatus) {
  1506. case cmPolicies::WARN:
  1507. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  1508. modal = "should";
  1509. CM_FALLTHROUGH;
  1510. case cmPolicies::OLD:
  1511. break;
  1512. case cmPolicies::NEW:
  1513. modal = "may";
  1514. messageType = MessageType::FATAL_ERROR;
  1515. break;
  1516. }
  1517. if (modal) {
  1518. e << "The file\n " << file
  1519. << "\nwas generated by the export() "
  1520. "command. It "
  1521. << modal
  1522. << " not be installed with the "
  1523. "install() command. Use the install(EXPORT) mechanism "
  1524. "instead. See the cmake-packages(7) manual for more.\n";
  1525. helper.Makefile->IssueMessage(messageType, e.str());
  1526. if (messageType == MessageType::FATAL_ERROR) {
  1527. return false;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. if (!ica.Finalize()) {
  1533. return false;
  1534. }
  1535. if (!type.empty() && !ica.GetDestination().empty()) {
  1536. status.SetError(cmStrCat(args[0],
  1537. " given both TYPE and DESTINATION arguments. "
  1538. "You may only specify one."));
  1539. return false;
  1540. }
  1541. std::string destination = helper.GetDestinationForType(&ica, type);
  1542. if (destination.empty()) {
  1543. // A destination is required.
  1544. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1545. return false;
  1546. }
  1547. // Create the files install generator.
  1548. helper.Makefile->AddInstallGenerator(CreateInstallFilesGenerator(
  1549. helper.Makefile, absFiles, ica, programs, destination));
  1550. // Tell the global generator about any installation component names
  1551. // specified.
  1552. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  1553. ica.GetComponent());
  1554. return true;
  1555. }
  1556. bool HandleDirectoryMode(std::vector<std::string> const& args,
  1557. cmExecutionStatus& status)
  1558. {
  1559. Helper helper(status);
  1560. enum Doing
  1561. {
  1562. DoingNone,
  1563. DoingDirs,
  1564. DoingDestination,
  1565. DoingPattern,
  1566. DoingRegex,
  1567. DoingPermsFile,
  1568. DoingPermsDir,
  1569. DoingPermsMatch,
  1570. DoingConfigurations,
  1571. DoingComponent,
  1572. DoingType
  1573. };
  1574. Doing doing = DoingDirs;
  1575. bool in_match_mode = false;
  1576. bool optional = false;
  1577. bool exclude_from_all = false;
  1578. bool message_never = false;
  1579. std::vector<std::string> dirs;
  1580. cm::optional<std::string> destination;
  1581. std::string permissions_file;
  1582. std::string permissions_dir;
  1583. std::vector<std::string> configurations;
  1584. std::string component = helper.DefaultComponentName;
  1585. std::string literal_args;
  1586. std::string type;
  1587. for (unsigned int i = 1; i < args.size(); ++i) {
  1588. if (args[i] == "DESTINATION") {
  1589. if (in_match_mode) {
  1590. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1591. "\" after PATTERN or REGEX."));
  1592. return false;
  1593. }
  1594. // Switch to setting the destination property.
  1595. doing = DoingDestination;
  1596. } else if (args[i] == "TYPE") {
  1597. if (in_match_mode) {
  1598. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1599. "\" after PATTERN or REGEX."));
  1600. return false;
  1601. }
  1602. // Switch to setting the type.
  1603. doing = DoingType;
  1604. } else if (args[i] == "OPTIONAL") {
  1605. if (in_match_mode) {
  1606. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1607. "\" after PATTERN or REGEX."));
  1608. return false;
  1609. }
  1610. // Mark the rule as optional.
  1611. optional = true;
  1612. doing = DoingNone;
  1613. } else if (args[i] == "MESSAGE_NEVER") {
  1614. if (in_match_mode) {
  1615. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1616. "\" after PATTERN or REGEX."));
  1617. return false;
  1618. }
  1619. // Mark the rule as quiet.
  1620. message_never = true;
  1621. doing = DoingNone;
  1622. } else if (args[i] == "PATTERN") {
  1623. // Switch to a new pattern match rule.
  1624. doing = DoingPattern;
  1625. in_match_mode = true;
  1626. } else if (args[i] == "REGEX") {
  1627. // Switch to a new regex match rule.
  1628. doing = DoingRegex;
  1629. in_match_mode = true;
  1630. } else if (args[i] == "EXCLUDE") {
  1631. // Add this property to the current match rule.
  1632. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
  1633. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1634. "\" before a PATTERN or REGEX is given."));
  1635. return false;
  1636. }
  1637. literal_args += " EXCLUDE";
  1638. doing = DoingNone;
  1639. } else if (args[i] == "PERMISSIONS") {
  1640. if (!in_match_mode) {
  1641. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1642. "\" before a PATTERN or REGEX is given."));
  1643. return false;
  1644. }
  1645. // Switch to setting the current match permissions property.
  1646. literal_args += " PERMISSIONS";
  1647. doing = DoingPermsMatch;
  1648. } else if (args[i] == "FILE_PERMISSIONS") {
  1649. if (in_match_mode) {
  1650. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1651. "\" after PATTERN or REGEX."));
  1652. return false;
  1653. }
  1654. // Switch to setting the file permissions property.
  1655. doing = DoingPermsFile;
  1656. } else if (args[i] == "DIRECTORY_PERMISSIONS") {
  1657. if (in_match_mode) {
  1658. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1659. "\" after PATTERN or REGEX."));
  1660. return false;
  1661. }
  1662. // Switch to setting the directory permissions property.
  1663. doing = DoingPermsDir;
  1664. } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
  1665. if (in_match_mode) {
  1666. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1667. "\" after PATTERN or REGEX."));
  1668. return false;
  1669. }
  1670. // Add this option literally.
  1671. literal_args += " USE_SOURCE_PERMISSIONS";
  1672. doing = DoingNone;
  1673. } else if (args[i] == "FILES_MATCHING") {
  1674. if (in_match_mode) {
  1675. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1676. "\" after PATTERN or REGEX."));
  1677. return false;
  1678. }
  1679. // Add this option literally.
  1680. literal_args += " FILES_MATCHING";
  1681. doing = DoingNone;
  1682. } else if (args[i] == "CONFIGURATIONS") {
  1683. if (in_match_mode) {
  1684. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1685. "\" after PATTERN or REGEX."));
  1686. return false;
  1687. }
  1688. // Switch to setting the configurations property.
  1689. doing = DoingConfigurations;
  1690. } else if (args[i] == "COMPONENT") {
  1691. if (in_match_mode) {
  1692. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1693. "\" after PATTERN or REGEX."));
  1694. return false;
  1695. }
  1696. // Switch to setting the component property.
  1697. doing = DoingComponent;
  1698. } else if (args[i] == "EXCLUDE_FROM_ALL") {
  1699. if (in_match_mode) {
  1700. status.SetError(cmStrCat(args[0], " does not allow \"", args[i],
  1701. "\" after PATTERN or REGEX."));
  1702. return false;
  1703. }
  1704. exclude_from_all = true;
  1705. doing = DoingNone;
  1706. } else if (doing == DoingDirs) {
  1707. // Convert this directory to a full path.
  1708. std::string dir = args[i];
  1709. std::string::size_type gpos = cmGeneratorExpression::Find(dir);
  1710. if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
  1711. dir =
  1712. cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', args[i]);
  1713. }
  1714. // Make sure the name is a directory.
  1715. if (cmSystemTools::FileExists(dir, true)) {
  1716. status.SetError(cmStrCat(args[0], " given non-directory \"", args[i],
  1717. "\" to install."));
  1718. return false;
  1719. }
  1720. // Store the directory for installation.
  1721. dirs.push_back(std::move(dir));
  1722. } else if (doing == DoingConfigurations) {
  1723. configurations.push_back(args[i]);
  1724. } else if (doing == DoingDestination) {
  1725. // A trailing slash is meaningful for this form, but normalization
  1726. // preserves it if present
  1727. switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0177)) {
  1728. case cmPolicies::NEW:
  1729. destination = cmCMakePath(args[i]).Normal().String();
  1730. break;
  1731. case cmPolicies::WARN:
  1732. // We can't be certain if a warning is appropriate if there are any
  1733. // generator expressions
  1734. if (cmGeneratorExpression::Find(args[i]) == cm::string_view::npos &&
  1735. args[i] != cmCMakePath(args[i]).Normal().String()) {
  1736. status.GetMakefile().IssueMessage(
  1737. MessageType::AUTHOR_WARNING,
  1738. cmPolicies::GetPolicyWarning(cmPolicies::CMP0177));
  1739. }
  1740. CM_FALLTHROUGH;
  1741. case cmPolicies::OLD:
  1742. destination = args[i];
  1743. break;
  1744. }
  1745. doing = DoingNone;
  1746. } else if (doing == DoingType) {
  1747. if (allowedTypes.count(args[i]) == 0) {
  1748. status.SetError(cmStrCat(args[0], " given non-type \"", args[i],
  1749. "\" with TYPE argument."));
  1750. return false;
  1751. }
  1752. type = args[i];
  1753. doing = DoingNone;
  1754. } else if (doing == DoingPattern) {
  1755. // Convert the pattern to a regular expression. Require a
  1756. // leading slash and trailing end-of-string in the matched
  1757. // string to make sure the pattern matches only whole file
  1758. // names.
  1759. literal_args += " REGEX \"/";
  1760. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1761. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1762. literal_args += regex;
  1763. literal_args += "$\"";
  1764. doing = DoingNone;
  1765. } else if (doing == DoingRegex) {
  1766. literal_args += " REGEX \"";
  1767. // Match rules are case-insensitive on some platforms.
  1768. #if defined(_WIN32) || defined(__APPLE__)
  1769. std::string regex = cmSystemTools::LowerCase(args[i]);
  1770. #else
  1771. std::string regex = args[i];
  1772. #endif
  1773. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1774. literal_args += regex;
  1775. literal_args += "\"";
  1776. doing = DoingNone;
  1777. } else if (doing == DoingComponent) {
  1778. component = args[i];
  1779. doing = DoingNone;
  1780. } else if (doing == DoingPermsFile) {
  1781. // Check the requested permission.
  1782. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1783. permissions_file)) {
  1784. status.SetError(cmStrCat(args[0], " given invalid file permission \"",
  1785. args[i], "\"."));
  1786. return false;
  1787. }
  1788. } else if (doing == DoingPermsDir) {
  1789. // Check the requested permission.
  1790. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1791. permissions_dir)) {
  1792. status.SetError(cmStrCat(
  1793. args[0], " given invalid directory permission \"", args[i], "\"."));
  1794. return false;
  1795. }
  1796. } else if (doing == DoingPermsMatch) {
  1797. // Check the requested permission.
  1798. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1799. literal_args)) {
  1800. status.SetError(
  1801. cmStrCat(args[0], " given invalid permission \"", args[i], "\"."));
  1802. return false;
  1803. }
  1804. } else {
  1805. // Unknown argument.
  1806. status.SetError(
  1807. cmStrCat(args[0], " given unknown argument \"", args[i], "\"."));
  1808. return false;
  1809. }
  1810. }
  1811. // Support installing an empty directory.
  1812. if (dirs.empty() && destination.has_value()) {
  1813. dirs.emplace_back();
  1814. }
  1815. // Check if there is something to do.
  1816. if (dirs.empty()) {
  1817. return true;
  1818. }
  1819. if (!destination.has_value()) {
  1820. if (type.empty()) {
  1821. // A destination is required.
  1822. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1823. return false;
  1824. }
  1825. destination = helper.GetDestinationForType(nullptr, type);
  1826. } else if (!type.empty()) {
  1827. status.SetError(cmStrCat(args[0],
  1828. " given both TYPE and DESTINATION "
  1829. "arguments. You may only specify one."));
  1830. return false;
  1831. }
  1832. cmInstallGenerator::MessageLevel message =
  1833. cmInstallGenerator::SelectMessageLevel(helper.Makefile, message_never);
  1834. // Create the directory install generator.
  1835. helper.Makefile->AddInstallGenerator(
  1836. cm::make_unique<cmInstallDirectoryGenerator>(
  1837. dirs, *destination, permissions_file, permissions_dir, configurations,
  1838. component, message, exclude_from_all, literal_args, optional,
  1839. helper.Makefile->GetBacktrace()));
  1840. // Tell the global generator about any installation component names
  1841. // specified.
  1842. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component);
  1843. return true;
  1844. }
  1845. bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
  1846. cmExecutionStatus& status)
  1847. {
  1848. #ifndef CMAKE_BOOTSTRAP
  1849. Helper helper(status);
  1850. // This is the EXPORT mode.
  1851. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1852. std::string exp;
  1853. std::string name_space;
  1854. bool exportOld = false;
  1855. std::string filename;
  1856. ica.Bind("EXPORT_ANDROID_MK"_s, exp);
  1857. ica.Bind("NAMESPACE"_s, name_space);
  1858. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1859. ica.Bind("FILE"_s, filename);
  1860. std::vector<std::string> unknownArgs;
  1861. ica.Parse(args, &unknownArgs);
  1862. if (!unknownArgs.empty()) {
  1863. // Unknown argument.
  1864. status.SetError(
  1865. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1866. return false;
  1867. }
  1868. if (!ica.Finalize()) {
  1869. return false;
  1870. }
  1871. // Make sure there is a destination.
  1872. if (ica.GetDestination().empty()) {
  1873. // A destination is required.
  1874. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1875. return false;
  1876. }
  1877. // Check the file name.
  1878. std::string fname = filename;
  1879. if (fname.find_first_of(":/\\") != std::string::npos) {
  1880. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1881. fname,
  1882. "\". The FILE argument may not contain a path. "
  1883. "Specify the path in the DESTINATION argument."));
  1884. return false;
  1885. }
  1886. // Check the file extension.
  1887. if (!fname.empty() &&
  1888. cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
  1889. status.SetError(cmStrCat(
  1890. args[0], " given invalid export file name \"", fname,
  1891. R"(". The FILE argument must specify a name ending in ".mk".)"));
  1892. return false;
  1893. }
  1894. if (fname.find_first_of(":/\\") != std::string::npos) {
  1895. status.SetError(
  1896. cmStrCat(args[0], " given export name \"", exp,
  1897. "\". "
  1898. "This name cannot be safely converted to a file name. "
  1899. "Specify a different export name or use the FILE option to set "
  1900. "a file name explicitly."));
  1901. return false;
  1902. }
  1903. // Use the default name
  1904. if (fname.empty()) {
  1905. fname = "Android.mk";
  1906. }
  1907. cmExportSet& exportSet =
  1908. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1909. cmInstallGenerator::MessageLevel message =
  1910. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  1911. // Create the export install generator.
  1912. helper.Makefile->AddInstallGenerator(
  1913. cm::make_unique<cmInstallAndroidMKExportGenerator>(
  1914. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  1915. ica.GetConfigurations(), ica.GetComponent(), message,
  1916. ica.GetExcludeFromAll(), std::move(fname), std::move(name_space),
  1917. helper.Makefile->GetBacktrace()));
  1918. return true;
  1919. #else
  1920. static_cast<void>(args);
  1921. status.SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake");
  1922. return false;
  1923. #endif
  1924. }
  1925. bool HandleExportMode(std::vector<std::string> const& args,
  1926. cmExecutionStatus& status)
  1927. {
  1928. Helper helper(status);
  1929. // This is the EXPORT mode.
  1930. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  1931. std::string exp;
  1932. std::string name_space;
  1933. bool exportOld = false;
  1934. std::string filename;
  1935. std::string cxx_modules_directory;
  1936. bool exportPackageDependencies = false;
  1937. ica.Bind("EXPORT"_s, exp);
  1938. ica.Bind("NAMESPACE"_s, name_space);
  1939. ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
  1940. ica.Bind("FILE"_s, filename);
  1941. ica.Bind("CXX_MODULES_DIRECTORY"_s, cxx_modules_directory);
  1942. if (cmExperimental::HasSupportEnabled(
  1943. status.GetMakefile(),
  1944. cmExperimental::Feature::ExportPackageDependencies)) {
  1945. ica.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s, exportPackageDependencies);
  1946. }
  1947. std::vector<std::string> unknownArgs;
  1948. ica.Parse(args, &unknownArgs);
  1949. if (!unknownArgs.empty()) {
  1950. // Unknown argument.
  1951. status.SetError(
  1952. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  1953. return false;
  1954. }
  1955. if (!ica.Finalize()) {
  1956. return false;
  1957. }
  1958. // Make sure there is a destination.
  1959. if (ica.GetDestination().empty()) {
  1960. // A destination is required.
  1961. status.SetError(cmStrCat(args[0], " given no DESTINATION!"));
  1962. return false;
  1963. }
  1964. // Check the file name.
  1965. std::string fname = filename;
  1966. if (fname.find_first_of(":/\\") != std::string::npos) {
  1967. status.SetError(cmStrCat(args[0], " given invalid export file name \"",
  1968. fname,
  1969. "\". "
  1970. "The FILE argument may not contain a path. "
  1971. "Specify the path in the DESTINATION argument."));
  1972. return false;
  1973. }
  1974. // Check the file extension.
  1975. if (!fname.empty() &&
  1976. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
  1977. status.SetError(
  1978. cmStrCat(args[0], " given invalid export file name \"", fname,
  1979. "\". "
  1980. "The FILE argument must specify a name ending in \".cmake\"."));
  1981. return false;
  1982. }
  1983. // Construct the file name.
  1984. if (fname.empty()) {
  1985. fname = cmStrCat(exp, ".cmake");
  1986. if (fname.find_first_of(":/\\") != std::string::npos) {
  1987. status.SetError(cmStrCat(
  1988. args[0], " given export name \"", exp,
  1989. "\". "
  1990. "This name cannot be safely converted to a file name. "
  1991. "Specify a different export name or use the FILE option to set "
  1992. "a file name explicitly."));
  1993. return false;
  1994. }
  1995. }
  1996. cmExportSet& exportSet =
  1997. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp];
  1998. if (exportOld) {
  1999. for (auto const& te : exportSet.GetTargetExports()) {
  2000. cmTarget* tgt =
  2001. helper.Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
  2002. const bool newCMP0022Behavior =
  2003. (tgt && tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  2004. tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
  2005. if (!newCMP0022Behavior) {
  2006. status.SetError(cmStrCat(
  2007. "INSTALL(EXPORT) given keyword \""
  2008. "EXPORT_LINK_INTERFACE_LIBRARIES\", but target \"",
  2009. te->TargetName, "\" does not have policy CMP0022 set to NEW."));
  2010. return false;
  2011. }
  2012. }
  2013. }
  2014. cmInstallGenerator::MessageLevel message =
  2015. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  2016. // Create the export install generator.
  2017. helper.Makefile->AddInstallGenerator(
  2018. cm::make_unique<cmInstallCMakeConfigExportGenerator>(
  2019. &exportSet, ica.GetDestination(), ica.GetPermissions(),
  2020. ica.GetConfigurations(), ica.GetComponent(), message,
  2021. ica.GetExcludeFromAll(), std::move(fname), std::move(name_space),
  2022. std::move(cxx_modules_directory), exportOld, exportPackageDependencies,
  2023. helper.Makefile->GetBacktrace()));
  2024. return true;
  2025. }
  2026. bool HandlePackageInfoMode(std::vector<std::string> const& args,
  2027. cmExecutionStatus& status)
  2028. {
  2029. #ifndef CMAKE_BOOTSTRAP
  2030. if (!cmExperimental::HasSupportEnabled(
  2031. status.GetMakefile(), cmExperimental::Feature::ExportPackageInfo)) {
  2032. status.SetError("does not recognize sub-command PACKAGE_INFO");
  2033. return false;
  2034. }
  2035. Helper helper(status);
  2036. // This is the PACKAGE_INFO mode.
  2037. cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile);
  2038. ArgumentParser::NonEmpty<std::string> pkg;
  2039. ArgumentParser::NonEmpty<std::string> appendix;
  2040. ArgumentParser::NonEmpty<std::string> exportName;
  2041. bool lowerCase = false;
  2042. ArgumentParser::NonEmpty<std::string> version;
  2043. ArgumentParser::NonEmpty<std::string> versionCompat;
  2044. ArgumentParser::NonEmpty<std::string> versionSchema;
  2045. ArgumentParser::NonEmpty<std::vector<std::string>> defaultTargets;
  2046. ArgumentParser::NonEmpty<std::vector<std::string>> defaultConfigs;
  2047. ArgumentParser::NonEmpty<std::string> cxxModulesDirectory;
  2048. ica.Bind("PACKAGE_INFO"_s, pkg);
  2049. ica.Bind("EXPORT"_s, exportName);
  2050. ica.Bind("APPENDIX"_s, appendix);
  2051. ica.Bind("LOWER_CASE_FILE"_s, lowerCase);
  2052. ica.Bind("VERSION"_s, version);
  2053. ica.Bind("COMPAT_VERSION"_s, versionCompat);
  2054. ica.Bind("VERSION_SCHEMA"_s, versionSchema);
  2055. ica.Bind("DEFAULT_TARGETS"_s, defaultTargets);
  2056. ica.Bind("DEFAULT_CONFIGURATIONS"_s, defaultConfigs);
  2057. // ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); TODO?
  2058. std::vector<std::string> unknownArgs;
  2059. ica.Parse(args, &unknownArgs);
  2060. if (!unknownArgs.empty()) {
  2061. // Unknown argument.
  2062. status.SetError(
  2063. cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
  2064. return false;
  2065. }
  2066. if (!ica.Finalize()) {
  2067. return false;
  2068. }
  2069. if (exportName.empty()) {
  2070. status.SetError(cmStrCat(args[0], " missing EXPORT."));
  2071. return false;
  2072. }
  2073. if (version.empty()) {
  2074. if (!versionCompat.empty()) {
  2075. status.SetError("COMPAT_VERSION requires VERSION.");
  2076. return false;
  2077. }
  2078. if (!versionSchema.empty()) {
  2079. status.SetError("VERSION_SCHEMA requires VERSION.");
  2080. return false;
  2081. }
  2082. } else {
  2083. if (!appendix.empty()) {
  2084. status.SetError("APPENDIX and VERSION are mutually exclusive.");
  2085. return false;
  2086. }
  2087. }
  2088. if (!appendix.empty()) {
  2089. if (!defaultTargets.empty()) {
  2090. status.SetError("APPENDIX and DEFAULT_TARGETS are mutually exclusive.");
  2091. return false;
  2092. }
  2093. if (!defaultConfigs.empty()) {
  2094. status.SetError("APPENDIX and DEFAULT_CONFIGURATIONS "
  2095. "are mutually exclusive.");
  2096. return false;
  2097. }
  2098. }
  2099. // Validate the package name.
  2100. if (!cmGeneratorExpression::IsValidTargetName(pkg) ||
  2101. pkg.find(':') != std::string::npos) {
  2102. status.SetError(
  2103. cmStrCat(args[0], " given invalid package name \"", pkg, "\"."));
  2104. return false;
  2105. }
  2106. // Construct the case-normalized package name and the file name.
  2107. std::string const pkgNameOnDisk =
  2108. (lowerCase ? cmSystemTools::LowerCase(pkg) : pkg);
  2109. std::string pkgFileName = [&]() -> std::string {
  2110. if (appendix.empty()) {
  2111. return cmStrCat(pkgNameOnDisk, ".cps");
  2112. }
  2113. return cmStrCat(pkgNameOnDisk, '-', appendix, ".cps");
  2114. }();
  2115. // Get or construct the destination path.
  2116. std::string dest = ica.GetDestination();
  2117. if (dest.empty()) {
  2118. if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") {
  2119. dest = std::string{ "cps"_s };
  2120. } else {
  2121. dest = cmStrCat(helper.GetLibraryDestination(nullptr), "/cps/",
  2122. pkgNameOnDisk);
  2123. }
  2124. }
  2125. cmExportSet& exportSet =
  2126. helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName];
  2127. cmInstallGenerator::MessageLevel message =
  2128. cmInstallGenerator::SelectMessageLevel(helper.Makefile);
  2129. // Create the export install generator.
  2130. helper.Makefile->AddInstallGenerator(
  2131. cm::make_unique<cmInstallPackageInfoExportGenerator>(
  2132. &exportSet, dest, ica.GetPermissions(), ica.GetConfigurations(),
  2133. ica.GetComponent(), message, ica.GetExcludeFromAll(),
  2134. std::move(pkgFileName), std::move(pkg), std::move(version),
  2135. std::move(versionCompat), std::move(versionSchema),
  2136. std::move(defaultTargets), std::move(defaultConfigs),
  2137. std::move(cxxModulesDirectory), helper.Makefile->GetBacktrace()));
  2138. return true;
  2139. #else
  2140. static_cast<void>(args);
  2141. status.SetError("PACKAGE_INFO not supported in bootstrap cmake");
  2142. return false;
  2143. #endif
  2144. }
  2145. bool HandleRuntimeDependencySetMode(std::vector<std::string> const& args,
  2146. cmExecutionStatus& status)
  2147. {
  2148. Helper helper(status);
  2149. auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
  2150. if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies(
  2151. system)) {
  2152. status.SetError(cmStrCat(
  2153. "RUNTIME_DEPENDENCY_SET is not supported on system \"", system, '"'));
  2154. return false;
  2155. }
  2156. // This is the RUNTIME_DEPENDENCY_SET mode.
  2157. cmInstallRuntimeDependencySet* runtimeDependencySet;
  2158. struct ArgVectors
  2159. {
  2160. ArgumentParser::MaybeEmpty<std::vector<std::string>> Library;
  2161. ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime;
  2162. ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework;
  2163. };
  2164. static auto const argHelper = cmArgumentParser<ArgVectors>{}
  2165. .Bind("LIBRARY"_s, &ArgVectors::Library)
  2166. .Bind("RUNTIME"_s, &ArgVectors::Runtime)
  2167. .Bind("FRAMEWORK"_s, &ArgVectors::Framework);
  2168. std::vector<std::string> genericArgVector;
  2169. ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
  2170. // now parse the generic args (i.e. the ones not specialized on LIBRARY,
  2171. // RUNTIME, FRAMEWORK etc. (see above)
  2172. // These generic args also contain the runtime dependency set
  2173. std::string runtimeDependencySetArg;
  2174. std::vector<std::string> runtimeDependencyArgVector;
  2175. cmInstallCommandArguments genericArgs(helper.DefaultComponentName,
  2176. *helper.Makefile);
  2177. genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg);
  2178. genericArgs.Parse(genericArgVector, &runtimeDependencyArgVector);
  2179. bool success = genericArgs.Finalize();
  2180. cmInstallCommandArguments libraryArgs(helper.DefaultComponentName,
  2181. *helper.Makefile);
  2182. cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName,
  2183. *helper.Makefile);
  2184. cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName,
  2185. *helper.Makefile);
  2186. // Now also parse the file(GET_RUNTIME_DEPENDENCY) args
  2187. std::vector<std::string> unknownArgs;
  2188. auto runtimeDependencyArgs = RuntimeDependenciesArgHelper.Parse(
  2189. runtimeDependencyArgVector, &unknownArgs);
  2190. // now parse the args for specific parts of the target (e.g. LIBRARY,
  2191. // RUNTIME, FRAMEWORK etc.
  2192. libraryArgs.Parse(argVectors.Library, &unknownArgs);
  2193. runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
  2194. frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
  2195. libraryArgs.SetGenericArguments(&genericArgs);
  2196. runtimeArgs.SetGenericArguments(&genericArgs);
  2197. frameworkArgs.SetGenericArguments(&genericArgs);
  2198. success = success && libraryArgs.Finalize();
  2199. success = success && runtimeArgs.Finalize();
  2200. success = success && frameworkArgs.Finalize();
  2201. if (!success) {
  2202. return false;
  2203. }
  2204. if (!unknownArgs.empty()) {
  2205. helper.SetError(
  2206. cmStrCat("RUNTIME_DEPENDENCY_SET given unknown argument \"",
  2207. unknownArgs.front(), "\"."));
  2208. return false;
  2209. }
  2210. if (runtimeDependencySetArg.empty()) {
  2211. helper.SetError(
  2212. "RUNTIME_DEPENDENCY_SET not given a runtime dependency set.");
  2213. return false;
  2214. }
  2215. runtimeDependencySet =
  2216. helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet(
  2217. runtimeDependencySetArg);
  2218. bool installsRuntime = false;
  2219. bool installsLibrary = false;
  2220. bool installsFramework = false;
  2221. AddInstallRuntimeDependenciesGenerator(
  2222. helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs,
  2223. std::move(runtimeDependencyArgs), installsRuntime, installsLibrary,
  2224. installsFramework);
  2225. // Tell the global generator about any installation component names
  2226. // specified
  2227. if (installsLibrary) {
  2228. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2229. libraryArgs.GetComponent());
  2230. }
  2231. if (installsRuntime) {
  2232. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2233. runtimeArgs.GetComponent());
  2234. }
  2235. if (installsFramework) {
  2236. helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
  2237. frameworkArgs.GetComponent());
  2238. }
  2239. return true;
  2240. }
  2241. bool Helper::MakeFilesFullPath(const char* modeName,
  2242. const std::vector<std::string>& relFiles,
  2243. std::vector<std::string>& absFiles)
  2244. {
  2245. return this->MakeFilesFullPath(
  2246. modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles);
  2247. }
  2248. bool Helper::MakeFilesFullPath(const char* modeName,
  2249. const std::string& basePath,
  2250. const std::vector<std::string>& relFiles,
  2251. std::vector<std::string>& absFiles)
  2252. {
  2253. for (std::string const& relFile : relFiles) {
  2254. std::string file = relFile;
  2255. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  2256. if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
  2257. file = cmStrCat(basePath, '/', relFile);
  2258. }
  2259. // Make sure the file is not a directory.
  2260. if (gpos == std::string::npos && !cmSystemTools::FileIsSymlink(file) &&
  2261. cmSystemTools::FileIsDirectory(file)) {
  2262. this->SetError(
  2263. cmStrCat(modeName, " given directory \"", relFile, "\" to install."));
  2264. return false;
  2265. }
  2266. // Store the file for installation.
  2267. absFiles.push_back(std::move(file));
  2268. }
  2269. return true;
  2270. }
  2271. bool Helper::CheckCMP0006() const
  2272. {
  2273. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
  2274. case cmPolicies::WARN:
  2275. this->Makefile->IssueMessage(
  2276. MessageType::AUTHOR_WARNING,
  2277. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006));
  2278. CM_FALLTHROUGH;
  2279. case cmPolicies::OLD:
  2280. // OLD behavior is to allow compatibility
  2281. return true;
  2282. case cmPolicies::NEW:
  2283. // NEW behavior is to disallow compatibility
  2284. break;
  2285. }
  2286. return false;
  2287. }
  2288. std::string Helper::GetDestination(const cmInstallCommandArguments* args,
  2289. const std::string& varName,
  2290. const std::string& guess) const
  2291. {
  2292. if (args && !args->GetDestination().empty()) {
  2293. return args->GetDestination();
  2294. }
  2295. std::string val = this->Makefile->GetSafeDefinition(varName);
  2296. if (!val.empty()) {
  2297. return val;
  2298. }
  2299. return guess;
  2300. }
  2301. std::string Helper::GetRuntimeDestination(
  2302. const cmInstallCommandArguments* args) const
  2303. {
  2304. return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin");
  2305. }
  2306. std::string Helper::GetSbinDestination(
  2307. const cmInstallCommandArguments* args) const
  2308. {
  2309. return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin");
  2310. }
  2311. std::string Helper::GetArchiveDestination(
  2312. const cmInstallCommandArguments* args) const
  2313. {
  2314. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  2315. }
  2316. std::string Helper::GetLibraryDestination(
  2317. const cmInstallCommandArguments* args) const
  2318. {
  2319. return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
  2320. }
  2321. std::string Helper::GetCxxModulesBmiDestination(
  2322. const cmInstallCommandArguments* args) const
  2323. {
  2324. if (args) {
  2325. return args->GetDestination();
  2326. }
  2327. return {};
  2328. }
  2329. std::string Helper::GetIncludeDestination(
  2330. const cmInstallCommandArguments* args) const
  2331. {
  2332. return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include");
  2333. }
  2334. std::string Helper::GetSysconfDestination(
  2335. const cmInstallCommandArguments* args) const
  2336. {
  2337. return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc");
  2338. }
  2339. std::string Helper::GetSharedStateDestination(
  2340. const cmInstallCommandArguments* args) const
  2341. {
  2342. return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com");
  2343. }
  2344. std::string Helper::GetLocalStateDestination(
  2345. const cmInstallCommandArguments* args) const
  2346. {
  2347. return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var");
  2348. }
  2349. std::string Helper::GetRunStateDestination(
  2350. const cmInstallCommandArguments* args) const
  2351. {
  2352. return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR",
  2353. this->GetLocalStateDestination(nullptr) +
  2354. "/run");
  2355. }
  2356. std::string Helper::GetDataRootDestination(
  2357. const cmInstallCommandArguments* args) const
  2358. {
  2359. return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share");
  2360. }
  2361. std::string Helper::GetDataDestination(
  2362. const cmInstallCommandArguments* args) const
  2363. {
  2364. return this->GetDestination(args, "CMAKE_INSTALL_DATADIR",
  2365. this->GetDataRootDestination(nullptr));
  2366. }
  2367. std::string Helper::GetInfoDestination(
  2368. const cmInstallCommandArguments* args) const
  2369. {
  2370. return this->GetDestination(args, "CMAKE_INSTALL_INFODIR",
  2371. this->GetDataRootDestination(nullptr) + "/info");
  2372. }
  2373. std::string Helper::GetLocaleDestination(
  2374. const cmInstallCommandArguments* args) const
  2375. {
  2376. return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR",
  2377. this->GetDataRootDestination(nullptr) +
  2378. "/locale");
  2379. }
  2380. std::string Helper::GetManDestination(
  2381. const cmInstallCommandArguments* args) const
  2382. {
  2383. return this->GetDestination(args, "CMAKE_INSTALL_MANDIR",
  2384. this->GetDataRootDestination(nullptr) + "/man");
  2385. }
  2386. std::string Helper::GetDocDestination(
  2387. const cmInstallCommandArguments* args) const
  2388. {
  2389. return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR",
  2390. this->GetDataRootDestination(nullptr) + "/doc");
  2391. }
  2392. std::string Helper::GetProgramExecutablesDestination(
  2393. const cmInstallCommandArguments* args) const
  2394. {
  2395. return this->GetDestination(args, "CMAKE_INSTALL_LIBEXECDIR", "libexec");
  2396. }
  2397. std::string Helper::GetDestinationForType(
  2398. const cmInstallCommandArguments* args, const std::string& type) const
  2399. {
  2400. if (args && !args->GetDestination().empty()) {
  2401. return args->GetDestination();
  2402. }
  2403. if (type == "BIN") {
  2404. return this->GetRuntimeDestination(nullptr);
  2405. }
  2406. if (type == "SBIN") {
  2407. return this->GetSbinDestination(nullptr);
  2408. }
  2409. if (type == "SYSCONF") {
  2410. return this->GetSysconfDestination(nullptr);
  2411. }
  2412. if (type == "SHAREDSTATE") {
  2413. return this->GetSharedStateDestination(nullptr);
  2414. }
  2415. if (type == "LOCALSTATE") {
  2416. return this->GetLocalStateDestination(nullptr);
  2417. }
  2418. if (type == "RUNSTATE") {
  2419. return this->GetRunStateDestination(nullptr);
  2420. }
  2421. if (type == "LIB") {
  2422. return this->GetLibraryDestination(nullptr);
  2423. }
  2424. if (type == "INCLUDE") {
  2425. return this->GetIncludeDestination(nullptr);
  2426. }
  2427. if (type == "DATA") {
  2428. return this->GetDataDestination(nullptr);
  2429. }
  2430. if (type == "INFO") {
  2431. return this->GetInfoDestination(nullptr);
  2432. }
  2433. if (type == "LOCALE") {
  2434. return this->GetLocaleDestination(nullptr);
  2435. }
  2436. if (type == "MAN") {
  2437. return this->GetManDestination(nullptr);
  2438. }
  2439. if (type == "DOC") {
  2440. return this->GetDocDestination(nullptr);
  2441. }
  2442. if (type == "LIBEXEC") {
  2443. return this->GetProgramExecutablesDestination(nullptr);
  2444. }
  2445. return "";
  2446. }
  2447. } // namespace
  2448. bool cmInstallCommand(std::vector<std::string> const& args,
  2449. cmExecutionStatus& status)
  2450. {
  2451. // Allow calling with no arguments so that arguments may be built up
  2452. // using a variable that may be left empty.
  2453. if (args.empty()) {
  2454. return true;
  2455. }
  2456. // Enable the install target.
  2457. status.GetMakefile().GetGlobalGenerator()->EnableInstallTarget();
  2458. static cmSubcommandTable const subcommand{
  2459. { "SCRIPT"_s, HandleScriptMode },
  2460. { "CODE"_s, HandleScriptMode },
  2461. { "TARGETS"_s, HandleTargetsMode },
  2462. { "IMPORTED_RUNTIME_ARTIFACTS"_s, HandleImportedRuntimeArtifactsMode },
  2463. { "FILES"_s, HandleFilesMode },
  2464. { "PROGRAMS"_s, HandleFilesMode },
  2465. { "DIRECTORY"_s, HandleDirectoryMode },
  2466. { "EXPORT"_s, HandleExportMode },
  2467. { "EXPORT_ANDROID_MK"_s, HandleExportAndroidMKMode },
  2468. { "PACKAGE_INFO"_s, HandlePackageInfoMode },
  2469. { "RUNTIME_DEPENDENCY_SET"_s, HandleRuntimeDependencySetMode },
  2470. };
  2471. return subcommand(args[0], args, status);
  2472. }