cmInstallTargetGenerator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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::INTERFACE_LIBRARY:
  84. // Not reachable. We never create a cmInstallTargetGenerator for
  85. // an INTERFACE_LIBRARY.
  86. assert(!"INTERFACE_LIBRARY targets have no installable outputs.");
  87. break;
  88. case cmTarget::OBJECT_LIBRARY:
  89. case cmTarget::UTILITY:
  90. case cmTarget::GLOBAL_TARGET:
  91. case cmTarget::UNKNOWN_LIBRARY:
  92. this->Target->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
  93. "cmInstallTargetGenerator created with non-installable target.");
  94. return;
  95. }
  96. if(targetType == cmTarget::EXECUTABLE)
  97. {
  98. // There is a bug in cmInstallCommand if this fails.
  99. assert(this->NamelinkMode == NamelinkModeNone);
  100. std::string targetName;
  101. std::string targetNameReal;
  102. std::string targetNameImport;
  103. std::string targetNamePDB;
  104. this->Target->GetExecutableNames(targetName, targetNameReal,
  105. targetNameImport, targetNamePDB,
  106. config);
  107. if(this->ImportLibrary)
  108. {
  109. std::string from1 = fromDirConfig + targetNameImport;
  110. std::string to1 = toDir + targetNameImport;
  111. filesFrom.push_back(from1);
  112. filesTo.push_back(to1);
  113. std::string targetNameImportLib;
  114. if(this->Target->GetImplibGNUtoMS(targetNameImport,
  115. targetNameImportLib))
  116. {
  117. filesFrom.push_back(fromDirConfig + targetNameImportLib);
  118. filesTo.push_back(toDir + targetNameImportLib);
  119. }
  120. // An import library looks like a static library.
  121. type = cmInstallType_STATIC_LIBRARY;
  122. }
  123. else
  124. {
  125. std::string from1 = fromDirConfig + targetName;
  126. std::string to1 = toDir + targetName;
  127. // Handle OSX Bundles.
  128. if(this->Target->IsAppBundleOnApple())
  129. {
  130. // Install the whole app bundle directory.
  131. type = cmInstallType_DIRECTORY;
  132. literal_args += " USE_SOURCE_PERMISSIONS";
  133. from1 += ".app";
  134. // Tweaks apply to the binary inside the bundle.
  135. to1 += ".app/Contents/MacOS/";
  136. to1 += targetName;
  137. }
  138. else
  139. {
  140. // Tweaks apply to the real file, so list it first.
  141. if(targetNameReal != targetName)
  142. {
  143. std::string from2 = fromDirConfig + targetNameReal;
  144. std::string to2 = toDir += targetNameReal;
  145. filesFrom.push_back(from2);
  146. filesTo.push_back(to2);
  147. }
  148. }
  149. filesFrom.push_back(from1);
  150. filesTo.push_back(to1);
  151. }
  152. }
  153. else
  154. {
  155. std::string targetName;
  156. std::string targetNameSO;
  157. std::string targetNameReal;
  158. std::string targetNameImport;
  159. std::string targetNamePDB;
  160. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
  161. targetNameImport, targetNamePDB,
  162. config);
  163. if(this->ImportLibrary)
  164. {
  165. // There is a bug in cmInstallCommand if this fails.
  166. assert(this->NamelinkMode == NamelinkModeNone);
  167. std::string from1 = fromDirConfig + targetNameImport;
  168. std::string to1 = toDir + targetNameImport;
  169. filesFrom.push_back(from1);
  170. filesTo.push_back(to1);
  171. std::string targetNameImportLib;
  172. if(this->Target->GetImplibGNUtoMS(targetNameImport,
  173. targetNameImportLib))
  174. {
  175. filesFrom.push_back(fromDirConfig + targetNameImportLib);
  176. filesTo.push_back(toDir + targetNameImportLib);
  177. }
  178. // An import library looks like a static library.
  179. type = cmInstallType_STATIC_LIBRARY;
  180. }
  181. else if(this->Target->IsFrameworkOnApple())
  182. {
  183. // There is a bug in cmInstallCommand if this fails.
  184. assert(this->NamelinkMode == NamelinkModeNone);
  185. // Install the whole framework directory.
  186. type = cmInstallType_DIRECTORY;
  187. literal_args += " USE_SOURCE_PERMISSIONS";
  188. std::string from1 = fromDirConfig + targetName;
  189. from1 = cmSystemTools::GetFilenamePath(from1);
  190. // Tweaks apply to the binary inside the bundle.
  191. std::string to1 = toDir + targetNameReal;
  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
  298. cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target,
  299. const char* config,
  300. NameType nameType)
  301. {
  302. std::string fname;
  303. // Compute the name of the library.
  304. if(target->GetType() == cmTarget::EXECUTABLE)
  305. {
  306. std::string targetName;
  307. std::string targetNameReal;
  308. std::string targetNameImport;
  309. std::string targetNamePDB;
  310. target->GetExecutableNames(targetName, targetNameReal,
  311. targetNameImport, targetNamePDB,
  312. config);
  313. if(nameType == NameImplib)
  314. {
  315. // Use the import library name.
  316. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  317. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  318. {
  319. fname = targetNameImport;
  320. }
  321. }
  322. else if(nameType == NameReal)
  323. {
  324. // Use the canonical name.
  325. fname = targetNameReal;
  326. }
  327. else
  328. {
  329. // Use the canonical name.
  330. fname = targetName;
  331. }
  332. }
  333. else
  334. {
  335. std::string targetName;
  336. std::string targetNameSO;
  337. std::string targetNameReal;
  338. std::string targetNameImport;
  339. std::string targetNamePDB;
  340. target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
  341. targetNameImport, targetNamePDB, config);
  342. if(nameType == NameImplib)
  343. {
  344. // Use the import library name.
  345. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  346. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  347. {
  348. fname = targetNameImport;
  349. }
  350. }
  351. else if(nameType == NameSO)
  352. {
  353. // Use the soname.
  354. fname = targetNameSO;
  355. }
  356. else if(nameType == NameReal)
  357. {
  358. // Use the real name.
  359. fname = targetNameReal;
  360. }
  361. else
  362. {
  363. // Use the canonical name.
  364. fname = targetName;
  365. }
  366. }
  367. return fname;
  368. }
  369. //----------------------------------------------------------------------------
  370. void
  371. cmInstallTargetGenerator
  372. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  373. std::string const& file, TweakMethod tweak)
  374. {
  375. cmOStringStream tw;
  376. (this->*tweak)(tw, indent.Next(), config, file);
  377. std::string tws = tw.str();
  378. if(!tws.empty())
  379. {
  380. os << indent << "if(EXISTS \"" << file << "\" AND\n"
  381. << indent << " NOT IS_SYMLINK \"" << file << "\")\n";
  382. os << tws;
  383. os << indent << "endif()\n";
  384. }
  385. }
  386. //----------------------------------------------------------------------------
  387. void
  388. cmInstallTargetGenerator
  389. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  390. std::vector<std::string> const& files, TweakMethod tweak)
  391. {
  392. if(files.size() == 1)
  393. {
  394. // Tweak a single file.
  395. this->AddTweak(os, indent, config, this->GetDestDirPath(files[0]), tweak);
  396. }
  397. else
  398. {
  399. // Generate a foreach loop to tweak multiple files.
  400. cmOStringStream tw;
  401. this->AddTweak(tw, indent.Next(), config, "${file}", tweak);
  402. std::string tws = tw.str();
  403. if(!tws.empty())
  404. {
  405. Indent indent2 = indent.Next().Next();
  406. os << indent << "foreach(file\n";
  407. for(std::vector<std::string>::const_iterator i = files.begin();
  408. i != files.end(); ++i)
  409. {
  410. os << indent2 << "\"" << this->GetDestDirPath(*i) << "\"\n";
  411. }
  412. os << indent2 << ")\n";
  413. os << tws;
  414. os << indent << "endforeach()\n";
  415. }
  416. }
  417. }
  418. //----------------------------------------------------------------------------
  419. std::string cmInstallTargetGenerator::GetDestDirPath(std::string const& file)
  420. {
  421. // Construct the path of the file on disk after installation on
  422. // which tweaks may be performed.
  423. std::string toDestDirPath = "$ENV{DESTDIR}";
  424. if(file[0] != '/' && file[0] != '$')
  425. {
  426. toDestDirPath += "/";
  427. }
  428. toDestDirPath += file;
  429. return toDestDirPath;
  430. }
  431. //----------------------------------------------------------------------------
  432. void cmInstallTargetGenerator::PreReplacementTweaks(std::ostream& os,
  433. Indent const& indent,
  434. const char* config,
  435. std::string const& file)
  436. {
  437. this->AddRPathCheckRule(os, indent, config, file);
  438. }
  439. //----------------------------------------------------------------------------
  440. void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
  441. Indent const& indent,
  442. const char* config,
  443. std::string const& file)
  444. {
  445. this->AddInstallNamePatchRule(os, indent, config, file);
  446. this->AddChrpathPatchRule(os, indent, config, file);
  447. this->AddRanlibRule(os, indent, file);
  448. this->AddStripRule(os, indent, file);
  449. }
  450. //----------------------------------------------------------------------------
  451. void
  452. cmInstallTargetGenerator
  453. ::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
  454. const char* config, std::string const& toDestDirPath)
  455. {
  456. if(this->ImportLibrary ||
  457. !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  458. this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
  459. this->Target->GetType() == cmTarget::EXECUTABLE))
  460. {
  461. return;
  462. }
  463. // Fix the install_name settings in installed binaries.
  464. std::string installNameTool =
  465. this->Target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
  466. if(!installNameTool.size())
  467. {
  468. return;
  469. }
  470. // Build a map of build-tree install_name to install-tree install_name for
  471. // shared libraries linked to this target.
  472. std::map<cmStdString, cmStdString> install_name_remap;
  473. if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config))
  474. {
  475. std::set<cmTarget const*> const& sharedLibs
  476. = cli->GetSharedLibrariesLinked();
  477. for(std::set<cmTarget const*>::const_iterator j = sharedLibs.begin();
  478. j != sharedLibs.end(); ++j)
  479. {
  480. cmTarget const* tgt = *j;
  481. // The install_name of an imported target does not change.
  482. if(tgt->IsImported())
  483. {
  484. continue;
  485. }
  486. // If the build tree and install tree use different path
  487. // components of the install_name field then we need to create a
  488. // mapping to be applied after installation.
  489. std::string for_build = tgt->GetInstallNameDirForBuildTree(config);
  490. std::string for_install = tgt->GetInstallNameDirForInstallTree();
  491. if(for_build != for_install)
  492. {
  493. // The directory portions differ. Append the filename to
  494. // create the mapping.
  495. std::string fname =
  496. this->GetInstallFilename(tgt, config, NameSO);
  497. // Map from the build-tree install_name.
  498. for_build += fname;
  499. // Map to the install-tree install_name.
  500. for_install += fname;
  501. // Store the mapping entry.
  502. install_name_remap[for_build] = for_install;
  503. }
  504. }
  505. }
  506. // Edit the install_name of the target itself if necessary.
  507. std::string new_id;
  508. if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
  509. {
  510. std::string for_build =
  511. this->Target->GetInstallNameDirForBuildTree(config);
  512. std::string for_install =
  513. this->Target->GetInstallNameDirForInstallTree();
  514. if(this->Target->IsFrameworkOnApple() && for_install.empty())
  515. {
  516. // Frameworks seem to have an id corresponding to their own full
  517. // path.
  518. // ...
  519. // for_install = fullDestPath_without_DESTDIR_or_name;
  520. }
  521. // If the install name will change on installation set the new id
  522. // on the installed file.
  523. if(for_build != for_install)
  524. {
  525. // Prepare to refer to the install-tree install_name.
  526. new_id = for_install;
  527. new_id += this->GetInstallFilename(this->Target, config, NameSO);
  528. }
  529. }
  530. // Write a rule to run install_name_tool to set the install-tree
  531. // install_name value and references.
  532. if(!new_id.empty() || !install_name_remap.empty())
  533. {
  534. os << indent << "execute_process(COMMAND \"" << installNameTool;
  535. os << "\"";
  536. if(!new_id.empty())
  537. {
  538. os << "\n" << indent << " -id \"" << new_id << "\"";
  539. }
  540. for(std::map<cmStdString, cmStdString>::const_iterator
  541. i = install_name_remap.begin();
  542. i != install_name_remap.end(); ++i)
  543. {
  544. os << "\n" << indent << " -change \""
  545. << i->first << "\" \"" << i->second << "\"";
  546. }
  547. os << "\n" << indent << " \"" << toDestDirPath << "\")\n";
  548. }
  549. }
  550. //----------------------------------------------------------------------------
  551. void
  552. cmInstallTargetGenerator
  553. ::AddRPathCheckRule(std::ostream& os, Indent const& indent,
  554. const char* config, std::string const& toDestDirPath)
  555. {
  556. // Skip the chrpath if the target does not need it.
  557. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  558. {
  559. return;
  560. }
  561. // Skip if on Apple
  562. if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  563. {
  564. return;
  565. }
  566. // Get the link information for this target.
  567. // It can provide the RPATH.
  568. cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
  569. if(!cli)
  570. {
  571. return;
  572. }
  573. // Get the install RPATH from the link information.
  574. std::string newRpath = cli->GetChrpathString();
  575. // Write a rule to remove the installed file if its rpath is not the
  576. // new rpath. This is needed for existing build/install trees when
  577. // the installed rpath changes but the file is not rebuilt.
  578. os << indent << "file(RPATH_CHECK\n"
  579. << indent << " FILE \"" << toDestDirPath << "\"\n"
  580. << indent << " RPATH \"" << newRpath << "\")\n";
  581. }
  582. //----------------------------------------------------------------------------
  583. void
  584. cmInstallTargetGenerator
  585. ::AddChrpathPatchRule(std::ostream& os, Indent const& indent,
  586. const char* config, std::string const& toDestDirPath)
  587. {
  588. // Skip the chrpath if the target does not need it.
  589. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  590. {
  591. return;
  592. }
  593. // Get the link information for this target.
  594. // It can provide the RPATH.
  595. cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
  596. if(!cli)
  597. {
  598. return;
  599. }
  600. if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  601. {
  602. // If using install_name_tool, set up the rules to modify the rpaths.
  603. std::string installNameTool =
  604. this->Target->GetMakefile()->
  605. GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
  606. std::vector<std::string> oldRuntimeDirs, newRuntimeDirs;
  607. cli->GetRPath(oldRuntimeDirs, false);
  608. cli->GetRPath(newRuntimeDirs, true);
  609. // Note: These are separate commands to avoid install_name_tool
  610. // corruption on 10.6.
  611. for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin();
  612. i != oldRuntimeDirs.end(); ++i)
  613. {
  614. os << indent << "execute_process(COMMAND " << installNameTool << "\n";
  615. os << indent << " -delete_rpath \"" << *i << "\"\n";
  616. os << indent << " \"" << toDestDirPath << "\")\n";
  617. }
  618. for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
  619. i != newRuntimeDirs.end(); ++i)
  620. {
  621. os << indent << "execute_process(COMMAND " << installNameTool << "\n";
  622. os << indent << " -add_rpath \"" << *i << "\"\n";
  623. os << indent << " \"" << toDestDirPath << "\")\n";
  624. }
  625. }
  626. else
  627. {
  628. // Construct the original rpath string to be replaced.
  629. std::string oldRpath = cli->GetRPathString(false);
  630. // Get the install RPATH from the link information.
  631. std::string newRpath = cli->GetChrpathString();
  632. // Skip the rule if the paths are identical
  633. if(oldRpath == newRpath)
  634. {
  635. return;
  636. }
  637. // Write a rule to run chrpath to set the install-tree RPATH
  638. if(newRpath.empty())
  639. {
  640. os << indent << "file(RPATH_REMOVE\n"
  641. << indent << " FILE \"" << toDestDirPath << "\")\n";
  642. }
  643. else
  644. {
  645. os << indent << "file(RPATH_CHANGE\n"
  646. << indent << " FILE \"" << toDestDirPath << "\"\n"
  647. << indent << " OLD_RPATH \"" << oldRpath << "\"\n"
  648. << indent << " NEW_RPATH \"" << newRpath << "\")\n";
  649. }
  650. }
  651. }
  652. //----------------------------------------------------------------------------
  653. void
  654. cmInstallTargetGenerator::AddStripRule(std::ostream& os,
  655. Indent const& indent,
  656. const std::string& toDestDirPath)
  657. {
  658. // don't strip static and import libraries, because it removes the only
  659. // symbol table they have so you can't link to them anymore
  660. if(this->Target->GetType()==cmTarget::STATIC_LIBRARY || this->ImportLibrary)
  661. {
  662. return;
  663. }
  664. // Don't handle OSX Bundles.
  665. if(this->Target->GetMakefile()->IsOn("APPLE") &&
  666. this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
  667. {
  668. return;
  669. }
  670. if(! this->Target->GetMakefile()->IsSet("CMAKE_STRIP"))
  671. {
  672. return;
  673. }
  674. os << indent << "if(CMAKE_INSTALL_DO_STRIP)\n";
  675. os << indent << " execute_process(COMMAND \""
  676. << this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
  677. << "\" \"" << toDestDirPath << "\")\n";
  678. os << indent << "endif()\n";
  679. }
  680. //----------------------------------------------------------------------------
  681. void
  682. cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
  683. Indent const& indent,
  684. const std::string& toDestDirPath)
  685. {
  686. // Static libraries need ranlib on this platform.
  687. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  688. {
  689. return;
  690. }
  691. // Perform post-installation processing on the file depending
  692. // on its type.
  693. if(!this->Target->GetMakefile()->IsOn("APPLE"))
  694. {
  695. return;
  696. }
  697. std::string ranlib =
  698. this->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB");
  699. if(ranlib.empty())
  700. {
  701. return;
  702. }
  703. os << indent << "execute_process(COMMAND \""
  704. << ranlib << "\" \"" << toDestDirPath << "\")\n";
  705. }