cmInstallCommand.cxx 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  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 "cmsys/Glob.hxx"
  5. #include <sstream>
  6. #include <stddef.h>
  7. #include <string.h>
  8. #include <utility>
  9. #include "cmAlgorithms.h"
  10. #include "cmCommandArgumentsHelper.h"
  11. #include "cmExportSet.h"
  12. #include "cmExportSetMap.h"
  13. #include "cmGeneratorExpression.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmInstallCommandArguments.h"
  16. #include "cmInstallDirectoryGenerator.h"
  17. #include "cmInstallExportGenerator.h"
  18. #include "cmInstallFilesGenerator.h"
  19. #include "cmInstallGenerator.h"
  20. #include "cmInstallScriptGenerator.h"
  21. #include "cmInstallTargetGenerator.h"
  22. #include "cmMakefile.h"
  23. #include "cmPolicies.h"
  24. #include "cmStateTypes.h"
  25. #include "cmSystemTools.h"
  26. #include "cmTarget.h"
  27. #include "cmTargetExport.h"
  28. #include "cmake.h"
  29. class cmExecutionStatus;
  30. static cmInstallTargetGenerator* CreateInstallTargetGenerator(
  31. cmTarget& target, const cmInstallCommandArguments& args, bool impLib,
  32. bool forceOpt = false, bool namelink = false)
  33. {
  34. cmInstallGenerator::MessageLevel message =
  35. cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
  36. target.SetHaveInstallRule(true);
  37. const char* component = namelink ? args.GetNamelinkComponent().c_str()
  38. : args.GetComponent().c_str();
  39. return new cmInstallTargetGenerator(
  40. target.GetName(), args.GetDestination().c_str(), impLib,
  41. args.GetPermissions().c_str(), args.GetConfigurations(), component,
  42. message, args.GetExcludeFromAll(), args.GetOptional() || forceOpt);
  43. }
  44. static cmInstallFilesGenerator* CreateInstallFilesGenerator(
  45. cmMakefile* mf, const std::vector<std::string>& absFiles,
  46. const cmInstallCommandArguments& args, bool programs)
  47. {
  48. cmInstallGenerator::MessageLevel message =
  49. cmInstallGenerator::SelectMessageLevel(mf);
  50. return new cmInstallFilesGenerator(
  51. absFiles, args.GetDestination().c_str(), programs,
  52. args.GetPermissions().c_str(), args.GetConfigurations(),
  53. args.GetComponent().c_str(), message, args.GetExcludeFromAll(),
  54. args.GetRename().c_str(), args.GetOptional());
  55. }
  56. // cmInstallCommand
  57. bool cmInstallCommand::InitialPass(std::vector<std::string> const& args,
  58. cmExecutionStatus&)
  59. {
  60. // Allow calling with no arguments so that arguments may be built up
  61. // using a variable that may be left empty.
  62. if (args.empty()) {
  63. return true;
  64. }
  65. // Enable the install target.
  66. this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
  67. this->DefaultComponentName =
  68. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
  69. if (this->DefaultComponentName.empty()) {
  70. this->DefaultComponentName = "Unspecified";
  71. }
  72. std::string const& mode = args[0];
  73. // Switch among the command modes.
  74. if (mode == "SCRIPT") {
  75. return this->HandleScriptMode(args);
  76. }
  77. if (mode == "CODE") {
  78. return this->HandleScriptMode(args);
  79. }
  80. if (mode == "TARGETS") {
  81. return this->HandleTargetsMode(args);
  82. }
  83. if (mode == "FILES") {
  84. return this->HandleFilesMode(args);
  85. }
  86. if (mode == "PROGRAMS") {
  87. return this->HandleFilesMode(args);
  88. }
  89. if (mode == "DIRECTORY") {
  90. return this->HandleDirectoryMode(args);
  91. }
  92. if (mode == "EXPORT") {
  93. return this->HandleExportMode(args);
  94. }
  95. if (mode == "EXPORT_ANDROID_MK") {
  96. return this->HandleExportAndroidMKMode(args);
  97. }
  98. // Unknown mode.
  99. std::string e = "called with unknown mode ";
  100. e += args[0];
  101. this->SetError(e);
  102. return false;
  103. }
  104. bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
  105. {
  106. std::string component = this->DefaultComponentName;
  107. int componentCount = 0;
  108. bool doing_script = false;
  109. bool doing_code = false;
  110. bool exclude_from_all = false;
  111. // Scan the args once for COMPONENT. Only allow one.
  112. //
  113. for (size_t i = 0; i < args.size(); ++i) {
  114. if (args[i] == "COMPONENT" && i + 1 < args.size()) {
  115. ++componentCount;
  116. ++i;
  117. component = args[i];
  118. }
  119. if (args[i] == "EXCLUDE_FROM_ALL") {
  120. exclude_from_all = true;
  121. }
  122. }
  123. if (componentCount > 1) {
  124. this->SetError("given more than one COMPONENT for the SCRIPT or CODE "
  125. "signature of the INSTALL command. "
  126. "Use multiple INSTALL commands with one COMPONENT each.");
  127. return false;
  128. }
  129. // Scan the args again, this time adding install generators each time we
  130. // encounter a SCRIPT or CODE arg:
  131. //
  132. for (std::string const& arg : args) {
  133. if (arg == "SCRIPT") {
  134. doing_script = true;
  135. doing_code = false;
  136. } else if (arg == "CODE") {
  137. doing_script = false;
  138. doing_code = true;
  139. } else if (arg == "COMPONENT") {
  140. doing_script = false;
  141. doing_code = false;
  142. } else if (doing_script) {
  143. doing_script = false;
  144. std::string script = arg;
  145. if (!cmSystemTools::FileIsFullPath(script)) {
  146. script = this->Makefile->GetCurrentSourceDirectory();
  147. script += "/";
  148. script += arg;
  149. }
  150. if (cmSystemTools::FileIsDirectory(script)) {
  151. this->SetError("given a directory as value of SCRIPT argument.");
  152. return false;
  153. }
  154. this->Makefile->AddInstallGenerator(new cmInstallScriptGenerator(
  155. script.c_str(), false, component.c_str(), exclude_from_all));
  156. } else if (doing_code) {
  157. doing_code = false;
  158. std::string const& code = arg;
  159. this->Makefile->AddInstallGenerator(new cmInstallScriptGenerator(
  160. code.c_str(), true, component.c_str(), exclude_from_all));
  161. }
  162. }
  163. if (doing_script) {
  164. this->SetError("given no value for SCRIPT argument.");
  165. return false;
  166. }
  167. if (doing_code) {
  168. this->SetError("given no value for CODE argument.");
  169. return false;
  170. }
  171. // Tell the global generator about any installation component names
  172. // specified.
  173. this->Makefile->GetGlobalGenerator()->AddInstallComponent(component.c_str());
  174. return true;
  175. }
  176. /*struct InstallPart
  177. {
  178. InstallPart(cmCommandArgumentsHelper* helper, const char* key,
  179. cmCommandArgumentGroup* group);
  180. cmCAStringVector argVector;
  181. cmInstallCommandArguments args;
  182. };*/
  183. bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
  184. {
  185. // This is the TARGETS mode.
  186. std::vector<cmTarget*> targets;
  187. cmCommandArgumentsHelper argHelper;
  188. cmCommandArgumentGroup group;
  189. cmCAStringVector genericArgVector(&argHelper, nullptr);
  190. cmCAStringVector archiveArgVector(&argHelper, "ARCHIVE", &group);
  191. cmCAStringVector libraryArgVector(&argHelper, "LIBRARY", &group);
  192. cmCAStringVector runtimeArgVector(&argHelper, "RUNTIME", &group);
  193. cmCAStringVector objectArgVector(&argHelper, "OBJECTS", &group);
  194. cmCAStringVector frameworkArgVector(&argHelper, "FRAMEWORK", &group);
  195. cmCAStringVector bundleArgVector(&argHelper, "BUNDLE", &group);
  196. cmCAStringVector includesArgVector(&argHelper, "INCLUDES", &group);
  197. cmCAStringVector privateHeaderArgVector(&argHelper, "PRIVATE_HEADER",
  198. &group);
  199. cmCAStringVector publicHeaderArgVector(&argHelper, "PUBLIC_HEADER", &group);
  200. cmCAStringVector resourceArgVector(&argHelper, "RESOURCE", &group);
  201. genericArgVector.Follows(nullptr);
  202. group.Follows(&genericArgVector);
  203. argHelper.Parse(&args, nullptr);
  204. // now parse the generic args (i.e. the ones not specialized on LIBRARY/
  205. // ARCHIVE, RUNTIME etc. (see above)
  206. // These generic args also contain the targets and the export stuff
  207. std::vector<std::string> unknownArgs;
  208. cmInstallCommandArguments genericArgs(this->DefaultComponentName);
  209. cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
  210. cmCAString exports(&genericArgs.Parser, "EXPORT",
  211. &genericArgs.ArgumentGroup);
  212. targetList.Follows(nullptr);
  213. genericArgs.ArgumentGroup.Follows(&targetList);
  214. genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
  215. bool success = genericArgs.Finalize();
  216. cmInstallCommandArguments archiveArgs(this->DefaultComponentName);
  217. cmInstallCommandArguments libraryArgs(this->DefaultComponentName);
  218. cmInstallCommandArguments runtimeArgs(this->DefaultComponentName);
  219. cmInstallCommandArguments objectArgs(this->DefaultComponentName);
  220. cmInstallCommandArguments frameworkArgs(this->DefaultComponentName);
  221. cmInstallCommandArguments bundleArgs(this->DefaultComponentName);
  222. cmInstallCommandArguments privateHeaderArgs(this->DefaultComponentName);
  223. cmInstallCommandArguments publicHeaderArgs(this->DefaultComponentName);
  224. cmInstallCommandArguments resourceArgs(this->DefaultComponentName);
  225. cmInstallCommandIncludesArgument includesArgs;
  226. // now parse the args for specific parts of the target (e.g. LIBRARY,
  227. // RUNTIME, ARCHIVE etc.
  228. archiveArgs.Parse(&archiveArgVector.GetVector(), &unknownArgs);
  229. libraryArgs.Parse(&libraryArgVector.GetVector(), &unknownArgs);
  230. runtimeArgs.Parse(&runtimeArgVector.GetVector(), &unknownArgs);
  231. objectArgs.Parse(&objectArgVector.GetVector(), &unknownArgs);
  232. frameworkArgs.Parse(&frameworkArgVector.GetVector(), &unknownArgs);
  233. bundleArgs.Parse(&bundleArgVector.GetVector(), &unknownArgs);
  234. privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
  235. publicHeaderArgs.Parse(&publicHeaderArgVector.GetVector(), &unknownArgs);
  236. resourceArgs.Parse(&resourceArgVector.GetVector(), &unknownArgs);
  237. includesArgs.Parse(&includesArgVector.GetVector(), &unknownArgs);
  238. if (!unknownArgs.empty()) {
  239. // Unknown argument.
  240. std::ostringstream e;
  241. e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
  242. this->SetError(e.str());
  243. return false;
  244. }
  245. // apply generic args
  246. archiveArgs.SetGenericArguments(&genericArgs);
  247. libraryArgs.SetGenericArguments(&genericArgs);
  248. runtimeArgs.SetGenericArguments(&genericArgs);
  249. objectArgs.SetGenericArguments(&genericArgs);
  250. frameworkArgs.SetGenericArguments(&genericArgs);
  251. bundleArgs.SetGenericArguments(&genericArgs);
  252. privateHeaderArgs.SetGenericArguments(&genericArgs);
  253. publicHeaderArgs.SetGenericArguments(&genericArgs);
  254. resourceArgs.SetGenericArguments(&genericArgs);
  255. success = success && archiveArgs.Finalize();
  256. success = success && libraryArgs.Finalize();
  257. success = success && runtimeArgs.Finalize();
  258. success = success && objectArgs.Finalize();
  259. success = success && frameworkArgs.Finalize();
  260. success = success && bundleArgs.Finalize();
  261. success = success && privateHeaderArgs.Finalize();
  262. success = success && publicHeaderArgs.Finalize();
  263. success = success && resourceArgs.Finalize();
  264. if (!success) {
  265. return false;
  266. }
  267. // Enforce argument rules too complex to specify for the
  268. // general-purpose parser.
  269. if (archiveArgs.GetNamelinkOnly() || runtimeArgs.GetNamelinkOnly() ||
  270. objectArgs.GetNamelinkOnly() || frameworkArgs.GetNamelinkOnly() ||
  271. bundleArgs.GetNamelinkOnly() || privateHeaderArgs.GetNamelinkOnly() ||
  272. publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly()) {
  273. this->SetError(
  274. "TARGETS given NAMELINK_ONLY option not in LIBRARY group. "
  275. "The NAMELINK_ONLY option may be specified only following LIBRARY.");
  276. return false;
  277. }
  278. if (archiveArgs.GetNamelinkSkip() || runtimeArgs.GetNamelinkSkip() ||
  279. objectArgs.GetNamelinkSkip() || frameworkArgs.GetNamelinkSkip() ||
  280. bundleArgs.GetNamelinkSkip() || privateHeaderArgs.GetNamelinkSkip() ||
  281. publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip()) {
  282. this->SetError(
  283. "TARGETS given NAMELINK_SKIP option not in LIBRARY group. "
  284. "The NAMELINK_SKIP option may be specified only following LIBRARY.");
  285. return false;
  286. }
  287. if (archiveArgs.HasNamelinkComponent() ||
  288. runtimeArgs.HasNamelinkComponent() ||
  289. objectArgs.HasNamelinkComponent() ||
  290. frameworkArgs.HasNamelinkComponent() ||
  291. bundleArgs.HasNamelinkComponent() ||
  292. privateHeaderArgs.HasNamelinkComponent() ||
  293. publicHeaderArgs.HasNamelinkComponent() ||
  294. resourceArgs.HasNamelinkComponent()) {
  295. this->SetError(
  296. "TARGETS given NAMELINK_COMPONENT option not in LIBRARY group. "
  297. "The NAMELINK_COMPONENT option may be specified only following "
  298. "LIBRARY.");
  299. return false;
  300. }
  301. if (libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip()) {
  302. this->SetError("TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. "
  303. "At most one of these two options may be specified.");
  304. return false;
  305. }
  306. // Select the mode for installing symlinks to versioned shared libraries.
  307. cmInstallTargetGenerator::NamelinkModeType namelinkMode =
  308. cmInstallTargetGenerator::NamelinkModeNone;
  309. if (libraryArgs.GetNamelinkOnly()) {
  310. namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
  311. } else if (libraryArgs.GetNamelinkSkip()) {
  312. namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
  313. }
  314. // Check if there is something to do.
  315. if (targetList.GetVector().empty()) {
  316. return true;
  317. }
  318. // Check whether this is a DLL platform.
  319. bool dll_platform =
  320. strcmp(this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"),
  321. "") != 0;
  322. for (std::string const& tgt : targetList.GetVector()) {
  323. if (this->Makefile->IsAlias(tgt)) {
  324. std::ostringstream e;
  325. e << "TARGETS given target \"" << tgt << "\" which is an alias.";
  326. this->SetError(e.str());
  327. return false;
  328. }
  329. // Lookup this target in the current directory.
  330. cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt);
  331. if (!target) {
  332. // If no local target has been found, find it in the global scope.
  333. target = this->Makefile->GetGlobalGenerator()->FindTarget(tgt, true);
  334. }
  335. if (target) {
  336. // Found the target. Check its type.
  337. if (target->GetType() != cmStateEnums::EXECUTABLE &&
  338. target->GetType() != cmStateEnums::STATIC_LIBRARY &&
  339. target->GetType() != cmStateEnums::SHARED_LIBRARY &&
  340. target->GetType() != cmStateEnums::MODULE_LIBRARY &&
  341. target->GetType() != cmStateEnums::OBJECT_LIBRARY &&
  342. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  343. std::ostringstream e;
  344. e << "TARGETS given target \"" << tgt
  345. << "\" which is not an executable, library, or module.";
  346. this->SetError(e.str());
  347. return false;
  348. }
  349. // Store the target in the list to be installed.
  350. targets.push_back(target);
  351. } else {
  352. // Did not find the target.
  353. std::ostringstream e;
  354. e << "TARGETS given target \"" << tgt << "\" which does not exist.";
  355. this->SetError(e.str());
  356. return false;
  357. }
  358. }
  359. // Keep track of whether we will be performing an installation of
  360. // any files of the given type.
  361. bool installsArchive = false;
  362. bool installsLibrary = false;
  363. bool installsNamelink = false;
  364. bool installsRuntime = false;
  365. bool installsObject = false;
  366. bool installsFramework = false;
  367. bool installsBundle = false;
  368. bool installsPrivateHeader = false;
  369. bool installsPublicHeader = false;
  370. bool installsResource = false;
  371. // Generate install script code to install the given targets.
  372. for (cmTarget* ti : targets) {
  373. // Handle each target type.
  374. cmTarget& target = *ti;
  375. cmInstallTargetGenerator* archiveGenerator = nullptr;
  376. cmInstallTargetGenerator* libraryGenerator = nullptr;
  377. cmInstallTargetGenerator* namelinkGenerator = nullptr;
  378. cmInstallTargetGenerator* runtimeGenerator = nullptr;
  379. cmInstallTargetGenerator* objectGenerator = nullptr;
  380. cmInstallTargetGenerator* frameworkGenerator = nullptr;
  381. cmInstallTargetGenerator* bundleGenerator = nullptr;
  382. cmInstallFilesGenerator* privateHeaderGenerator = nullptr;
  383. cmInstallFilesGenerator* publicHeaderGenerator = nullptr;
  384. cmInstallFilesGenerator* resourceGenerator = nullptr;
  385. // Track whether this is a namelink-only rule.
  386. bool namelinkOnly = false;
  387. switch (target.GetType()) {
  388. case cmStateEnums::SHARED_LIBRARY: {
  389. // Shared libraries are handled differently on DLL and non-DLL
  390. // platforms. All windows platforms are DLL platforms including
  391. // cygwin. Currently no other platform is a DLL platform.
  392. if (dll_platform) {
  393. // When in namelink only mode skip all libraries on Windows.
  394. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  395. continue;
  396. }
  397. // This is a DLL platform.
  398. if (!archiveArgs.GetDestination().empty()) {
  399. // The import library uses the ARCHIVE properties.
  400. archiveGenerator =
  401. CreateInstallTargetGenerator(target, archiveArgs, true);
  402. }
  403. if (!runtimeArgs.GetDestination().empty()) {
  404. // The DLL uses the RUNTIME properties.
  405. runtimeGenerator =
  406. CreateInstallTargetGenerator(target, runtimeArgs, false);
  407. }
  408. if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) {
  409. this->SetError("Library TARGETS given no DESTINATION!");
  410. return false;
  411. }
  412. } else {
  413. // This is a non-DLL platform.
  414. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  415. // INSTALL properties. Otherwise, use the LIBRARY properties.
  416. if (target.IsFrameworkOnApple()) {
  417. // When in namelink only mode skip frameworks.
  418. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  419. continue;
  420. }
  421. // Use the FRAMEWORK properties.
  422. if (!frameworkArgs.GetDestination().empty()) {
  423. frameworkGenerator =
  424. CreateInstallTargetGenerator(target, frameworkArgs, false);
  425. } else {
  426. std::ostringstream e;
  427. e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
  428. "FRAMEWORK target \""
  429. << target.GetName() << "\".";
  430. this->SetError(e.str());
  431. return false;
  432. }
  433. } else {
  434. // The shared library uses the LIBRARY properties.
  435. if (!libraryArgs.GetDestination().empty()) {
  436. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
  437. libraryGenerator =
  438. CreateInstallTargetGenerator(target, libraryArgs, false);
  439. libraryGenerator->SetNamelinkMode(
  440. cmInstallTargetGenerator::NamelinkModeSkip);
  441. }
  442. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) {
  443. namelinkGenerator = CreateInstallTargetGenerator(
  444. target, libraryArgs, false, false, true);
  445. namelinkGenerator->SetNamelinkMode(
  446. cmInstallTargetGenerator::NamelinkModeOnly);
  447. }
  448. namelinkOnly =
  449. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  450. } else {
  451. std::ostringstream e;
  452. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  453. "target \""
  454. << target.GetName() << "\".";
  455. this->SetError(e.str());
  456. return false;
  457. }
  458. }
  459. }
  460. } break;
  461. case cmStateEnums::STATIC_LIBRARY: {
  462. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  463. // INSTALL properties. Otherwise, use the LIBRARY properties.
  464. if (target.IsFrameworkOnApple()) {
  465. // When in namelink only mode skip frameworks.
  466. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  467. continue;
  468. }
  469. // Use the FRAMEWORK properties.
  470. if (!frameworkArgs.GetDestination().empty()) {
  471. frameworkGenerator =
  472. CreateInstallTargetGenerator(target, frameworkArgs, false);
  473. } else {
  474. std::ostringstream e;
  475. e << "TARGETS given no FRAMEWORK DESTINATION for static library "
  476. "FRAMEWORK target \""
  477. << target.GetName() << "\".";
  478. this->SetError(e.str());
  479. return false;
  480. }
  481. } else {
  482. // Static libraries use ARCHIVE properties.
  483. if (!archiveArgs.GetDestination().empty()) {
  484. archiveGenerator =
  485. CreateInstallTargetGenerator(target, archiveArgs, false);
  486. } else {
  487. std::ostringstream e;
  488. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  489. "target \""
  490. << target.GetName() << "\".";
  491. this->SetError(e.str());
  492. return false;
  493. }
  494. }
  495. } break;
  496. case cmStateEnums::MODULE_LIBRARY: {
  497. // Modules use LIBRARY properties.
  498. if (!libraryArgs.GetDestination().empty()) {
  499. libraryGenerator =
  500. CreateInstallTargetGenerator(target, libraryArgs, false);
  501. libraryGenerator->SetNamelinkMode(namelinkMode);
  502. namelinkOnly =
  503. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  504. } else {
  505. std::ostringstream e;
  506. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  507. << target.GetName() << "\".";
  508. this->SetError(e.str());
  509. return false;
  510. }
  511. } break;
  512. case cmStateEnums::OBJECT_LIBRARY: {
  513. // Objects use OBJECT properties.
  514. if (!objectArgs.GetDestination().empty()) {
  515. // Verify that we know where the objects are to install them.
  516. std::string reason;
  517. if (!this->Makefile->GetGlobalGenerator()
  518. ->HasKnownObjectFileLocation(&reason)) {
  519. std::ostringstream e;
  520. e << "TARGETS given OBJECT library \"" << target.GetName()
  521. << "\" whose objects may not be installed" << reason << ".";
  522. this->SetError(e.str());
  523. return false;
  524. }
  525. objectGenerator =
  526. CreateInstallTargetGenerator(target, objectArgs, false);
  527. } else {
  528. // Installing an OBJECT library without a destination transforms
  529. // it to an INTERFACE library. It installs no files but can be
  530. // exported.
  531. }
  532. } break;
  533. case cmStateEnums::EXECUTABLE: {
  534. if (target.IsAppBundleOnApple()) {
  535. // Application bundles use the BUNDLE properties.
  536. if (!bundleArgs.GetDestination().empty()) {
  537. bundleGenerator =
  538. CreateInstallTargetGenerator(target, bundleArgs, false);
  539. } else if (!runtimeArgs.GetDestination().empty()) {
  540. bool failure = false;
  541. if (this->CheckCMP0006(failure)) {
  542. // For CMake 2.4 compatibility fallback to the RUNTIME
  543. // properties.
  544. bundleGenerator =
  545. CreateInstallTargetGenerator(target, runtimeArgs, false);
  546. } else if (failure) {
  547. return false;
  548. }
  549. }
  550. if (!bundleGenerator) {
  551. std::ostringstream e;
  552. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  553. "executable target \""
  554. << target.GetName() << "\".";
  555. this->SetError(e.str());
  556. return false;
  557. }
  558. } else {
  559. // Executables use the RUNTIME properties.
  560. if (!runtimeArgs.GetDestination().empty()) {
  561. runtimeGenerator =
  562. CreateInstallTargetGenerator(target, runtimeArgs, false);
  563. } else {
  564. std::ostringstream e;
  565. e << "TARGETS given no RUNTIME DESTINATION for executable "
  566. "target \""
  567. << target.GetName() << "\".";
  568. this->SetError(e.str());
  569. return false;
  570. }
  571. }
  572. // On DLL platforms an executable may also have an import
  573. // library. Install it to the archive destination if it
  574. // exists.
  575. if (dll_platform && !archiveArgs.GetDestination().empty() &&
  576. target.IsExecutableWithExports()) {
  577. // The import library uses the ARCHIVE properties.
  578. archiveGenerator =
  579. CreateInstallTargetGenerator(target, archiveArgs, true, true);
  580. }
  581. } break;
  582. case cmStateEnums::INTERFACE_LIBRARY:
  583. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  584. // only effect of that is to make it exportable. It installs no
  585. // other files itself.
  586. break;
  587. default:
  588. // This should never happen due to the above type check.
  589. // Ignore the case.
  590. break;
  591. }
  592. // These well-known sets of files are installed *automatically* for
  593. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  594. // FRAMEWORK. For other target types or on other platforms, they are not
  595. // installed automatically and so we need to create install files
  596. // generators for them.
  597. bool createInstallGeneratorsForTargetFileSets = true;
  598. if (target.IsFrameworkOnApple() ||
  599. target.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  600. createInstallGeneratorsForTargetFileSets = false;
  601. }
  602. if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) {
  603. const char* files = target.GetProperty("PRIVATE_HEADER");
  604. if ((files) && (*files)) {
  605. std::vector<std::string> relFiles;
  606. cmSystemTools::ExpandListArgument(files, relFiles);
  607. std::vector<std::string> absFiles;
  608. if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) {
  609. return false;
  610. }
  611. // Create the files install generator.
  612. if (!privateHeaderArgs.GetDestination().empty()) {
  613. privateHeaderGenerator = CreateInstallFilesGenerator(
  614. this->Makefile, absFiles, privateHeaderArgs, false);
  615. } else {
  616. std::ostringstream e;
  617. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  618. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  619. cmSystemTools::Message(e.str().c_str(), "Warning");
  620. }
  621. }
  622. files = target.GetProperty("PUBLIC_HEADER");
  623. if ((files) && (*files)) {
  624. std::vector<std::string> relFiles;
  625. cmSystemTools::ExpandListArgument(files, relFiles);
  626. std::vector<std::string> absFiles;
  627. if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) {
  628. return false;
  629. }
  630. // Create the files install generator.
  631. if (!publicHeaderArgs.GetDestination().empty()) {
  632. publicHeaderGenerator = CreateInstallFilesGenerator(
  633. this->Makefile, absFiles, publicHeaderArgs, false);
  634. } else {
  635. std::ostringstream e;
  636. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  637. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  638. cmSystemTools::Message(e.str().c_str(), "Warning");
  639. }
  640. }
  641. files = target.GetProperty("RESOURCE");
  642. if ((files) && (*files)) {
  643. std::vector<std::string> relFiles;
  644. cmSystemTools::ExpandListArgument(files, relFiles);
  645. std::vector<std::string> absFiles;
  646. if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles)) {
  647. return false;
  648. }
  649. // Create the files install generator.
  650. if (!resourceArgs.GetDestination().empty()) {
  651. resourceGenerator = CreateInstallFilesGenerator(
  652. this->Makefile, absFiles, resourceArgs, false);
  653. } else {
  654. std::ostringstream e;
  655. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  656. << "RESOURCE files but no RESOURCE DESTINATION.";
  657. cmSystemTools::Message(e.str().c_str(), "Warning");
  658. }
  659. }
  660. }
  661. // Keep track of whether we're installing anything in each category
  662. installsArchive = installsArchive || archiveGenerator != nullptr;
  663. installsLibrary = installsLibrary || libraryGenerator != nullptr;
  664. installsNamelink = installsNamelink || namelinkGenerator != nullptr;
  665. installsRuntime = installsRuntime || runtimeGenerator != nullptr;
  666. installsObject = installsObject || objectGenerator != nullptr;
  667. installsFramework = installsFramework || frameworkGenerator != nullptr;
  668. installsBundle = installsBundle || bundleGenerator != nullptr;
  669. installsPrivateHeader =
  670. installsPrivateHeader || privateHeaderGenerator != nullptr;
  671. installsPublicHeader =
  672. installsPublicHeader || publicHeaderGenerator != nullptr;
  673. installsResource = installsResource || resourceGenerator;
  674. this->Makefile->AddInstallGenerator(archiveGenerator);
  675. this->Makefile->AddInstallGenerator(libraryGenerator);
  676. this->Makefile->AddInstallGenerator(namelinkGenerator);
  677. this->Makefile->AddInstallGenerator(runtimeGenerator);
  678. this->Makefile->AddInstallGenerator(objectGenerator);
  679. this->Makefile->AddInstallGenerator(frameworkGenerator);
  680. this->Makefile->AddInstallGenerator(bundleGenerator);
  681. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  682. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  683. this->Makefile->AddInstallGenerator(resourceGenerator);
  684. // Add this install rule to an export if one was specified and
  685. // this is not a namelink-only rule.
  686. if (!exports.GetString().empty() && !namelinkOnly) {
  687. cmTargetExport* te = new cmTargetExport;
  688. te->TargetName = target.GetName();
  689. te->ArchiveGenerator = archiveGenerator;
  690. te->BundleGenerator = bundleGenerator;
  691. te->FrameworkGenerator = frameworkGenerator;
  692. te->HeaderGenerator = publicHeaderGenerator;
  693. te->LibraryGenerator = libraryGenerator;
  694. te->RuntimeGenerator = runtimeGenerator;
  695. te->ObjectsGenerator = objectGenerator;
  696. this->Makefile->GetGlobalGenerator()
  697. ->GetExportSets()[exports.GetString()]
  698. ->AddTargetExport(te);
  699. te->InterfaceIncludeDirectories =
  700. cmJoin(includesArgs.GetIncludeDirs(), ";");
  701. }
  702. }
  703. // Tell the global generator about any installation component names
  704. // specified
  705. if (installsArchive) {
  706. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  707. archiveArgs.GetComponent().c_str());
  708. }
  709. if (installsLibrary) {
  710. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  711. libraryArgs.GetComponent().c_str());
  712. }
  713. if (installsNamelink) {
  714. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  715. libraryArgs.GetNamelinkComponent().c_str());
  716. }
  717. if (installsRuntime) {
  718. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  719. runtimeArgs.GetComponent().c_str());
  720. }
  721. if (installsObject) {
  722. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  723. objectArgs.GetComponent().c_str());
  724. }
  725. if (installsFramework) {
  726. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  727. frameworkArgs.GetComponent().c_str());
  728. }
  729. if (installsBundle) {
  730. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  731. bundleArgs.GetComponent().c_str());
  732. }
  733. if (installsPrivateHeader) {
  734. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  735. privateHeaderArgs.GetComponent().c_str());
  736. }
  737. if (installsPublicHeader) {
  738. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  739. publicHeaderArgs.GetComponent().c_str());
  740. }
  741. if (installsResource) {
  742. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  743. resourceArgs.GetComponent().c_str());
  744. }
  745. return true;
  746. }
  747. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  748. {
  749. // This is the FILES mode.
  750. bool programs = (args[0] == "PROGRAMS");
  751. cmInstallCommandArguments ica(this->DefaultComponentName);
  752. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  753. files.Follows(nullptr);
  754. ica.ArgumentGroup.Follows(&files);
  755. std::vector<std::string> unknownArgs;
  756. ica.Parse(&args, &unknownArgs);
  757. if (!unknownArgs.empty()) {
  758. // Unknown argument.
  759. std::ostringstream e;
  760. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  761. this->SetError(e.str());
  762. return false;
  763. }
  764. const std::vector<std::string>& filesVector = files.GetVector();
  765. // Check if there is something to do.
  766. if (filesVector.empty()) {
  767. return true;
  768. }
  769. if (!ica.GetRename().empty() && filesVector.size() > 1) {
  770. // The rename option works only with one file.
  771. std::ostringstream e;
  772. e << args[0] << " given RENAME option with more than one file.";
  773. this->SetError(e.str());
  774. return false;
  775. }
  776. std::vector<std::string> absFiles;
  777. if (!this->MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) {
  778. return false;
  779. }
  780. cmPolicies::PolicyStatus status =
  781. this->Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  782. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  783. for (std::string const& file : filesVector) {
  784. if (gg->IsExportedTargetsFile(file)) {
  785. const char* modal = nullptr;
  786. std::ostringstream e;
  787. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  788. switch (status) {
  789. case cmPolicies::WARN:
  790. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  791. modal = "should";
  792. case cmPolicies::OLD:
  793. break;
  794. case cmPolicies::REQUIRED_IF_USED:
  795. case cmPolicies::REQUIRED_ALWAYS:
  796. case cmPolicies::NEW:
  797. modal = "may";
  798. messageType = cmake::FATAL_ERROR;
  799. }
  800. if (modal) {
  801. e << "The file\n " << file
  802. << "\nwas generated by the export() "
  803. "command. It "
  804. << modal
  805. << " not be installed with the "
  806. "install() command. Use the install(EXPORT) mechanism "
  807. "instead. See the cmake-packages(7) manual for more.\n";
  808. this->Makefile->IssueMessage(messageType, e.str());
  809. if (messageType == cmake::FATAL_ERROR) {
  810. return false;
  811. }
  812. }
  813. }
  814. }
  815. if (!ica.Finalize()) {
  816. return false;
  817. }
  818. if (ica.GetDestination().empty()) {
  819. // A destination is required.
  820. std::ostringstream e;
  821. e << args[0] << " given no DESTINATION!";
  822. this->SetError(e.str());
  823. return false;
  824. }
  825. // Create the files install generator.
  826. this->Makefile->AddInstallGenerator(
  827. CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
  828. // Tell the global generator about any installation component names
  829. // specified.
  830. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  831. ica.GetComponent().c_str());
  832. return true;
  833. }
  834. bool cmInstallCommand::HandleDirectoryMode(
  835. std::vector<std::string> const& args)
  836. {
  837. enum Doing
  838. {
  839. DoingNone,
  840. DoingDirs,
  841. DoingDestination,
  842. DoingPattern,
  843. DoingRegex,
  844. DoingPermsFile,
  845. DoingPermsDir,
  846. DoingPermsMatch,
  847. DoingConfigurations,
  848. DoingComponent
  849. };
  850. Doing doing = DoingDirs;
  851. bool in_match_mode = false;
  852. bool optional = false;
  853. bool exclude_from_all = false;
  854. bool message_never = false;
  855. std::vector<std::string> dirs;
  856. const char* destination = nullptr;
  857. std::string permissions_file;
  858. std::string permissions_dir;
  859. std::vector<std::string> configurations;
  860. std::string component = this->DefaultComponentName;
  861. std::string literal_args;
  862. for (unsigned int i = 1; i < args.size(); ++i) {
  863. if (args[i] == "DESTINATION") {
  864. if (in_match_mode) {
  865. std::ostringstream e;
  866. e << args[0] << " does not allow \"" << args[i]
  867. << "\" after PATTERN or REGEX.";
  868. this->SetError(e.str());
  869. return false;
  870. }
  871. // Switch to setting the destination property.
  872. doing = DoingDestination;
  873. } else if (args[i] == "OPTIONAL") {
  874. if (in_match_mode) {
  875. std::ostringstream e;
  876. e << args[0] << " does not allow \"" << args[i]
  877. << "\" after PATTERN or REGEX.";
  878. this->SetError(e.str());
  879. return false;
  880. }
  881. // Mark the rule as optional.
  882. optional = true;
  883. doing = DoingNone;
  884. } else if (args[i] == "MESSAGE_NEVER") {
  885. if (in_match_mode) {
  886. std::ostringstream e;
  887. e << args[0] << " does not allow \"" << args[i]
  888. << "\" after PATTERN or REGEX.";
  889. this->SetError(e.str());
  890. return false;
  891. }
  892. // Mark the rule as quiet.
  893. message_never = true;
  894. doing = DoingNone;
  895. } else if (args[i] == "PATTERN") {
  896. // Switch to a new pattern match rule.
  897. doing = DoingPattern;
  898. in_match_mode = true;
  899. } else if (args[i] == "REGEX") {
  900. // Switch to a new regex match rule.
  901. doing = DoingRegex;
  902. in_match_mode = true;
  903. } else if (args[i] == "EXCLUDE") {
  904. // Add this property to the current match rule.
  905. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
  906. std::ostringstream e;
  907. e << args[0] << " does not allow \"" << args[i]
  908. << "\" before a PATTERN or REGEX is given.";
  909. this->SetError(e.str());
  910. return false;
  911. }
  912. literal_args += " EXCLUDE";
  913. doing = DoingNone;
  914. } else if (args[i] == "PERMISSIONS") {
  915. if (!in_match_mode) {
  916. std::ostringstream e;
  917. e << args[0] << " does not allow \"" << args[i]
  918. << "\" before a PATTERN or REGEX is given.";
  919. this->SetError(e.str());
  920. return false;
  921. }
  922. // Switch to setting the current match permissions property.
  923. literal_args += " PERMISSIONS";
  924. doing = DoingPermsMatch;
  925. } else if (args[i] == "FILE_PERMISSIONS") {
  926. if (in_match_mode) {
  927. std::ostringstream e;
  928. e << args[0] << " does not allow \"" << args[i]
  929. << "\" after PATTERN or REGEX.";
  930. this->SetError(e.str());
  931. return false;
  932. }
  933. // Switch to setting the file permissions property.
  934. doing = DoingPermsFile;
  935. } else if (args[i] == "DIRECTORY_PERMISSIONS") {
  936. if (in_match_mode) {
  937. std::ostringstream e;
  938. e << args[0] << " does not allow \"" << args[i]
  939. << "\" after PATTERN or REGEX.";
  940. this->SetError(e.str());
  941. return false;
  942. }
  943. // Switch to setting the directory permissions property.
  944. doing = DoingPermsDir;
  945. } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
  946. if (in_match_mode) {
  947. std::ostringstream e;
  948. e << args[0] << " does not allow \"" << args[i]
  949. << "\" after PATTERN or REGEX.";
  950. this->SetError(e.str());
  951. return false;
  952. }
  953. // Add this option literally.
  954. literal_args += " USE_SOURCE_PERMISSIONS";
  955. doing = DoingNone;
  956. } else if (args[i] == "FILES_MATCHING") {
  957. if (in_match_mode) {
  958. std::ostringstream e;
  959. e << args[0] << " does not allow \"" << args[i]
  960. << "\" after PATTERN or REGEX.";
  961. this->SetError(e.str());
  962. return false;
  963. }
  964. // Add this option literally.
  965. literal_args += " FILES_MATCHING";
  966. doing = DoingNone;
  967. } else if (args[i] == "CONFIGURATIONS") {
  968. if (in_match_mode) {
  969. std::ostringstream e;
  970. e << args[0] << " does not allow \"" << args[i]
  971. << "\" after PATTERN or REGEX.";
  972. this->SetError(e.str());
  973. return false;
  974. }
  975. // Switch to setting the configurations property.
  976. doing = DoingConfigurations;
  977. } else if (args[i] == "COMPONENT") {
  978. if (in_match_mode) {
  979. std::ostringstream e;
  980. e << args[0] << " does not allow \"" << args[i]
  981. << "\" after PATTERN or REGEX.";
  982. this->SetError(e.str());
  983. return false;
  984. }
  985. // Switch to setting the component property.
  986. doing = DoingComponent;
  987. } else if (args[i] == "EXCLUDE_FROM_ALL") {
  988. if (in_match_mode) {
  989. std::ostringstream e;
  990. e << args[0] << " does not allow \"" << args[i]
  991. << "\" after PATTERN or REGEX.";
  992. this->SetError(e.str());
  993. return false;
  994. }
  995. exclude_from_all = true;
  996. doing = DoingNone;
  997. } else if (doing == DoingDirs) {
  998. // Convert this directory to a full path.
  999. std::string dir = args[i];
  1000. std::string::size_type gpos = cmGeneratorExpression::Find(dir);
  1001. if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
  1002. dir = this->Makefile->GetCurrentSourceDirectory();
  1003. dir += "/";
  1004. dir += args[i];
  1005. }
  1006. // Make sure the name is a directory.
  1007. if (cmSystemTools::FileExists(dir) &&
  1008. !cmSystemTools::FileIsDirectory(dir)) {
  1009. std::ostringstream e;
  1010. e << args[0] << " given non-directory \"" << args[i]
  1011. << "\" to install.";
  1012. this->SetError(e.str());
  1013. return false;
  1014. }
  1015. // Store the directory for installation.
  1016. dirs.push_back(std::move(dir));
  1017. } else if (doing == DoingConfigurations) {
  1018. configurations.push_back(args[i]);
  1019. } else if (doing == DoingDestination) {
  1020. destination = args[i].c_str();
  1021. doing = DoingNone;
  1022. } else if (doing == DoingPattern) {
  1023. // Convert the pattern to a regular expression. Require a
  1024. // leading slash and trailing end-of-string in the matched
  1025. // string to make sure the pattern matches only whole file
  1026. // names.
  1027. literal_args += " REGEX \"/";
  1028. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1029. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1030. literal_args += regex;
  1031. literal_args += "$\"";
  1032. doing = DoingNone;
  1033. } else if (doing == DoingRegex) {
  1034. literal_args += " REGEX \"";
  1035. // Match rules are case-insensitive on some platforms.
  1036. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  1037. std::string regex = cmSystemTools::LowerCase(args[i]);
  1038. #else
  1039. std::string regex = args[i];
  1040. #endif
  1041. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1042. literal_args += regex;
  1043. literal_args += "\"";
  1044. doing = DoingNone;
  1045. } else if (doing == DoingComponent) {
  1046. component = args[i];
  1047. doing = DoingNone;
  1048. } else if (doing == DoingPermsFile) {
  1049. // Check the requested permission.
  1050. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1051. permissions_file)) {
  1052. std::ostringstream e;
  1053. e << args[0] << " given invalid file permission \"" << args[i]
  1054. << "\".";
  1055. this->SetError(e.str());
  1056. return false;
  1057. }
  1058. } else if (doing == DoingPermsDir) {
  1059. // Check the requested permission.
  1060. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1061. permissions_dir)) {
  1062. std::ostringstream e;
  1063. e << args[0] << " given invalid directory permission \"" << args[i]
  1064. << "\".";
  1065. this->SetError(e.str());
  1066. return false;
  1067. }
  1068. } else if (doing == DoingPermsMatch) {
  1069. // Check the requested permission.
  1070. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1071. literal_args)) {
  1072. std::ostringstream e;
  1073. e << args[0] << " given invalid permission \"" << args[i] << "\".";
  1074. this->SetError(e.str());
  1075. return false;
  1076. }
  1077. } else {
  1078. // Unknown argument.
  1079. std::ostringstream e;
  1080. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  1081. this->SetError(e.str());
  1082. return false;
  1083. }
  1084. }
  1085. // Support installing an empty directory.
  1086. if (dirs.empty() && destination) {
  1087. dirs.emplace_back();
  1088. }
  1089. // Check if there is something to do.
  1090. if (dirs.empty()) {
  1091. return true;
  1092. }
  1093. if (!destination) {
  1094. // A destination is required.
  1095. std::ostringstream e;
  1096. e << args[0] << " given no DESTINATION!";
  1097. this->SetError(e.str());
  1098. return false;
  1099. }
  1100. cmInstallGenerator::MessageLevel message =
  1101. cmInstallGenerator::SelectMessageLevel(this->Makefile, message_never);
  1102. // Create the directory install generator.
  1103. this->Makefile->AddInstallGenerator(new cmInstallDirectoryGenerator(
  1104. dirs, destination, permissions_file.c_str(), permissions_dir.c_str(),
  1105. configurations, component.c_str(), message, exclude_from_all,
  1106. literal_args.c_str(), optional));
  1107. // Tell the global generator about any installation component names
  1108. // specified.
  1109. this->Makefile->GetGlobalGenerator()->AddInstallComponent(component.c_str());
  1110. return true;
  1111. }
  1112. bool cmInstallCommand::HandleExportAndroidMKMode(
  1113. std::vector<std::string> const& args)
  1114. {
  1115. #ifdef CMAKE_BUILD_WITH_CMAKE
  1116. // This is the EXPORT mode.
  1117. cmInstallCommandArguments ica(this->DefaultComponentName);
  1118. cmCAString exp(&ica.Parser, "EXPORT_ANDROID_MK");
  1119. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1120. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1121. &ica.ArgumentGroup);
  1122. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1123. exp.Follows(nullptr);
  1124. ica.ArgumentGroup.Follows(&exp);
  1125. std::vector<std::string> unknownArgs;
  1126. ica.Parse(&args, &unknownArgs);
  1127. if (!unknownArgs.empty()) {
  1128. // Unknown argument.
  1129. std::ostringstream e;
  1130. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1131. this->SetError(e.str());
  1132. return false;
  1133. }
  1134. if (!ica.Finalize()) {
  1135. return false;
  1136. }
  1137. // Make sure there is a destination.
  1138. if (ica.GetDestination().empty()) {
  1139. // A destination is required.
  1140. std::ostringstream e;
  1141. e << args[0] << " given no DESTINATION!";
  1142. this->SetError(e.str());
  1143. return false;
  1144. }
  1145. // Check the file name.
  1146. std::string fname = filename.GetString();
  1147. if (fname.find_first_of(":/\\") != std::string::npos) {
  1148. std::ostringstream e;
  1149. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1150. << "The FILE argument may not contain a path. "
  1151. << "Specify the path in the DESTINATION argument.";
  1152. this->SetError(e.str());
  1153. return false;
  1154. }
  1155. // Check the file extension.
  1156. if (!fname.empty() &&
  1157. cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
  1158. std::ostringstream e;
  1159. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1160. << "The FILE argument must specify a name ending in \".mk\".";
  1161. this->SetError(e.str());
  1162. return false;
  1163. }
  1164. if (fname.find_first_of(":/\\") != std::string::npos) {
  1165. std::ostringstream e;
  1166. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1167. << "This name cannot be safely converted to a file name. "
  1168. << "Specify a different export name or use the FILE option to set "
  1169. << "a file name explicitly.";
  1170. this->SetError(e.str());
  1171. return false;
  1172. }
  1173. // Use the default name
  1174. if (fname.empty()) {
  1175. fname = "Android.mk";
  1176. }
  1177. cmExportSet* exportSet =
  1178. this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
  1179. cmInstallGenerator::MessageLevel message =
  1180. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1181. // Create the export install generator.
  1182. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  1183. exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  1184. ica.GetConfigurations(), ica.GetComponent().c_str(), message,
  1185. ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
  1186. exportOld.IsEnabled(), true);
  1187. this->Makefile->AddInstallGenerator(exportGenerator);
  1188. return true;
  1189. #else
  1190. static_cast<void>(args);
  1191. this->SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake");
  1192. return false;
  1193. #endif
  1194. }
  1195. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  1196. {
  1197. // This is the EXPORT mode.
  1198. cmInstallCommandArguments ica(this->DefaultComponentName);
  1199. cmCAString exp(&ica.Parser, "EXPORT");
  1200. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1201. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1202. &ica.ArgumentGroup);
  1203. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1204. exp.Follows(nullptr);
  1205. ica.ArgumentGroup.Follows(&exp);
  1206. std::vector<std::string> unknownArgs;
  1207. ica.Parse(&args, &unknownArgs);
  1208. if (!unknownArgs.empty()) {
  1209. // Unknown argument.
  1210. std::ostringstream e;
  1211. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1212. this->SetError(e.str());
  1213. return false;
  1214. }
  1215. if (!ica.Finalize()) {
  1216. return false;
  1217. }
  1218. // Make sure there is a destination.
  1219. if (ica.GetDestination().empty()) {
  1220. // A destination is required.
  1221. std::ostringstream e;
  1222. e << args[0] << " given no DESTINATION!";
  1223. this->SetError(e.str());
  1224. return false;
  1225. }
  1226. // Check the file name.
  1227. std::string fname = filename.GetString();
  1228. if (fname.find_first_of(":/\\") != std::string::npos) {
  1229. std::ostringstream e;
  1230. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1231. << "The FILE argument may not contain a path. "
  1232. << "Specify the path in the DESTINATION argument.";
  1233. this->SetError(e.str());
  1234. return false;
  1235. }
  1236. // Check the file extension.
  1237. if (!fname.empty() &&
  1238. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
  1239. std::ostringstream e;
  1240. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1241. << "The FILE argument must specify a name ending in \".cmake\".";
  1242. this->SetError(e.str());
  1243. return false;
  1244. }
  1245. // Construct the file name.
  1246. if (fname.empty()) {
  1247. fname = exp.GetString();
  1248. fname += ".cmake";
  1249. if (fname.find_first_of(":/\\") != std::string::npos) {
  1250. std::ostringstream e;
  1251. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1252. << "This name cannot be safely converted to a file name. "
  1253. << "Specify a different export name or use the FILE option to set "
  1254. << "a file name explicitly.";
  1255. this->SetError(e.str());
  1256. return false;
  1257. }
  1258. }
  1259. cmExportSet* exportSet =
  1260. this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
  1261. if (exportOld.IsEnabled()) {
  1262. for (cmTargetExport* te : *exportSet->GetTargetExports()) {
  1263. cmTarget* tgt =
  1264. this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
  1265. const bool newCMP0022Behavior =
  1266. (tgt && tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  1267. tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
  1268. if (!newCMP0022Behavior) {
  1269. std::ostringstream e;
  1270. e << "INSTALL(EXPORT) given keyword \""
  1271. << "EXPORT_LINK_INTERFACE_LIBRARIES"
  1272. << "\", but target \"" << te->TargetName
  1273. << "\" does not have policy CMP0022 set to NEW.";
  1274. this->SetError(e.str());
  1275. return false;
  1276. }
  1277. }
  1278. }
  1279. cmInstallGenerator::MessageLevel message =
  1280. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1281. // Create the export install generator.
  1282. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  1283. exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  1284. ica.GetConfigurations(), ica.GetComponent().c_str(), message,
  1285. ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
  1286. exportOld.IsEnabled(), false);
  1287. this->Makefile->AddInstallGenerator(exportGenerator);
  1288. return true;
  1289. }
  1290. bool cmInstallCommand::MakeFilesFullPath(
  1291. const char* modeName, const std::vector<std::string>& relFiles,
  1292. std::vector<std::string>& absFiles)
  1293. {
  1294. for (std::string const& relFile : relFiles) {
  1295. std::string file = relFile;
  1296. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  1297. if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
  1298. file = this->Makefile->GetCurrentSourceDirectory();
  1299. file += "/";
  1300. file += relFile;
  1301. }
  1302. // Make sure the file is not a directory.
  1303. if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) {
  1304. std::ostringstream e;
  1305. e << modeName << " given directory \"" << relFile << "\" to install.";
  1306. this->SetError(e.str());
  1307. return false;
  1308. }
  1309. // Store the file for installation.
  1310. absFiles.push_back(std::move(file));
  1311. }
  1312. return true;
  1313. }
  1314. bool cmInstallCommand::CheckCMP0006(bool& failure)
  1315. {
  1316. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
  1317. case cmPolicies::WARN:
  1318. this->Makefile->IssueMessage(
  1319. cmake::AUTHOR_WARNING,
  1320. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006));
  1321. CM_FALLTHROUGH;
  1322. case cmPolicies::OLD:
  1323. // OLD behavior is to allow compatibility
  1324. return true;
  1325. case cmPolicies::NEW:
  1326. // NEW behavior is to disallow compatibility
  1327. break;
  1328. case cmPolicies::REQUIRED_IF_USED:
  1329. case cmPolicies::REQUIRED_ALWAYS:
  1330. failure = true;
  1331. this->Makefile->IssueMessage(
  1332. cmake::FATAL_ERROR,
  1333. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006));
  1334. break;
  1335. }
  1336. return false;
  1337. }