cmInstallCommand.cxx 49 KB

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