cmInstallCommand.cxx 101 KB

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