cmInstallCommand.cxx 50 KB

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