cmInstallCommand.cxx 84 KB

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