cmInstallTargetGenerator.cxx 23 KB

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