1
0

cmInstallCommand.cxx 48 KB

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