cmInstallTargetGenerator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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;
  184. from1 = cmSystemTools::GetFilenamePath(from1);
  185. // Tweaks apply to the binary inside the bundle.
  186. std::string to1 = toDir + targetNameReal;
  187. filesFrom.push_back(from1);
  188. filesTo.push_back(to1);
  189. }
  190. else
  191. {
  192. bool haveNamelink = false;
  193. // Library link name.
  194. std::string fromName = fromDirConfig + targetName;
  195. std::string toName = toDir + targetName;
  196. // Library interface name.
  197. std::string fromSOName;
  198. std::string toSOName;
  199. if(targetNameSO != targetName)
  200. {
  201. haveNamelink = true;
  202. fromSOName = fromDirConfig + targetNameSO;
  203. toSOName = toDir + targetNameSO;
  204. }
  205. // Library implementation name.
  206. std::string fromRealName;
  207. std::string toRealName;
  208. if(targetNameReal != targetName &&
  209. targetNameReal != targetNameSO)
  210. {
  211. haveNamelink = true;
  212. fromRealName = fromDirConfig + targetNameReal;
  213. toRealName = toDir + targetNameReal;
  214. }
  215. // Add the names based on the current namelink mode.
  216. if(haveNamelink)
  217. {
  218. // With a namelink we need to check the mode.
  219. if(this->NamelinkMode == NamelinkModeOnly)
  220. {
  221. // Install the namelink only.
  222. filesFrom.push_back(fromName);
  223. filesTo.push_back(toName);
  224. }
  225. else
  226. {
  227. // Install the real file if it has its own name.
  228. if(!fromRealName.empty())
  229. {
  230. filesFrom.push_back(fromRealName);
  231. filesTo.push_back(toRealName);
  232. }
  233. // Install the soname link if it has its own name.
  234. if(!fromSOName.empty())
  235. {
  236. filesFrom.push_back(fromSOName);
  237. filesTo.push_back(toSOName);
  238. }
  239. // Install the namelink if it is not to be skipped.
  240. if(this->NamelinkMode != NamelinkModeSkip)
  241. {
  242. filesFrom.push_back(fromName);
  243. filesTo.push_back(toName);
  244. }
  245. }
  246. }
  247. else
  248. {
  249. // Without a namelink there will be only one file. Install it
  250. // if this is not a namelink-only rule.
  251. if(this->NamelinkMode != NamelinkModeOnly)
  252. {
  253. filesFrom.push_back(fromName);
  254. filesTo.push_back(toName);
  255. }
  256. }
  257. }
  258. }
  259. // If this fails the above code is buggy.
  260. assert(filesFrom.size() == filesTo.size());
  261. // Skip this rule if no files are to be installed for the target.
  262. if(filesFrom.empty())
  263. {
  264. return;
  265. }
  266. // Add pre-installation tweaks.
  267. this->AddTweak(os, indent, config, filesTo,
  268. &cmInstallTargetGenerator::PreReplacementTweaks);
  269. // Write code to install the target file.
  270. const char* no_dir_permissions = 0;
  271. const char* no_rename = 0;
  272. bool optional = this->Optional || this->ImportLibrary;
  273. this->AddInstallRule(os, type, filesFrom,
  274. optional,
  275. this->FilePermissions.c_str(), no_dir_permissions,
  276. no_rename, literal_args.c_str(),
  277. indent);
  278. // Add post-installation tweaks.
  279. this->AddTweak(os, indent, config, filesTo,
  280. &cmInstallTargetGenerator::PostReplacementTweaks);
  281. }
  282. //----------------------------------------------------------------------------
  283. std::string
  284. cmInstallTargetGenerator::GetInstallFilename(const char* config) const
  285. {
  286. NameType nameType = this->ImportLibrary? NameImplib : NameNormal;
  287. return
  288. cmInstallTargetGenerator::GetInstallFilename(this->Target, config,
  289. nameType);
  290. }
  291. //----------------------------------------------------------------------------
  292. std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target,
  293. const char* config,
  294. NameType nameType)
  295. {
  296. std::string fname;
  297. // Compute the name of the library.
  298. if(target->GetType() == cmTarget::EXECUTABLE)
  299. {
  300. std::string targetName;
  301. std::string targetNameReal;
  302. std::string targetNameImport;
  303. std::string targetNamePDB;
  304. target->GetExecutableNames(targetName, targetNameReal,
  305. targetNameImport, targetNamePDB,
  306. config);
  307. if(nameType == NameImplib)
  308. {
  309. // Use the import library name.
  310. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  311. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  312. {
  313. fname = targetNameImport;
  314. }
  315. }
  316. else if(nameType == NameReal)
  317. {
  318. // Use the canonical name.
  319. fname = targetNameReal;
  320. }
  321. else
  322. {
  323. // Use the canonical name.
  324. fname = targetName;
  325. }
  326. }
  327. else
  328. {
  329. std::string targetName;
  330. std::string targetNameSO;
  331. std::string targetNameReal;
  332. std::string targetNameImport;
  333. std::string targetNamePDB;
  334. target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
  335. targetNameImport, targetNamePDB, config);
  336. if(nameType == NameImplib)
  337. {
  338. // Use the import library name.
  339. if(!target->GetImplibGNUtoMS(targetNameImport, fname,
  340. "${CMAKE_IMPORT_LIBRARY_SUFFIX}"))
  341. {
  342. fname = targetNameImport;
  343. }
  344. }
  345. else if(nameType == NameSO)
  346. {
  347. // Use the soname.
  348. fname = targetNameSO;
  349. }
  350. else if(nameType == NameReal)
  351. {
  352. // Use the real name.
  353. fname = targetNameReal;
  354. }
  355. else
  356. {
  357. // Use the canonical name.
  358. fname = targetName;
  359. }
  360. }
  361. return fname;
  362. }
  363. //----------------------------------------------------------------------------
  364. void
  365. cmInstallTargetGenerator
  366. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  367. std::string const& file, TweakMethod tweak)
  368. {
  369. cmOStringStream tw;
  370. (this->*tweak)(tw, indent.Next(), config, file);
  371. std::string tws = tw.str();
  372. if(!tws.empty())
  373. {
  374. os << indent << "IF(EXISTS \"" << file << "\" AND\n"
  375. << indent << " NOT IS_SYMLINK \"" << file << "\")\n";
  376. os << tws;
  377. os << indent << "ENDIF()\n";
  378. }
  379. }
  380. //----------------------------------------------------------------------------
  381. void
  382. cmInstallTargetGenerator
  383. ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
  384. std::vector<std::string> const& files, TweakMethod tweak)
  385. {
  386. if(files.size() == 1)
  387. {
  388. // Tweak a single file.
  389. this->AddTweak(os, indent, config, this->GetDestDirPath(files[0]), tweak);
  390. }
  391. else
  392. {
  393. // Generate a foreach loop to tweak multiple files.
  394. cmOStringStream tw;
  395. this->AddTweak(tw, indent.Next(), config, "${file}", tweak);
  396. std::string tws = tw.str();
  397. if(!tws.empty())
  398. {
  399. Indent indent2 = indent.Next().Next();
  400. os << indent << "FOREACH(file\n";
  401. for(std::vector<std::string>::const_iterator i = files.begin();
  402. i != files.end(); ++i)
  403. {
  404. os << indent2 << "\"" << this->GetDestDirPath(*i) << "\"\n";
  405. }
  406. os << indent2 << ")\n";
  407. os << tws;
  408. os << indent << "ENDFOREACH()\n";
  409. }
  410. }
  411. }
  412. //----------------------------------------------------------------------------
  413. std::string cmInstallTargetGenerator::GetDestDirPath(std::string const& file)
  414. {
  415. // Construct the path of the file on disk after installation on
  416. // which tweaks may be performed.
  417. std::string toDestDirPath = "$ENV{DESTDIR}";
  418. if(file[0] != '/' && file[0] != '$')
  419. {
  420. toDestDirPath += "/";
  421. }
  422. toDestDirPath += file;
  423. return toDestDirPath;
  424. }
  425. //----------------------------------------------------------------------------
  426. void cmInstallTargetGenerator::PreReplacementTweaks(std::ostream& os,
  427. Indent const& indent,
  428. const char* config,
  429. std::string const& file)
  430. {
  431. this->AddRPathCheckRule(os, indent, config, file);
  432. }
  433. //----------------------------------------------------------------------------
  434. void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
  435. Indent const& indent,
  436. const char* config,
  437. std::string const& file)
  438. {
  439. this->AddInstallNamePatchRule(os, indent, config, file);
  440. this->AddChrpathPatchRule(os, indent, config, file);
  441. this->AddRanlibRule(os, indent, file);
  442. this->AddStripRule(os, indent, file);
  443. }
  444. //----------------------------------------------------------------------------
  445. void
  446. cmInstallTargetGenerator
  447. ::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
  448. const char* config, std::string const& toDestDirPath)
  449. {
  450. if(this->ImportLibrary ||
  451. !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  452. this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
  453. this->Target->GetType() == cmTarget::EXECUTABLE))
  454. {
  455. return;
  456. }
  457. // Fix the install_name settings in installed binaries.
  458. std::string installNameTool =
  459. this->Target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
  460. if(!installNameTool.size())
  461. {
  462. return;
  463. }
  464. // Build a map of build-tree install_name to install-tree install_name for
  465. // shared libraries linked to this target.
  466. std::map<cmStdString, cmStdString> install_name_remap;
  467. if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config))
  468. {
  469. std::set<cmTarget*> const& sharedLibs = cli->GetSharedLibrariesLinked();
  470. for(std::set<cmTarget*>::const_iterator j = sharedLibs.begin();
  471. j != sharedLibs.end(); ++j)
  472. {
  473. cmTarget* tgt = *j;
  474. // The install_name of an imported target does not change.
  475. if(tgt->IsImported())
  476. {
  477. continue;
  478. }
  479. // If the build tree and install tree use different path
  480. // components of the install_name field then we need to create a
  481. // mapping to be applied after installation.
  482. std::string for_build = tgt->GetInstallNameDirForBuildTree(config);
  483. std::string for_install = tgt->GetInstallNameDirForInstallTree();
  484. if(for_build != for_install)
  485. {
  486. // The directory portions differ. Append the filename to
  487. // create the mapping.
  488. std::string fname =
  489. this->GetInstallFilename(tgt, config, NameSO);
  490. // Map from the build-tree install_name.
  491. for_build += fname;
  492. // Map to the install-tree install_name.
  493. for_install += fname;
  494. // Store the mapping entry.
  495. install_name_remap[for_build] = for_install;
  496. }
  497. }
  498. }
  499. // Edit the install_name of the target itself if necessary.
  500. std::string new_id;
  501. if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
  502. {
  503. std::string for_build =
  504. this->Target->GetInstallNameDirForBuildTree(config);
  505. std::string for_install =
  506. this->Target->GetInstallNameDirForInstallTree();
  507. if(this->Target->IsFrameworkOnApple() && for_install.empty())
  508. {
  509. // Frameworks seem to have an id corresponding to their own full
  510. // path.
  511. // ...
  512. // for_install = fullDestPath_without_DESTDIR_or_name;
  513. }
  514. // If the install name will change on installation set the new id
  515. // on the installed file.
  516. if(for_build != for_install)
  517. {
  518. // Prepare to refer to the install-tree install_name.
  519. new_id = for_install;
  520. new_id += this->GetInstallFilename(this->Target, config, NameSO);
  521. }
  522. }
  523. // Write a rule to run install_name_tool to set the install-tree
  524. // install_name value and references.
  525. if(!new_id.empty() || !install_name_remap.empty())
  526. {
  527. os << indent << "EXECUTE_PROCESS(COMMAND \"" << installNameTool;
  528. os << "\"";
  529. if(!new_id.empty())
  530. {
  531. os << "\n" << indent << " -id \"" << new_id << "\"";
  532. }
  533. for(std::map<cmStdString, cmStdString>::const_iterator
  534. i = install_name_remap.begin();
  535. i != install_name_remap.end(); ++i)
  536. {
  537. os << "\n" << indent << " -change \""
  538. << i->first << "\" \"" << i->second << "\"";
  539. }
  540. os << "\n" << indent << " \"" << toDestDirPath << "\")\n";
  541. }
  542. }
  543. //----------------------------------------------------------------------------
  544. void
  545. cmInstallTargetGenerator
  546. ::AddRPathCheckRule(std::ostream& os, Indent const& indent,
  547. const char* config, std::string const& toDestDirPath)
  548. {
  549. // Skip the chrpath if the target does not need it.
  550. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  551. {
  552. return;
  553. }
  554. // Skip if on Apple
  555. if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  556. {
  557. return;
  558. }
  559. // Get the link information for this target.
  560. // It can provide the RPATH.
  561. cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
  562. if(!cli)
  563. {
  564. return;
  565. }
  566. // Get the install RPATH from the link information.
  567. std::string newRpath = cli->GetChrpathString();
  568. // Write a rule to remove the installed file if its rpath is not the
  569. // new rpath. This is needed for existing build/install trees when
  570. // the installed rpath changes but the file is not rebuilt.
  571. os << indent << "FILE(RPATH_CHECK\n"
  572. << indent << " FILE \"" << toDestDirPath << "\"\n"
  573. << indent << " RPATH \"" << newRpath << "\")\n";
  574. }
  575. //----------------------------------------------------------------------------
  576. void
  577. cmInstallTargetGenerator
  578. ::AddChrpathPatchRule(std::ostream& os, Indent const& indent,
  579. const char* config, std::string const& toDestDirPath)
  580. {
  581. // Skip the chrpath if the target does not need it.
  582. if(this->ImportLibrary || !this->Target->IsChrpathUsed(config))
  583. {
  584. return;
  585. }
  586. // Get the link information for this target.
  587. // It can provide the RPATH.
  588. cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
  589. if(!cli)
  590. {
  591. return;
  592. }
  593. if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  594. {
  595. // If using install_name_tool, set up the rules to modify the rpaths.
  596. std::string installNameTool =
  597. this->Target->GetMakefile()->
  598. GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
  599. std::vector<std::string> oldRuntimeDirs, newRuntimeDirs;
  600. cli->GetRPath(oldRuntimeDirs, false);
  601. cli->GetRPath(newRuntimeDirs, true);
  602. // Note: These are separate commands to avoid install_name_tool
  603. // corruption on 10.6.
  604. for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin();
  605. i != oldRuntimeDirs.end(); ++i)
  606. {
  607. os << indent << "execute_process(COMMAND " << installNameTool << "\n";
  608. os << indent << " -delete_rpath \"" << *i << "\"\n";
  609. os << indent << " \"" << toDestDirPath << "\")\n";
  610. }
  611. for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
  612. i != newRuntimeDirs.end(); ++i)
  613. {
  614. os << indent << "execute_process(COMMAND " << installNameTool << "\n";
  615. os << indent << " -add_rpath \"" << *i << "\"\n";
  616. os << indent << " \"" << toDestDirPath << "\")\n";
  617. }
  618. }
  619. else
  620. {
  621. // Construct the original rpath string to be replaced.
  622. std::string oldRpath = cli->GetRPathString(false);
  623. // Get the install RPATH from the link information.
  624. std::string newRpath = cli->GetChrpathString();
  625. // Skip the rule if the paths are identical
  626. if(oldRpath == newRpath)
  627. {
  628. return;
  629. }
  630. // Write a rule to run chrpath to set the install-tree RPATH
  631. if(newRpath.empty())
  632. {
  633. os << indent << "FILE(RPATH_REMOVE\n"
  634. << indent << " FILE \"" << toDestDirPath << "\")\n";
  635. }
  636. else
  637. {
  638. os << indent << "FILE(RPATH_CHANGE\n"
  639. << indent << " FILE \"" << toDestDirPath << "\"\n"
  640. << indent << " OLD_RPATH \"" << oldRpath << "\"\n"
  641. << indent << " NEW_RPATH \"" << newRpath << "\")\n";
  642. }
  643. }
  644. }
  645. //----------------------------------------------------------------------------
  646. void
  647. cmInstallTargetGenerator::AddStripRule(std::ostream& os,
  648. Indent const& indent,
  649. const std::string& toDestDirPath)
  650. {
  651. // don't strip static and import libraries, because it removes the only
  652. // symbol table they have so you can't link to them anymore
  653. if(this->Target->GetType()==cmTarget::STATIC_LIBRARY || this->ImportLibrary)
  654. {
  655. return;
  656. }
  657. // Don't handle OSX Bundles.
  658. if(this->Target->GetMakefile()->IsOn("APPLE") &&
  659. this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
  660. {
  661. return;
  662. }
  663. if(! this->Target->GetMakefile()->IsSet("CMAKE_STRIP"))
  664. {
  665. return;
  666. }
  667. os << indent << "IF(CMAKE_INSTALL_DO_STRIP)\n";
  668. os << indent << " EXECUTE_PROCESS(COMMAND \""
  669. << this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
  670. << "\" \"" << toDestDirPath << "\")\n";
  671. os << indent << "ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
  672. }
  673. //----------------------------------------------------------------------------
  674. void
  675. cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
  676. Indent const& indent,
  677. const std::string& toDestDirPath)
  678. {
  679. // Static libraries need ranlib on this platform.
  680. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  681. {
  682. return;
  683. }
  684. // Perform post-installation processing on the file depending
  685. // on its type.
  686. if(!this->Target->GetMakefile()->IsOn("APPLE"))
  687. {
  688. return;
  689. }
  690. std::string ranlib =
  691. this->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB");
  692. if(ranlib.empty())
  693. {
  694. return;
  695. }
  696. os << indent << "EXECUTE_PROCESS(COMMAND \""
  697. << ranlib << "\" \"" << toDestDirPath << "\")\n";
  698. }