cmInstallTargetGenerator.cxx 24 KB

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