cmInstallCommand.cxx 51 KB

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