cmInstallCommand.cxx 51 KB

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