diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-05-25 20:18:49 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2021-05-31 12:41:44 (GMT) |
commit | 60e752ced8e9b604591082ee3b21d545fafa8ad8 (patch) | |
tree | 86495c940f685d6c777488ffc97aa9c2d93b83ee /Source/cmInstallTargetGenerator.cxx | |
parent | dd6fd62615ef816f5cbdbd8cd5f827a5cc360464 (diff) | |
download | CMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.zip CMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.tar.gz CMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.tar.bz2 |
Refactor: Move common methods into cmInstallGenerator
Diffstat (limited to 'Source/cmInstallTargetGenerator.cxx')
-rw-r--r-- | Source/cmInstallTargetGenerator.cxx | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 3e79ad8..35165cf 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -77,12 +77,15 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( } // Tweak files located in the destination directory. - std::string toDir = cmStrCat(this->ConvertToAbsoluteDestination(dest), '/'); + std::string toDir = cmStrCat(ConvertToAbsoluteDestination(dest), '/'); // Add pre-installation tweaks. if (!files.NoTweak) { - this->AddTweak(os, indent, config, toDir, files.To, - &cmInstallTargetGenerator::PreReplacementTweaks); + AddTweak(os, indent, config, toDir, files.To, + [this](std::ostream& o, Indent i, const std::string& c, + const std::string& f) { + this->PreReplacementTweaks(o, i, c, f); + }); } // Write code to install the target file. @@ -102,8 +105,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( // Add post-installation tweaks. if (!files.NoTweak) { - this->AddTweak(os, indent, config, toDir, files.To, - &cmInstallTargetGenerator::PostReplacementTweaks); + AddTweak(os, indent, config, toDir, files.To, + [this](std::ostream& o, Indent i, const std::string& c, + const std::string& f) { + this->PostReplacementTweaks(o, i, c, f); + }); } } @@ -461,63 +467,6 @@ bool cmInstallTargetGenerator::Compute(cmLocalGenerator* lg) return true; } -void cmInstallTargetGenerator::AddTweak(std::ostream& os, Indent indent, - const std::string& config, - std::string const& file, - TweakMethod tweak) -{ - std::ostringstream tw; - (this->*tweak)(tw, indent.Next(), config, file); - std::string tws = tw.str(); - if (!tws.empty()) { - os << indent << "if(EXISTS \"" << file << "\" AND\n" - << indent << " NOT IS_SYMLINK \"" << file << "\")\n"; - os << tws; - os << indent << "endif()\n"; - } -} - -void cmInstallTargetGenerator::AddTweak(std::ostream& os, Indent indent, - const std::string& config, - std::string const& dir, - std::vector<std::string> const& files, - TweakMethod tweak) -{ - if (files.size() == 1) { - // Tweak a single file. - this->AddTweak(os, indent, config, - this->GetDestDirPath(cmStrCat(dir, files[0])), tweak); - } else { - // Generate a foreach loop to tweak multiple files. - std::ostringstream tw; - this->AddTweak(tw, indent.Next(), config, "${file}", tweak); - std::string tws = tw.str(); - if (!tws.empty()) { - Indent indent2 = indent.Next().Next(); - os << indent << "foreach(file\n"; - for (std::string const& f : files) { - os << indent2 << "\"" << this->GetDestDirPath(cmStrCat(dir, f)) - << "\"\n"; - } - os << indent2 << ")\n"; - os << tws; - os << indent << "endforeach()\n"; - } - } -} - -std::string cmInstallTargetGenerator::GetDestDirPath(std::string const& file) -{ - // Construct the path of the file on disk after installation on - // which tweaks may be performed. - std::string toDestDirPath = "$ENV{DESTDIR}"; - if (file[0] != '/' && file[0] != '$') { - toDestDirPath += "/"; - } - toDestDirPath += file; - return toDestDirPath; -} - void cmInstallTargetGenerator::PreReplacementTweaks(std::ostream& os, Indent indent, const std::string& config, |