cmInstallCommand.cxx 41 KB

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