cmInstallTargetGenerator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallTargetGenerator.h"
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmake.h"
  16. #include "cmGeneratorTarget.h"
  17. #include <assert.h>
  18. //----------------------------------------------------------------------------
  19. cmInstallTargetGenerator
  20. ::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
  21. const char* file_permissions,
  22. std::vector<std::string> const& configurations,
  23. const char* component, bool optional):
  24. cmInstallGenerator(dest, configurations, component), Target(&t),
  25. ImportLibrary(implib), FilePermissions(file_permissions),
  26. Optional(optional), GeneratorTarget(0)
  27. {
  28. this->ActionsPerConfig = true;
  29. this->NamelinkMode = NamelinkModeNone;
  30. this->Target->SetHaveInstallRule(true);
  31. }
  32. //----------------------------------------------------------------------------
  33. cmInstallTargetGenerator
  34. ::~cmInstallTargetGenerator()
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
  39. {
  40. // Warn if installing an exclude-from-all target.
  41. if(this->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  42. {
  43. cmOStringStream msg;
  44. msg << "WARNING: Target \"" << this->Target->GetName()
  45. << "\" has EXCLUDE_FROM_ALL set and will not be built by default "
  46. << "but an install rule has been provided for it. CMake does "
  47. << "not define behavior for this case.";
  48. cmSystemTools::Message(msg.str().c_str(), "Warning");
  49. }
  50. // Perform the main install script generation.
  51. this->cmInstallGenerator::GenerateScript(os);
  52. }
  53. //----------------------------------------------------------------------------
  54. void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
  55. const char* config,
  56. Indent const& indent)
  57. {
  58. // Compute the build tree directory from which to copy the target.
  59. std::string fromDirConfig;
  60. if(this->Target->NeedRelinkBeforeInstall(config))
  61. {
  62. fromDirConfig = this->Target->GetMakefile()->GetStartOutputDirectory();
  63. fromDirConfig += cmake::GetCMakeFilesDirectory();
  64. fromDirConfig += "/CMakeRelink.dir/";
  65. }
  66. else
  67. {
  68. fromDirConfig = this->Target->GetDirectory(config, this->ImportLibrary);
  69. fromDirConfig += "/";
  70. }
  71. std::string toDir = this->GetInstallDestination();
  72. toDir += "/";
  73. // Compute the list of files to install for this target.
  74. std::vector<std::string> filesFrom;
  75. std::vector<std::string> filesTo;
  76. std::string literal_args;
  77. cmTarget::TargetType targetType = this->Target->GetType();
  78. cmInstallType type = cmInstallType();
  79. switch(targetType)
  80. {
  81. case cmTarget::EXECUTABLE: type = cmInstallType_EXECUTABLE; break;
  82. case cmTarget::STATIC_LIBRARY: type = cmInstallType_STATIC_LIBRARY; break;
  83. case cmTarget::SHARED_LIBRARY: type = cmInstallType_SHARED_LIBRARY; break;
  84. case cmTarget::MODULE_LIBRARY: type = cmInstallType_MODULE_LIBRARY; break;
  85. case cmTarget::OBJECT_LIBRARY:
  86. case cmTarget::UTILITY:
  87. case cmTarget::GLOBAL_TARGET:
  88. case cmTarget::UNKNOWN_LIBRARY:
  89. this->Target->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
  90. "cmInstallTargetGenerator created with non-installable target.");
  91. return;
  92. }
  93. if(targetType == cmTarget::EXECUTABLE)
  94. {
  95. // There is a bug in cmInstallCommand if this fails.
  96. assert(this->NamelinkMode == NamelinkModeNone);
  97. std::string targetName;
  98. std::string targetNameReal;
  99. std::string targetNameImport;
  100. std::string targetNamePDB;
  101. this->Target->GetExecutableNames(targetName, targetNameReal,
  102. targetNameImport, targetNamePDB,
  103. config);
  104. if(this->ImportLibrary)
  105. {
  106. std::string from1 = fromDirConfig + targetNameImport;
  107. std::string to1 = toDir + targetNameImport;
  108. filesFrom.push_back(from1);
  109. filesTo.push_back(to1);
  110. std::string targetNameImportLib;
  111. if(this->Target->GetImplibGNUtoMS(targetNameImport,
  112. targetNameImportLib))
  113. {
  114. filesFrom.push_back(fromDirConfig + targetNameImportLib);
  115. filesTo.push_back(toDir + targetNameImportLib);
  116. }
  117. // An import library looks like a static library.
  118. type = cmInstallType_STATIC_LIBRARY;
  119. }
  120. else
  121. {
  122. std::string from1 = fromDirConfig + targetName;
  123. std::string to1 = toDir + targetName;
  124. // Handle OSX Bundles.
  125. if(this->Target->IsAppBundleOnApple())
  126. {
  127. // Install the whole app bundle directory.
  128. type = cmInstallType_DIRECTORY;
  129. literal_args += " USE_SOURCE_PERMISSIONS";
  130. from1 += ".app";
  131. // Tweaks apply to the binary inside the bundle.
  132. to1 += ".app/Contents/MacOS/";
  133. to1 += targetName;
  134. }
  135. else
  136. {
  137. // Tweaks apply to the real file, so list it first.
  138. if(targetNameReal != targetName)
  139. {
  140. std::string from2 = fromDirConfig + targetNameReal;
  141. std::string to2 = toDir += targetNameReal;
  142. filesFrom.push_back(from2);
  143. filesTo.push_back(to2);
  144. }
  145. }
  146. filesFrom.push_back(from1);
  147. filesTo.push_back(to1);
  148. }
  149. }
  150. else
  151. {
  152. std::string targetName;
  153. std::string targetNameSO;
  154. std::string targetNameReal;
  155. std::string targetNameImport;
  156. std::string targetNamePDB;
  157. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
  158. targetNameImport, targetNamePDB,
  159. config);
  160. if(this->ImportLibrary)
  161. {
  162. // There is a bug in cmInstallCommand if this fails.
  163. assert(this->NamelinkMode == NamelinkModeNone);
  164. std::string from1 = fromDirConfig + targetNameImport;
  165. std::string to1 = toDir + targetNameImport;
  166. filesFrom.push_back(from1);
  167. filesTo.push_back(to1);
  168. std::string targetNameImportLib;
  169. if(this->Target->GetImplibGNUtoMS(targetNameImport,
  170. targetNameImportLib))
  171. {
  172. filesFrom.push_back(fromDirConfig + targetNameImportLib);
  173. filesTo.push_back(toDir + targetNameImportLib);
  174. }
  175. // An import library looks like a static library.
  176. type = cmInstallType_STATIC_LIBRARY;
  177. }
  178. else if(this->Target->IsFrameworkOnApple())
  179. {
  180. // There is a bug in cmInstallCommand if this fails.
  181. assert(this->NamelinkMode == NamelinkModeNone);
  182. // Install the whole framework directory.
  183. type = cmInstallType_DIRECTORY;
  184. literal_args += " USE_SOURCE_PERMISSIONS";
  185. std::string from1 = fromDirConfig + targetName + ".framework";
  186. // Tweaks apply to the binary inside the bundle.
  187. std::string to1 = toDir + targetName;
  188. to1 += ".framework/Versions/";
  189. to1 += this->Target->GetFrameworkVersion();
  190. to1 += "/";
  191. to1 += targetName;
  192. filesFrom.push_back(from1);
  193. filesTo.push_back(to1);
  194. }
  195. else
  196. {
  197. bool haveNamelink = false;
  198. // Library link name.
  199. std::string fromName = fromDirConfig + targetName;
  200. std::string toName = toDir + targetName;
  201. // Library interface name.
  202. std::string fromSOName;
  203. std::string toSOName;
  204. if(targetNameSO != targetName)
  205. {
  206. haveNamelink = true;
  207. fromSOName = fromDirConfig + targetNameSO;
  208. toSOName = toDir + targetNameSO;
  209. }
  210. // Library implementation name.
  211. std::string fromRealName;
  212. std::string toRealName;
  213. if(targetNameReal != targetName &&
  214. targetNameReal != targetNameSO)
  215. {
  216. haveNamelink = true;
  217. fromRealName = fromDirConfig + targetNameReal;
  218. toRealName = toDir + targetNameReal;
  219. }
  220. // Add the names based on the current namelink mode.
  221. if(haveNamelink)
  222. {
  223. // With a namelink we need to check the mode.
  224. if(this->NamelinkMode == NamelinkModeOnly)
  225. {
  226. // Install the namelink only.
  227. filesFrom.push_back(fromName);
  228. filesTo.push_back(toName);
  229. }
  230. else
  231. {
  232. // Install the real file if it has its own name.
  233. if(!fromRealName.empty())
  234. {
  235. filesFrom.push_back(fromRealName);
  236. filesTo.push_back(toRealName);
  237. }
  238. // Install the soname link if it has its own name.
  239. if(!fromSOName.empty())
  240. {
  241. filesFrom.push_back(fromSOName);
  242. filesTo.push_back(toSOName);
  243. }
  244. // Install the namelink if it is not to be skipped.
  245. if(this->NamelinkMode != NamelinkModeSkip)
  246. {
  247. filesFrom.push_back(fromName);
  248. filesTo.push_back(toName);
  249. }
  250. }
  251. }
  252. else
  253. {
  254. // Without a namelink there will be only one file. Install it
  255. // if this is not a namelink-only rule.
  256. if(this->NamelinkMode != NamelinkModeOnly)
  257. {
  258. filesFrom.push_back(fromName);
  259. filesTo.push_back(toName);
  260. }
  261. }
  262. }
  263. }
  264. // If this fails the above code is buggy.
  265. assert(filesFrom.size() == filesTo.size());
  266. // Skip this rule if no files are to be installed for the target.
  267. if(filesFrom.empty())
  268. {
  269. return;
  270. }
  271. // Add pre-installation tweaks.
  272. this->AddTweak(os, indent, config, filesTo,
  273. &cmInstallTargetGenerator::PreReplacementTweaks);
  274. // Write code to install the target file.
  275. const char* no_dir_permissions = 0;
  276. const char* no_rename = 0;
  277. bool optional = this->Optional || this->ImportLibrary;
  278. this->AddInstallRule(os, type, filesFrom,
  279. optional,
  280. this->FilePermissions.c_str(), no_dir_permissions,
  281. no_rename, literal_args.c_str(),
  282. indent);
  283. // Add post-installation tweaks.
  284. this->AddTweak(os, indent, config, filesTo,
  285. &cmInstallTargetGenerator::PostReplacementTweaks);
  286. }
  287. //----------------------------------------------------------------------------
  288. std::string
  289. cmInstallTargetGenerator::GetInstallFilename(const char* config) const
  290. {
  291. NameType nameType = this->ImportLibrary? NameImplib : NameNormal;
  292. return
  293. cmInstallTargetGenerator::GetInstallFilename(this->Target, config,
  294. nameType);
  295. }
  296. //----------------------------------------------------------------------------
  297. std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target,
  298. const char* config,
  299. NameType nameType)
  300. {
  301. std::string fname;
  302. // Compute the name of the library.
  303. if(target->GetType() == cmTarget::EXECUTABLE)
  304. {
  305. std::string targetName;
  306. std::string targetNameReal;
  307. std::string targetNameImport;
  308. std::string targetNamePDB;
  309. target->GetExecutableNames(targetName, targetNameReal,
  310. targetNameImport, targetNamePDB,
  311. config);
  312. if(nameType == NameImplib)
  313. {
  314. // Use the import library name.
  315. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  316. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  317. {
  318. fname = targetNameImport;
  319. }
  320. }
  321. else if(nameType == NameReal)
  322. {
  323. // Use the canonical name.
  324. fname = targetNameReal;
  325. }
  326. else
  327. {
  328. // Use the canonical name.
  329. fname = targetName;
  330. }
  331. }
  332. else
  333. {
  334. std::string targetName;
  335. std::string targetNameSO;
  336. std::string targetNameReal;
  337. std::string targetNameImport;
  338. std::string targetNamePDB;
  339. target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
  340. targetNameImport, targetNamePDB, config);
  341. if(nameType == NameImplib)
  342. {
  343. // Use the import library name.
  344. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  345. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  346. {
  347. fname = targetNameImport;
  348. }
  349. }
  350. else if(nameType == NameSO)
  351. {
  352. // Use the soname.
  353. fname = targetNameSO;
  354. }
  355. else if(nameType == NameReal)
  356. {
  357. // Use the real name.
  358. fname = targetNameReal;
  359. }
  360. else
  361. {
  362. // Use the canonical name.
  363. fname = targetName;
  364. }
  365. }
  366. return fname;
  367. }
  368. //----------------------------------------------------------------------------
  369. void
  370. cmInstallTargetGenerator
  371. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  372. std::string const& file, TweakMethod tweak)
  373. {
  374. cmOStringStream tw;
  375. (this->*tweak)(tw, indent.Next(), config, file);
  376. std::string tws = tw.str();
  377. if(!tws.empty())
  378. {
  379. os << indent << "IF(EXISTS \"" << file << "\" AND\n"
  380. << indent << " NOT IS_SYMLINK \"" << file << "\")\n";
  381. os << tws;
  382. os << indent << "ENDIF()\n";
  383. }
  384. }
  385. //----------------------------------------------------------------------------
  386. void
  387. cmInstallTargetGenerator
  388. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  389. std::vector<std::string> const& files, TweakMethod tweak)
  390. {
  391. if(files.size() == 1)
  392. {
  393. // Tweak a single file.
  394. this->AddTweak(os, indent, config, this->GetDestDirPath(files[0]), tweak);
  395. }
  396. else
  397. {
  398. // Generate a foreach loop to tweak multiple files.
  399. cmOStringStream tw;
  400. this->AddTweak(tw, indent.Next(), config, "${file}", tweak);
  401. std::string tws = tw.str();
  402. if(!tws.empty())
  403. {
  404. Indent indent2 = indent.Next().Next();
  405. os << indent << "FOREACH(file\n";
  406. for(std::vector<std::string>::const_iterator i = files.begin();
  407. i != files.end(); ++i)
  408. {
  409. os << indent2 << "\"" << this->GetDestDirPath(*i) << "\"\n";
  410. }
  411. os << indent2 << ")\n";
  412. os << tws;
  413. os << indent << "ENDFOREACH()\n";
  414. }
  415. }
  416. }
  417. //----------------------------------------------------------------------------
  418. std::string cmInstallTargetGenerator::GetDestDirPath(std::string const& file)
  419. {
  420. // Construct the path of the file on disk after installation on
  421. // which tweaks may be performed.
  422. std::string toDestDirPath = "$ENV{DESTDIR}";
  423. if(file[0] != '/' && file[0] != '$')
  424. {
  425. toDestDirPath += "/";
  426. }
  427. toDestDirPath += file;
  428. return toDestDirPath;
  429. }
  430. //----------------------------------------------------------------------------
  431. void cmInstallTargetGenerator::PreReplacementTweaks(std::ostream& os,
  432. Indent const& indent,
  433. const char* config,
  434. std::string const& file)
  435. {
  436. this->AddRPathCheckRule(os, indent, config, file);
  437. }
  438. //----------------------------------------------------------------------------
  439. void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
  440. Indent const& indent,
  441. const char* config,
  442. std::string const& file)
  443. {
  444. this->AddInstallNamePatchRule(os, indent, config, file);
  445. this->AddChrpathPatchRule(os, indent, config, file);
  446. this->AddRanlibRule(os, indent, file);
  447. this->AddStripRule(os, indent, file);
  448. }
  449. void cmInstallTargetGenerator::CreateGeneratorTarget()
  450. {
  451. if (!this->GeneratorTarget)
  452. {
  453. this->GeneratorTarget = this->Target->GetMakefile()
  454. ->GetLocalGenerator()
  455. ->GetGlobalGenerator()
  456. ->GetGeneratorTarget(this->Target);
  457. }
  458. }
  459. //----------------------------------------------------------------------------
  460. void
  461. cmInstallTargetGenerator
  462. ::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
  463. const char* config, std::string const& toDestDirPath)
  464. {
  465. if(this->ImportLibrary ||
  466. !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  467. this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
  468. this->Target->GetType() == cmTarget::EXECUTABLE))
  469. {
  470. return;
  471. }
  472. // Fix the install_name settings in installed binaries.
  473. std::string installNameTool =
  474. this->Target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
  475. if(!installNameTool.size())
  476. {
  477. return;
  478. }
  479. this->CreateGeneratorTarget();
  480. // Build a map of build-tree install_name to install-tree install_name for
  481. // shared libraries linked to this target.
  482. std::map<cmStdString, cmStdString> install_name_remap;
  483. if(cmComputeLinkInformation* cli =
  484. this->GeneratorTarget->GetLinkInformation(config))
  485. {
  486. std::set<cmTarget*> const& sharedLibs = cli->GetSharedLibrariesLinked();
  487. for(std::set<cmTarget*>::const_iterator j = sharedLibs.begin();
  488. j != sharedLibs.end(); ++j)
  489. {
  490. cmTarget* tgt = *j;
  491. // The install_name of an imported target does not change.
  492. if(tgt->IsImported())
  493. {
  494. continue;
  495. }
  496. // If the build tree and install tree use different path
  497. // components of the install_name field then we need to create a
  498. // mapping to be applied after installation.
  499. std::string for_build = tgt->GetInstallNameDirForBuildTree(config);
  500. std::string for_install = tgt->GetInstallNameDirForInstallTree(config);
  501. if(for_build != for_install)
  502. {
  503. // The directory portions differ. Append the filename to
  504. // create the mapping.
  505. std::string fname =
  506. this->GetInstallFilename(tgt, config, NameSO);
  507. // Map from the build-tree install_name.
  508. for_build += fname;
  509. // Map to the install-tree install_name.
  510. for_install += fname;
  511. // Store the mapping entry.
  512. install_name_remap[for_build] = for_install;
  513. }
  514. }
  515. }
  516. // Edit the install_name of the target itself if necessary.
  517. std::string new_id;
  518. if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
  519. {
  520. std::string for_build =
  521. this->Target->GetInstallNameDirForBuildTree(config);
  522. std::string for_install =
  523. this->Target->GetInstallNameDirForInstallTree(config);
  524. if(this->Target->IsFrameworkOnApple() && for_install.empty())
  525. {
  526. // Frameworks seem to have an id corresponding to their own full
  527. // path.
  528. // ...
  529. // for_install = fullDestPath_without_DESTDIR_or_name;
  530. }
  531. // If the install name will change on installation set the new id
  532. // on the installed file.
  533. if(for_build != for_install)
  534. {
  535. // Prepare to refer to the install-tree install_name.
  536. new_id = for_install;
  537. new_id += this->GetInstallFilename(this->Target, config, NameSO);
  538. }
  539. }
  540. // Write a rule to run install_name_tool to set the install-tree
  541. // install_name value and references.
  542. if(!new_id.empty() || !install_name_remap.empty())
  543. {
  544. os << indent << "EXECUTE_PROCESS(COMMAND \"" << installNameTool;
  545. os << "\"";
  546. if(!new_id.empty())
  547. {
  548. os << "\n" << indent << " -id \"" << new_id << "\"";
  549. }
  550. for(std::map<cmStdString, cmStdString>::const_iterator
  551. i = install_name_remap.begin();
  552. i != install_name_remap.end(); ++i)
  553. {
  554. os << "\n" << indent << " -change \""
  555. << i->first << "\" \"" << i->second << "\"";
  556. }
  557. os << "\n" << indent << " \"" << toDestDirPath << "\")\n";
  558. }
  559. }
  560. //----------------------------------------------------------------------------
  561. void
  562. cmInstallTargetGenerator
  563. ::AddRPathCheckRule(std::ostream& os, Indent const& indent,
  564. const char* config, std::string const& toDestDirPath)
  565. {
  566. // Skip the chrpath if the target does not need it.
  567. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  568. {
  569. return;
  570. }
  571. this->CreateGeneratorTarget();
  572. // Get the link information for this target.
  573. // It can provide the RPATH.
  574. cmComputeLinkInformation* cli =
  575. this->GeneratorTarget->GetLinkInformation(config);
  576. if(!cli)
  577. {
  578. return;
  579. }
  580. // Get the install RPATH from the link information.
  581. std::string newRpath = cli->GetChrpathString();
  582. // Write a rule to remove the installed file if its rpath is not the
  583. // new rpath. This is needed for existing build/install trees when
  584. // the installed rpath changes but the file is not rebuilt.
  585. os << indent << "FILE(RPATH_CHECK\n"
  586. << indent << " FILE \"" << toDestDirPath << "\"\n"
  587. << indent << " RPATH \"" << newRpath << "\")\n";
  588. }
  589. //----------------------------------------------------------------------------
  590. void
  591. cmInstallTargetGenerator
  592. ::AddChrpathPatchRule(std::ostream& os, Indent const& indent,
  593. const char* config, std::string const& toDestDirPath)
  594. {
  595. // Skip the chrpath if the target does not need it.
  596. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  597. {
  598. return;
  599. }
  600. this->CreateGeneratorTarget();
  601. // Get the link information for this target.
  602. // It can provide the RPATH.
  603. cmComputeLinkInformation* cli =
  604. this->GeneratorTarget->GetLinkInformation(config);
  605. if(!cli)
  606. {
  607. return;
  608. }
  609. // Construct the original rpath string to be replaced.
  610. std::string oldRpath = cli->GetRPathString(false);
  611. // Get the install RPATH from the link information.
  612. std::string newRpath = cli->GetChrpathString();
  613. // Skip the rule if the paths are identical
  614. if(oldRpath == newRpath)
  615. {
  616. return;
  617. }
  618. // Write a rule to run chrpath to set the install-tree RPATH
  619. if(newRpath.empty())
  620. {
  621. os << indent << "FILE(RPATH_REMOVE\n"
  622. << indent << " FILE \"" << toDestDirPath << "\")\n";
  623. }
  624. else
  625. {
  626. os << indent << "FILE(RPATH_CHANGE\n"
  627. << indent << " FILE \"" << toDestDirPath << "\"\n"
  628. << indent << " OLD_RPATH \"" << oldRpath << "\"\n"
  629. << indent << " NEW_RPATH \"" << newRpath << "\")\n";
  630. }
  631. }
  632. //----------------------------------------------------------------------------
  633. void
  634. cmInstallTargetGenerator::AddStripRule(std::ostream& os,
  635. Indent const& indent,
  636. const std::string& toDestDirPath)
  637. {
  638. // don't strip static libraries, because it removes the only symbol table
  639. // they have so you can't link to them anymore
  640. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  641. {
  642. return;
  643. }
  644. // Don't handle OSX Bundles.
  645. if(this->Target->GetMakefile()->IsOn("APPLE") &&
  646. this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
  647. {
  648. return;
  649. }
  650. if(! this->Target->GetMakefile()->IsSet("CMAKE_STRIP"))
  651. {
  652. return;
  653. }
  654. os << indent << "IF(CMAKE_INSTALL_DO_STRIP)\n";
  655. os << indent << " EXECUTE_PROCESS(COMMAND \""
  656. << this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
  657. << "\" \"" << toDestDirPath << "\")\n";
  658. os << indent << "ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
  659. }
  660. //----------------------------------------------------------------------------
  661. void
  662. cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
  663. Indent const& indent,
  664. const std::string& toDestDirPath)
  665. {
  666. // Static libraries need ranlib on this platform.
  667. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  668. {
  669. return;
  670. }
  671. // Perform post-installation processing on the file depending
  672. // on its type.
  673. if(!this->Target->GetMakefile()->IsOn("APPLE"))
  674. {
  675. return;
  676. }
  677. std::string ranlib =
  678. this->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB");
  679. if(ranlib.empty())
  680. {
  681. return;
  682. }
  683. os << indent << "EXECUTE_PROCESS(COMMAND \""
  684. << ranlib << "\" \"" << toDestDirPath << "\")\n";
  685. }