cmInstallCommand.cxx 50 KB

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