cmInstallCommand.cxx 50 KB

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