summaryrefslogtreecommitdiffstats
path: root/Source/cmInstallGenerator.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2021-05-25 20:18:49 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2021-05-31 12:41:44 (GMT)
commit60e752ced8e9b604591082ee3b21d545fafa8ad8 (patch)
tree86495c940f685d6c777488ffc97aa9c2d93b83ee /Source/cmInstallGenerator.cxx
parentdd6fd62615ef816f5cbdbd8cd5f827a5cc360464 (diff)
downloadCMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.zip
CMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.tar.gz
CMake-60e752ced8e9b604591082ee3b21d545fafa8ad8.tar.bz2
Refactor: Move common methods into cmInstallGenerator
Diffstat (limited to 'Source/cmInstallGenerator.cxx')
-rw-r--r--Source/cmInstallGenerator.cxx63
1 files changed, 60 insertions, 3 deletions
diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx
index cf5f45e..9f0d119 100644
--- a/Source/cmInstallGenerator.cxx
+++ b/Source/cmInstallGenerator.cxx
@@ -2,10 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallGenerator.h"
-#include <ostream>
+#include <sstream>
#include <utility>
#include "cmMakefile.h"
+#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
cmInstallGenerator::cmInstallGenerator(
@@ -98,7 +99,7 @@ void cmInstallGenerator::AddInstallRule(
<< "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
os << indent << "endif()\n";
}
- std::string absDest = this->ConvertToAbsoluteDestination(dest);
+ std::string absDest = ConvertToAbsoluteDestination(dest);
os << "file(INSTALL DESTINATION \"" << absDest << "\" TYPE " << stype;
if (optional) {
os << " OPTIONAL";
@@ -183,7 +184,7 @@ bool cmInstallGenerator::InstallsForConfig(const std::string& config)
}
std::string cmInstallGenerator::ConvertToAbsoluteDestination(
- std::string const& dest) const
+ std::string const& dest)
{
std::string result;
if (!dest.empty() && !cmSystemTools::FileIsFullPath(dest)) {
@@ -211,3 +212,59 @@ cmInstallGenerator::MessageLevel cmInstallGenerator::SelectMessageLevel(
}
return MessageDefault;
}
+
+std::string cmInstallGenerator::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 cmInstallGenerator::AddTweak(std::ostream& os, Indent indent,
+ const std::string& config,
+ std::string const& file,
+ const TweakMethod& tweak)
+{
+ std::ostringstream tw;
+ 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 cmInstallGenerator::AddTweak(std::ostream& os, Indent indent,
+ const std::string& config,
+ std::string const& dir,
+ std::vector<std::string> const& files,
+ const TweakMethod& tweak)
+{
+ if (files.size() == 1) {
+ // Tweak a single file.
+ AddTweak(os, indent, config, GetDestDirPath(cmStrCat(dir, files[0])),
+ tweak);
+ } else {
+ // Generate a foreach loop to tweak multiple files.
+ std::ostringstream tw;
+ 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 << "\"" << GetDestDirPath(cmStrCat(dir, f)) << "\"\n";
+ }
+ os << indent2 << ")\n";
+ os << tws;
+ os << indent << "endforeach()\n";
+ }
+ }
+}