cmInstallCommand.cxx 48 KB

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