cmInstallCommand.cxx 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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. if (cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt)) {
  331. // Found the target. Check its type.
  332. if (target->GetType() != cmStateEnums::EXECUTABLE &&
  333. target->GetType() != cmStateEnums::STATIC_LIBRARY &&
  334. target->GetType() != cmStateEnums::SHARED_LIBRARY &&
  335. target->GetType() != cmStateEnums::MODULE_LIBRARY &&
  336. target->GetType() != cmStateEnums::OBJECT_LIBRARY &&
  337. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  338. std::ostringstream e;
  339. e << "TARGETS given target \"" << tgt
  340. << "\" which is not an executable, library, or module.";
  341. this->SetError(e.str());
  342. return false;
  343. }
  344. // Store the target in the list to be installed.
  345. targets.push_back(target);
  346. } else {
  347. // Did not find the target.
  348. std::ostringstream e;
  349. e << "TARGETS given target \"" << tgt
  350. << "\" which does not exist in this directory.";
  351. this->SetError(e.str());
  352. return false;
  353. }
  354. }
  355. // Keep track of whether we will be performing an installation of
  356. // any files of the given type.
  357. bool installsArchive = false;
  358. bool installsLibrary = false;
  359. bool installsNamelink = false;
  360. bool installsRuntime = false;
  361. bool installsObject = false;
  362. bool installsFramework = false;
  363. bool installsBundle = false;
  364. bool installsPrivateHeader = false;
  365. bool installsPublicHeader = false;
  366. bool installsResource = false;
  367. // Generate install script code to install the given targets.
  368. for (cmTarget* ti : targets) {
  369. // Handle each target type.
  370. cmTarget& target = *ti;
  371. cmInstallTargetGenerator* archiveGenerator = nullptr;
  372. cmInstallTargetGenerator* libraryGenerator = nullptr;
  373. cmInstallTargetGenerator* namelinkGenerator = nullptr;
  374. cmInstallTargetGenerator* runtimeGenerator = nullptr;
  375. cmInstallTargetGenerator* objectGenerator = nullptr;
  376. cmInstallTargetGenerator* frameworkGenerator = nullptr;
  377. cmInstallTargetGenerator* bundleGenerator = nullptr;
  378. cmInstallFilesGenerator* privateHeaderGenerator = nullptr;
  379. cmInstallFilesGenerator* publicHeaderGenerator = nullptr;
  380. cmInstallFilesGenerator* resourceGenerator = nullptr;
  381. // Track whether this is a namelink-only rule.
  382. bool namelinkOnly = false;
  383. switch (target.GetType()) {
  384. case cmStateEnums::SHARED_LIBRARY: {
  385. // Shared libraries are handled differently on DLL and non-DLL
  386. // platforms. All windows platforms are DLL platforms including
  387. // cygwin. Currently no other platform is a DLL platform.
  388. if (dll_platform) {
  389. // When in namelink only mode skip all libraries on Windows.
  390. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  391. continue;
  392. }
  393. // This is a DLL platform.
  394. if (!archiveArgs.GetDestination().empty()) {
  395. // The import library uses the ARCHIVE properties.
  396. archiveGenerator =
  397. CreateInstallTargetGenerator(target, archiveArgs, true);
  398. }
  399. if (!runtimeArgs.GetDestination().empty()) {
  400. // The DLL uses the RUNTIME properties.
  401. runtimeGenerator =
  402. CreateInstallTargetGenerator(target, runtimeArgs, false);
  403. }
  404. if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) {
  405. this->SetError("Library TARGETS given no DESTINATION!");
  406. return false;
  407. }
  408. } else {
  409. // This is a non-DLL platform.
  410. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  411. // INSTALL properties. Otherwise, use the LIBRARY properties.
  412. if (target.IsFrameworkOnApple()) {
  413. // When in namelink only mode skip frameworks.
  414. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  415. continue;
  416. }
  417. // Use the FRAMEWORK properties.
  418. if (!frameworkArgs.GetDestination().empty()) {
  419. frameworkGenerator =
  420. CreateInstallTargetGenerator(target, frameworkArgs, false);
  421. } else {
  422. std::ostringstream e;
  423. e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
  424. "FRAMEWORK target \""
  425. << target.GetName() << "\".";
  426. this->SetError(e.str());
  427. return false;
  428. }
  429. } else {
  430. // The shared library uses the LIBRARY properties.
  431. if (!libraryArgs.GetDestination().empty()) {
  432. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
  433. libraryGenerator =
  434. CreateInstallTargetGenerator(target, libraryArgs, false);
  435. libraryGenerator->SetNamelinkMode(
  436. cmInstallTargetGenerator::NamelinkModeSkip);
  437. }
  438. if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) {
  439. namelinkGenerator = CreateInstallTargetGenerator(
  440. target, libraryArgs, false, false, true);
  441. namelinkGenerator->SetNamelinkMode(
  442. cmInstallTargetGenerator::NamelinkModeOnly);
  443. }
  444. namelinkOnly =
  445. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  446. } else {
  447. std::ostringstream e;
  448. e << "TARGETS given no LIBRARY DESTINATION for shared library "
  449. "target \""
  450. << target.GetName() << "\".";
  451. this->SetError(e.str());
  452. return false;
  453. }
  454. }
  455. }
  456. } break;
  457. case cmStateEnums::STATIC_LIBRARY: {
  458. // If it is marked with FRAMEWORK property use the FRAMEWORK set of
  459. // INSTALL properties. Otherwise, use the LIBRARY properties.
  460. if (target.IsFrameworkOnApple()) {
  461. // When in namelink only mode skip frameworks.
  462. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
  463. continue;
  464. }
  465. // Use the FRAMEWORK properties.
  466. if (!frameworkArgs.GetDestination().empty()) {
  467. frameworkGenerator =
  468. CreateInstallTargetGenerator(target, frameworkArgs, false);
  469. } else {
  470. std::ostringstream e;
  471. e << "TARGETS given no FRAMEWORK DESTINATION for static library "
  472. "FRAMEWORK target \""
  473. << target.GetName() << "\".";
  474. this->SetError(e.str());
  475. return false;
  476. }
  477. } else {
  478. // Static libraries use ARCHIVE properties.
  479. if (!archiveArgs.GetDestination().empty()) {
  480. archiveGenerator =
  481. CreateInstallTargetGenerator(target, archiveArgs, false);
  482. } else {
  483. std::ostringstream e;
  484. e << "TARGETS given no ARCHIVE DESTINATION for static library "
  485. "target \""
  486. << target.GetName() << "\".";
  487. this->SetError(e.str());
  488. return false;
  489. }
  490. }
  491. } break;
  492. case cmStateEnums::MODULE_LIBRARY: {
  493. // Modules use LIBRARY properties.
  494. if (!libraryArgs.GetDestination().empty()) {
  495. libraryGenerator =
  496. CreateInstallTargetGenerator(target, libraryArgs, false);
  497. libraryGenerator->SetNamelinkMode(namelinkMode);
  498. namelinkOnly =
  499. (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
  500. } else {
  501. std::ostringstream e;
  502. e << "TARGETS given no LIBRARY DESTINATION for module target \""
  503. << target.GetName() << "\".";
  504. this->SetError(e.str());
  505. return false;
  506. }
  507. } break;
  508. case cmStateEnums::OBJECT_LIBRARY: {
  509. // Objects use OBJECT properties.
  510. if (!objectArgs.GetDestination().empty()) {
  511. // Verify that we know where the objects are to install them.
  512. std::string reason;
  513. if (!this->Makefile->GetGlobalGenerator()
  514. ->HasKnownObjectFileLocation(&reason)) {
  515. std::ostringstream e;
  516. e << "TARGETS given OBJECT library \"" << target.GetName()
  517. << "\" whose objects may not be installed" << reason << ".";
  518. this->SetError(e.str());
  519. return false;
  520. }
  521. objectGenerator =
  522. CreateInstallTargetGenerator(target, objectArgs, false);
  523. } else {
  524. // Installing an OBJECT library without a destination transforms
  525. // it to an INTERFACE library. It installs no files but can be
  526. // exported.
  527. }
  528. } break;
  529. case cmStateEnums::EXECUTABLE: {
  530. if (target.IsAppBundleOnApple()) {
  531. // Application bundles use the BUNDLE properties.
  532. if (!bundleArgs.GetDestination().empty()) {
  533. bundleGenerator =
  534. CreateInstallTargetGenerator(target, bundleArgs, false);
  535. } else if (!runtimeArgs.GetDestination().empty()) {
  536. bool failure = false;
  537. if (this->CheckCMP0006(failure)) {
  538. // For CMake 2.4 compatibility fallback to the RUNTIME
  539. // properties.
  540. bundleGenerator =
  541. CreateInstallTargetGenerator(target, runtimeArgs, false);
  542. } else if (failure) {
  543. return false;
  544. }
  545. }
  546. if (!bundleGenerator) {
  547. std::ostringstream e;
  548. e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
  549. "executable target \""
  550. << target.GetName() << "\".";
  551. this->SetError(e.str());
  552. return false;
  553. }
  554. } else {
  555. // Executables use the RUNTIME properties.
  556. if (!runtimeArgs.GetDestination().empty()) {
  557. runtimeGenerator =
  558. CreateInstallTargetGenerator(target, runtimeArgs, false);
  559. } else {
  560. std::ostringstream e;
  561. e << "TARGETS given no RUNTIME DESTINATION for executable "
  562. "target \""
  563. << target.GetName() << "\".";
  564. this->SetError(e.str());
  565. return false;
  566. }
  567. }
  568. // On DLL platforms an executable may also have an import
  569. // library. Install it to the archive destination if it
  570. // exists.
  571. if (dll_platform && !archiveArgs.GetDestination().empty() &&
  572. target.IsExecutableWithExports()) {
  573. // The import library uses the ARCHIVE properties.
  574. archiveGenerator =
  575. CreateInstallTargetGenerator(target, archiveArgs, true, true);
  576. }
  577. } break;
  578. case cmStateEnums::INTERFACE_LIBRARY:
  579. // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
  580. // only effect of that is to make it exportable. It installs no
  581. // other files itself.
  582. break;
  583. default:
  584. // This should never happen due to the above type check.
  585. // Ignore the case.
  586. break;
  587. }
  588. // These well-known sets of files are installed *automatically* for
  589. // FRAMEWORK SHARED library targets on the Mac as part of installing the
  590. // FRAMEWORK. For other target types or on other platforms, they are not
  591. // installed automatically and so we need to create install files
  592. // generators for them.
  593. bool createInstallGeneratorsForTargetFileSets = true;
  594. if (target.IsFrameworkOnApple() ||
  595. target.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  596. createInstallGeneratorsForTargetFileSets = false;
  597. }
  598. if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) {
  599. const char* files = target.GetProperty("PRIVATE_HEADER");
  600. if ((files) && (*files)) {
  601. std::vector<std::string> relFiles;
  602. cmSystemTools::ExpandListArgument(files, relFiles);
  603. std::vector<std::string> absFiles;
  604. if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) {
  605. return false;
  606. }
  607. // Create the files install generator.
  608. if (!privateHeaderArgs.GetDestination().empty()) {
  609. privateHeaderGenerator = CreateInstallFilesGenerator(
  610. this->Makefile, absFiles, privateHeaderArgs, false);
  611. } else {
  612. std::ostringstream e;
  613. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  614. << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
  615. cmSystemTools::Message(e.str().c_str(), "Warning");
  616. }
  617. }
  618. files = target.GetProperty("PUBLIC_HEADER");
  619. if ((files) && (*files)) {
  620. std::vector<std::string> relFiles;
  621. cmSystemTools::ExpandListArgument(files, relFiles);
  622. std::vector<std::string> absFiles;
  623. if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) {
  624. return false;
  625. }
  626. // Create the files install generator.
  627. if (!publicHeaderArgs.GetDestination().empty()) {
  628. publicHeaderGenerator = CreateInstallFilesGenerator(
  629. this->Makefile, absFiles, publicHeaderArgs, false);
  630. } else {
  631. std::ostringstream e;
  632. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  633. << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
  634. cmSystemTools::Message(e.str().c_str(), "Warning");
  635. }
  636. }
  637. files = target.GetProperty("RESOURCE");
  638. if ((files) && (*files)) {
  639. std::vector<std::string> relFiles;
  640. cmSystemTools::ExpandListArgument(files, relFiles);
  641. std::vector<std::string> absFiles;
  642. if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles)) {
  643. return false;
  644. }
  645. // Create the files install generator.
  646. if (!resourceArgs.GetDestination().empty()) {
  647. resourceGenerator = CreateInstallFilesGenerator(
  648. this->Makefile, absFiles, resourceArgs, false);
  649. } else {
  650. std::ostringstream e;
  651. e << "INSTALL TARGETS - target " << target.GetName() << " has "
  652. << "RESOURCE files but no RESOURCE DESTINATION.";
  653. cmSystemTools::Message(e.str().c_str(), "Warning");
  654. }
  655. }
  656. }
  657. // Keep track of whether we're installing anything in each category
  658. installsArchive = installsArchive || archiveGenerator != nullptr;
  659. installsLibrary = installsLibrary || libraryGenerator != nullptr;
  660. installsNamelink = installsNamelink || namelinkGenerator != nullptr;
  661. installsRuntime = installsRuntime || runtimeGenerator != nullptr;
  662. installsObject = installsObject || objectGenerator != nullptr;
  663. installsFramework = installsFramework || frameworkGenerator != nullptr;
  664. installsBundle = installsBundle || bundleGenerator != nullptr;
  665. installsPrivateHeader =
  666. installsPrivateHeader || privateHeaderGenerator != nullptr;
  667. installsPublicHeader =
  668. installsPublicHeader || publicHeaderGenerator != nullptr;
  669. installsResource = installsResource || resourceGenerator;
  670. this->Makefile->AddInstallGenerator(archiveGenerator);
  671. this->Makefile->AddInstallGenerator(libraryGenerator);
  672. this->Makefile->AddInstallGenerator(namelinkGenerator);
  673. this->Makefile->AddInstallGenerator(runtimeGenerator);
  674. this->Makefile->AddInstallGenerator(objectGenerator);
  675. this->Makefile->AddInstallGenerator(frameworkGenerator);
  676. this->Makefile->AddInstallGenerator(bundleGenerator);
  677. this->Makefile->AddInstallGenerator(privateHeaderGenerator);
  678. this->Makefile->AddInstallGenerator(publicHeaderGenerator);
  679. this->Makefile->AddInstallGenerator(resourceGenerator);
  680. // Add this install rule to an export if one was specified and
  681. // this is not a namelink-only rule.
  682. if (!exports.GetString().empty() && !namelinkOnly) {
  683. cmTargetExport* te = new cmTargetExport;
  684. te->TargetName = target.GetName();
  685. te->ArchiveGenerator = archiveGenerator;
  686. te->BundleGenerator = bundleGenerator;
  687. te->FrameworkGenerator = frameworkGenerator;
  688. te->HeaderGenerator = publicHeaderGenerator;
  689. te->LibraryGenerator = libraryGenerator;
  690. te->RuntimeGenerator = runtimeGenerator;
  691. te->ObjectsGenerator = objectGenerator;
  692. this->Makefile->GetGlobalGenerator()
  693. ->GetExportSets()[exports.GetString()]
  694. ->AddTargetExport(te);
  695. te->InterfaceIncludeDirectories =
  696. cmJoin(includesArgs.GetIncludeDirs(), ";");
  697. }
  698. }
  699. // Tell the global generator about any installation component names
  700. // specified
  701. if (installsArchive) {
  702. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  703. archiveArgs.GetComponent().c_str());
  704. }
  705. if (installsLibrary) {
  706. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  707. libraryArgs.GetComponent().c_str());
  708. }
  709. if (installsNamelink) {
  710. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  711. libraryArgs.GetNamelinkComponent().c_str());
  712. }
  713. if (installsRuntime) {
  714. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  715. runtimeArgs.GetComponent().c_str());
  716. }
  717. if (installsObject) {
  718. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  719. objectArgs.GetComponent().c_str());
  720. }
  721. if (installsFramework) {
  722. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  723. frameworkArgs.GetComponent().c_str());
  724. }
  725. if (installsBundle) {
  726. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  727. bundleArgs.GetComponent().c_str());
  728. }
  729. if (installsPrivateHeader) {
  730. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  731. privateHeaderArgs.GetComponent().c_str());
  732. }
  733. if (installsPublicHeader) {
  734. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  735. publicHeaderArgs.GetComponent().c_str());
  736. }
  737. if (installsResource) {
  738. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  739. resourceArgs.GetComponent().c_str());
  740. }
  741. return true;
  742. }
  743. bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
  744. {
  745. // This is the FILES mode.
  746. bool programs = (args[0] == "PROGRAMS");
  747. cmInstallCommandArguments ica(this->DefaultComponentName);
  748. cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
  749. files.Follows(nullptr);
  750. ica.ArgumentGroup.Follows(&files);
  751. std::vector<std::string> unknownArgs;
  752. ica.Parse(&args, &unknownArgs);
  753. if (!unknownArgs.empty()) {
  754. // Unknown argument.
  755. std::ostringstream e;
  756. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  757. this->SetError(e.str());
  758. return false;
  759. }
  760. const std::vector<std::string>& filesVector = files.GetVector();
  761. // Check if there is something to do.
  762. if (filesVector.empty()) {
  763. return true;
  764. }
  765. if (!ica.GetRename().empty() && filesVector.size() > 1) {
  766. // The rename option works only with one file.
  767. std::ostringstream e;
  768. e << args[0] << " given RENAME option with more than one file.";
  769. this->SetError(e.str());
  770. return false;
  771. }
  772. std::vector<std::string> absFiles;
  773. if (!this->MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) {
  774. return false;
  775. }
  776. cmPolicies::PolicyStatus status =
  777. this->Makefile->GetPolicyStatus(cmPolicies::CMP0062);
  778. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  779. for (std::string const& file : filesVector) {
  780. if (gg->IsExportedTargetsFile(file)) {
  781. const char* modal = nullptr;
  782. std::ostringstream e;
  783. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  784. switch (status) {
  785. case cmPolicies::WARN:
  786. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0062) << "\n";
  787. modal = "should";
  788. case cmPolicies::OLD:
  789. break;
  790. case cmPolicies::REQUIRED_IF_USED:
  791. case cmPolicies::REQUIRED_ALWAYS:
  792. case cmPolicies::NEW:
  793. modal = "may";
  794. messageType = cmake::FATAL_ERROR;
  795. }
  796. if (modal) {
  797. e << "The file\n " << file << "\nwas generated by the export() "
  798. "command. It "
  799. << modal << " not be installed with the "
  800. "install() command. Use the install(EXPORT) mechanism "
  801. "instead. See the cmake-packages(7) manual for more.\n";
  802. this->Makefile->IssueMessage(messageType, e.str());
  803. if (messageType == cmake::FATAL_ERROR) {
  804. return false;
  805. }
  806. }
  807. }
  808. }
  809. if (!ica.Finalize()) {
  810. return false;
  811. }
  812. if (ica.GetDestination().empty()) {
  813. // A destination is required.
  814. std::ostringstream e;
  815. e << args[0] << " given no DESTINATION!";
  816. this->SetError(e.str());
  817. return false;
  818. }
  819. // Create the files install generator.
  820. this->Makefile->AddInstallGenerator(
  821. CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
  822. // Tell the global generator about any installation component names
  823. // specified.
  824. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  825. ica.GetComponent().c_str());
  826. return true;
  827. }
  828. bool cmInstallCommand::HandleDirectoryMode(
  829. std::vector<std::string> const& args)
  830. {
  831. enum Doing
  832. {
  833. DoingNone,
  834. DoingDirs,
  835. DoingDestination,
  836. DoingPattern,
  837. DoingRegex,
  838. DoingPermsFile,
  839. DoingPermsDir,
  840. DoingPermsMatch,
  841. DoingConfigurations,
  842. DoingComponent
  843. };
  844. Doing doing = DoingDirs;
  845. bool in_match_mode = false;
  846. bool optional = false;
  847. bool exclude_from_all = false;
  848. bool message_never = false;
  849. std::vector<std::string> dirs;
  850. const char* destination = nullptr;
  851. std::string permissions_file;
  852. std::string permissions_dir;
  853. std::vector<std::string> configurations;
  854. std::string component = this->DefaultComponentName;
  855. std::string literal_args;
  856. for (unsigned int i = 1; i < args.size(); ++i) {
  857. if (args[i] == "DESTINATION") {
  858. if (in_match_mode) {
  859. std::ostringstream e;
  860. e << args[0] << " does not allow \"" << args[i]
  861. << "\" after PATTERN or REGEX.";
  862. this->SetError(e.str());
  863. return false;
  864. }
  865. // Switch to setting the destination property.
  866. doing = DoingDestination;
  867. } else if (args[i] == "OPTIONAL") {
  868. if (in_match_mode) {
  869. std::ostringstream e;
  870. e << args[0] << " does not allow \"" << args[i]
  871. << "\" after PATTERN or REGEX.";
  872. this->SetError(e.str());
  873. return false;
  874. }
  875. // Mark the rule as optional.
  876. optional = true;
  877. doing = DoingNone;
  878. } else if (args[i] == "MESSAGE_NEVER") {
  879. if (in_match_mode) {
  880. std::ostringstream e;
  881. e << args[0] << " does not allow \"" << args[i]
  882. << "\" after PATTERN or REGEX.";
  883. this->SetError(e.str());
  884. return false;
  885. }
  886. // Mark the rule as quiet.
  887. message_never = true;
  888. doing = DoingNone;
  889. } else if (args[i] == "PATTERN") {
  890. // Switch to a new pattern match rule.
  891. doing = DoingPattern;
  892. in_match_mode = true;
  893. } else if (args[i] == "REGEX") {
  894. // Switch to a new regex match rule.
  895. doing = DoingRegex;
  896. in_match_mode = true;
  897. } else if (args[i] == "EXCLUDE") {
  898. // Add this property to the current match rule.
  899. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
  900. std::ostringstream e;
  901. e << args[0] << " does not allow \"" << args[i]
  902. << "\" before a PATTERN or REGEX is given.";
  903. this->SetError(e.str());
  904. return false;
  905. }
  906. literal_args += " EXCLUDE";
  907. doing = DoingNone;
  908. } else if (args[i] == "PERMISSIONS") {
  909. if (!in_match_mode) {
  910. std::ostringstream e;
  911. e << args[0] << " does not allow \"" << args[i]
  912. << "\" before a PATTERN or REGEX is given.";
  913. this->SetError(e.str());
  914. return false;
  915. }
  916. // Switch to setting the current match permissions property.
  917. literal_args += " PERMISSIONS";
  918. doing = DoingPermsMatch;
  919. } else if (args[i] == "FILE_PERMISSIONS") {
  920. if (in_match_mode) {
  921. std::ostringstream e;
  922. e << args[0] << " does not allow \"" << args[i]
  923. << "\" after PATTERN or REGEX.";
  924. this->SetError(e.str());
  925. return false;
  926. }
  927. // Switch to setting the file permissions property.
  928. doing = DoingPermsFile;
  929. } else if (args[i] == "DIRECTORY_PERMISSIONS") {
  930. if (in_match_mode) {
  931. std::ostringstream e;
  932. e << args[0] << " does not allow \"" << args[i]
  933. << "\" after PATTERN or REGEX.";
  934. this->SetError(e.str());
  935. return false;
  936. }
  937. // Switch to setting the directory permissions property.
  938. doing = DoingPermsDir;
  939. } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
  940. if (in_match_mode) {
  941. std::ostringstream e;
  942. e << args[0] << " does not allow \"" << args[i]
  943. << "\" after PATTERN or REGEX.";
  944. this->SetError(e.str());
  945. return false;
  946. }
  947. // Add this option literally.
  948. literal_args += " USE_SOURCE_PERMISSIONS";
  949. doing = DoingNone;
  950. } else if (args[i] == "FILES_MATCHING") {
  951. if (in_match_mode) {
  952. std::ostringstream e;
  953. e << args[0] << " does not allow \"" << args[i]
  954. << "\" after PATTERN or REGEX.";
  955. this->SetError(e.str());
  956. return false;
  957. }
  958. // Add this option literally.
  959. literal_args += " FILES_MATCHING";
  960. doing = DoingNone;
  961. } else if (args[i] == "CONFIGURATIONS") {
  962. if (in_match_mode) {
  963. std::ostringstream e;
  964. e << args[0] << " does not allow \"" << args[i]
  965. << "\" after PATTERN or REGEX.";
  966. this->SetError(e.str());
  967. return false;
  968. }
  969. // Switch to setting the configurations property.
  970. doing = DoingConfigurations;
  971. } else if (args[i] == "COMPONENT") {
  972. if (in_match_mode) {
  973. std::ostringstream e;
  974. e << args[0] << " does not allow \"" << args[i]
  975. << "\" after PATTERN or REGEX.";
  976. this->SetError(e.str());
  977. return false;
  978. }
  979. // Switch to setting the component property.
  980. doing = DoingComponent;
  981. } else if (args[i] == "EXCLUDE_FROM_ALL") {
  982. if (in_match_mode) {
  983. std::ostringstream e;
  984. e << args[0] << " does not allow \"" << args[i]
  985. << "\" after PATTERN or REGEX.";
  986. this->SetError(e.str());
  987. return false;
  988. }
  989. exclude_from_all = true;
  990. doing = DoingNone;
  991. } else if (doing == DoingDirs) {
  992. // Convert this directory to a full path.
  993. std::string dir = args[i];
  994. std::string::size_type gpos = cmGeneratorExpression::Find(dir);
  995. if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
  996. dir = this->Makefile->GetCurrentSourceDirectory();
  997. dir += "/";
  998. dir += args[i];
  999. }
  1000. // Make sure the name is a directory.
  1001. if (cmSystemTools::FileExists(dir) &&
  1002. !cmSystemTools::FileIsDirectory(dir)) {
  1003. std::ostringstream e;
  1004. e << args[0] << " given non-directory \"" << args[i]
  1005. << "\" to install.";
  1006. this->SetError(e.str());
  1007. return false;
  1008. }
  1009. // Store the directory for installation.
  1010. dirs.push_back(std::move(dir));
  1011. } else if (doing == DoingConfigurations) {
  1012. configurations.push_back(args[i]);
  1013. } else if (doing == DoingDestination) {
  1014. destination = args[i].c_str();
  1015. doing = DoingNone;
  1016. } else if (doing == DoingPattern) {
  1017. // Convert the pattern to a regular expression. Require a
  1018. // leading slash and trailing end-of-string in the matched
  1019. // string to make sure the pattern matches only whole file
  1020. // names.
  1021. literal_args += " REGEX \"/";
  1022. std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
  1023. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1024. literal_args += regex;
  1025. literal_args += "$\"";
  1026. doing = DoingNone;
  1027. } else if (doing == DoingRegex) {
  1028. literal_args += " REGEX \"";
  1029. // Match rules are case-insensitive on some platforms.
  1030. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  1031. std::string regex = cmSystemTools::LowerCase(args[i]);
  1032. #else
  1033. std::string regex = args[i];
  1034. #endif
  1035. cmSystemTools::ReplaceString(regex, "\\", "\\\\");
  1036. literal_args += regex;
  1037. literal_args += "\"";
  1038. doing = DoingNone;
  1039. } else if (doing == DoingComponent) {
  1040. component = args[i];
  1041. doing = DoingNone;
  1042. } else if (doing == DoingPermsFile) {
  1043. // Check the requested permission.
  1044. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1045. permissions_file)) {
  1046. std::ostringstream e;
  1047. e << args[0] << " given invalid file permission \"" << args[i]
  1048. << "\".";
  1049. this->SetError(e.str());
  1050. return false;
  1051. }
  1052. } else if (doing == DoingPermsDir) {
  1053. // Check the requested permission.
  1054. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1055. permissions_dir)) {
  1056. std::ostringstream e;
  1057. e << args[0] << " given invalid directory permission \"" << args[i]
  1058. << "\".";
  1059. this->SetError(e.str());
  1060. return false;
  1061. }
  1062. } else if (doing == DoingPermsMatch) {
  1063. // Check the requested permission.
  1064. if (!cmInstallCommandArguments::CheckPermissions(args[i],
  1065. literal_args)) {
  1066. std::ostringstream e;
  1067. e << args[0] << " given invalid permission \"" << args[i] << "\".";
  1068. this->SetError(e.str());
  1069. return false;
  1070. }
  1071. } else {
  1072. // Unknown argument.
  1073. std::ostringstream e;
  1074. e << args[0] << " given unknown argument \"" << args[i] << "\".";
  1075. this->SetError(e.str());
  1076. return false;
  1077. }
  1078. }
  1079. // Support installing an empty directory.
  1080. if (dirs.empty() && destination) {
  1081. dirs.emplace_back();
  1082. }
  1083. // Check if there is something to do.
  1084. if (dirs.empty()) {
  1085. return true;
  1086. }
  1087. if (!destination) {
  1088. // A destination is required.
  1089. std::ostringstream e;
  1090. e << args[0] << " given no DESTINATION!";
  1091. this->SetError(e.str());
  1092. return false;
  1093. }
  1094. cmInstallGenerator::MessageLevel message =
  1095. cmInstallGenerator::SelectMessageLevel(this->Makefile, message_never);
  1096. // Create the directory install generator.
  1097. this->Makefile->AddInstallGenerator(new cmInstallDirectoryGenerator(
  1098. dirs, destination, permissions_file.c_str(), permissions_dir.c_str(),
  1099. configurations, component.c_str(), message, exclude_from_all,
  1100. literal_args.c_str(), optional));
  1101. // Tell the global generator about any installation component names
  1102. // specified.
  1103. this->Makefile->GetGlobalGenerator()->AddInstallComponent(component.c_str());
  1104. return true;
  1105. }
  1106. bool cmInstallCommand::HandleExportAndroidMKMode(
  1107. std::vector<std::string> const& args)
  1108. {
  1109. #ifdef CMAKE_BUILD_WITH_CMAKE
  1110. // This is the EXPORT mode.
  1111. cmInstallCommandArguments ica(this->DefaultComponentName);
  1112. cmCAString exp(&ica.Parser, "EXPORT_ANDROID_MK");
  1113. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1114. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1115. &ica.ArgumentGroup);
  1116. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1117. exp.Follows(nullptr);
  1118. ica.ArgumentGroup.Follows(&exp);
  1119. std::vector<std::string> unknownArgs;
  1120. ica.Parse(&args, &unknownArgs);
  1121. if (!unknownArgs.empty()) {
  1122. // Unknown argument.
  1123. std::ostringstream e;
  1124. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1125. this->SetError(e.str());
  1126. return false;
  1127. }
  1128. if (!ica.Finalize()) {
  1129. return false;
  1130. }
  1131. // Make sure there is a destination.
  1132. if (ica.GetDestination().empty()) {
  1133. // A destination is required.
  1134. std::ostringstream e;
  1135. e << args[0] << " given no DESTINATION!";
  1136. this->SetError(e.str());
  1137. return false;
  1138. }
  1139. // Check the file name.
  1140. std::string fname = filename.GetString();
  1141. if (fname.find_first_of(":/\\") != std::string::npos) {
  1142. std::ostringstream e;
  1143. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1144. << "The FILE argument may not contain a path. "
  1145. << "Specify the path in the DESTINATION argument.";
  1146. this->SetError(e.str());
  1147. return false;
  1148. }
  1149. // Check the file extension.
  1150. if (!fname.empty() &&
  1151. cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
  1152. std::ostringstream e;
  1153. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1154. << "The FILE argument must specify a name ending in \".mk\".";
  1155. this->SetError(e.str());
  1156. return false;
  1157. }
  1158. if (fname.find_first_of(":/\\") != std::string::npos) {
  1159. std::ostringstream e;
  1160. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1161. << "This name cannot be safely converted to a file name. "
  1162. << "Specify a different export name or use the FILE option to set "
  1163. << "a file name explicitly.";
  1164. this->SetError(e.str());
  1165. return false;
  1166. }
  1167. // Use the default name
  1168. if (fname.empty()) {
  1169. fname = "Android.mk";
  1170. }
  1171. cmExportSet* exportSet =
  1172. this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
  1173. cmInstallGenerator::MessageLevel message =
  1174. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1175. // Create the export install generator.
  1176. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  1177. exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  1178. ica.GetConfigurations(), ica.GetComponent().c_str(), message,
  1179. ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
  1180. exportOld.IsEnabled(), true);
  1181. this->Makefile->AddInstallGenerator(exportGenerator);
  1182. return true;
  1183. #else
  1184. static_cast<void>(args);
  1185. this->SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake");
  1186. return false;
  1187. #endif
  1188. }
  1189. bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
  1190. {
  1191. // This is the EXPORT mode.
  1192. cmInstallCommandArguments ica(this->DefaultComponentName);
  1193. cmCAString exp(&ica.Parser, "EXPORT");
  1194. cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
  1195. cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES",
  1196. &ica.ArgumentGroup);
  1197. cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
  1198. exp.Follows(nullptr);
  1199. ica.ArgumentGroup.Follows(&exp);
  1200. std::vector<std::string> unknownArgs;
  1201. ica.Parse(&args, &unknownArgs);
  1202. if (!unknownArgs.empty()) {
  1203. // Unknown argument.
  1204. std::ostringstream e;
  1205. e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
  1206. this->SetError(e.str());
  1207. return false;
  1208. }
  1209. if (!ica.Finalize()) {
  1210. return false;
  1211. }
  1212. // Make sure there is a destination.
  1213. if (ica.GetDestination().empty()) {
  1214. // A destination is required.
  1215. std::ostringstream e;
  1216. e << args[0] << " given no DESTINATION!";
  1217. this->SetError(e.str());
  1218. return false;
  1219. }
  1220. // Check the file name.
  1221. std::string fname = filename.GetString();
  1222. if (fname.find_first_of(":/\\") != std::string::npos) {
  1223. std::ostringstream e;
  1224. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1225. << "The FILE argument may not contain a path. "
  1226. << "Specify the path in the DESTINATION argument.";
  1227. this->SetError(e.str());
  1228. return false;
  1229. }
  1230. // Check the file extension.
  1231. if (!fname.empty() &&
  1232. cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
  1233. std::ostringstream e;
  1234. e << args[0] << " given invalid export file name \"" << fname << "\". "
  1235. << "The FILE argument must specify a name ending in \".cmake\".";
  1236. this->SetError(e.str());
  1237. return false;
  1238. }
  1239. // Construct the file name.
  1240. if (fname.empty()) {
  1241. fname = exp.GetString();
  1242. fname += ".cmake";
  1243. if (fname.find_first_of(":/\\") != std::string::npos) {
  1244. std::ostringstream e;
  1245. e << args[0] << " given export name \"" << exp.GetString() << "\". "
  1246. << "This name cannot be safely converted to a file name. "
  1247. << "Specify a different export name or use the FILE option to set "
  1248. << "a file name explicitly.";
  1249. this->SetError(e.str());
  1250. return false;
  1251. }
  1252. }
  1253. cmExportSet* exportSet =
  1254. this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
  1255. if (exportOld.IsEnabled()) {
  1256. for (cmTargetExport* te : *exportSet->GetTargetExports()) {
  1257. cmTarget* tgt =
  1258. this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
  1259. const bool newCMP0022Behavior =
  1260. (tgt && tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  1261. tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
  1262. if (!newCMP0022Behavior) {
  1263. std::ostringstream e;
  1264. e << "INSTALL(EXPORT) given keyword \""
  1265. << "EXPORT_LINK_INTERFACE_LIBRARIES"
  1266. << "\", but target \"" << te->TargetName
  1267. << "\" does not have policy CMP0022 set to NEW.";
  1268. this->SetError(e.str());
  1269. return false;
  1270. }
  1271. }
  1272. }
  1273. cmInstallGenerator::MessageLevel message =
  1274. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  1275. // Create the export install generator.
  1276. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
  1277. exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
  1278. ica.GetConfigurations(), ica.GetComponent().c_str(), message,
  1279. ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
  1280. exportOld.IsEnabled(), false);
  1281. this->Makefile->AddInstallGenerator(exportGenerator);
  1282. return true;
  1283. }
  1284. bool cmInstallCommand::MakeFilesFullPath(
  1285. const char* modeName, const std::vector<std::string>& relFiles,
  1286. std::vector<std::string>& absFiles)
  1287. {
  1288. for (std::string const& relFile : relFiles) {
  1289. std::string file = relFile;
  1290. std::string::size_type gpos = cmGeneratorExpression::Find(file);
  1291. if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
  1292. file = this->Makefile->GetCurrentSourceDirectory();
  1293. file += "/";
  1294. file += relFile;
  1295. }
  1296. // Make sure the file is not a directory.
  1297. if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) {
  1298. std::ostringstream e;
  1299. e << modeName << " given directory \"" << relFile << "\" to install.";
  1300. this->SetError(e.str());
  1301. return false;
  1302. }
  1303. // Store the file for installation.
  1304. absFiles.push_back(std::move(file));
  1305. }
  1306. return true;
  1307. }
  1308. bool cmInstallCommand::CheckCMP0006(bool& failure)
  1309. {
  1310. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
  1311. case cmPolicies::WARN:
  1312. this->Makefile->IssueMessage(
  1313. cmake::AUTHOR_WARNING,
  1314. cmPolicies::GetPolicyWarning(cmPolicies::CMP0006));
  1315. CM_FALLTHROUGH;
  1316. case cmPolicies::OLD:
  1317. // OLD behavior is to allow compatibility
  1318. return true;
  1319. case cmPolicies::NEW:
  1320. // NEW behavior is to disallow compatibility
  1321. break;
  1322. case cmPolicies::REQUIRED_IF_USED:
  1323. case cmPolicies::REQUIRED_ALWAYS:
  1324. failure = true;
  1325. this->Makefile->IssueMessage(
  1326. cmake::FATAL_ERROR,
  1327. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006));
  1328. break;
  1329. }
  1330. return false;
  1331. }