[Cmake-commits] [cmake-commits] king committed cmInstallTargetGenerator.cxx 1.74 1.75 cmInstallTargetGenerator.h 1.32 1.33

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Oct 21 13:11:44 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv13315/Source

Modified Files:
	cmInstallTargetGenerator.cxx cmInstallTargetGenerator.h 
Log Message:
Tweak all files during target installation

During installation of a target we generate "tweak" rules to update the
installed file (RPATH, strip, ranlib, etc.).  However, some targets
install multiple files, such as the versioned names of a shared library.

Previously the extra files for a target have always been symbolic links,
but for cross-compiling from Windows to UNIX they may need to be copies.
This commit teaches the generated install scripts to loop over all files
installed for the target to apply tweaks to those that are not symlinks.

See issue #9171.


Index: cmInstallTargetGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C 2 -d -r1.32 -r1.33
*** cmInstallTargetGenerator.h	21 Oct 2009 17:09:55 -0000	1.32
--- cmInstallTargetGenerator.h	21 Oct 2009 17:11:42 -0000	1.33
***************
*** 64,67 ****
--- 64,81 ----
                                         const char* config,
                                         Indent const& indent);
+   typedef void (cmInstallTargetGenerator::*TweakMethod)(
+     std::ostream&, Indent const&, const char*, std::string const&
+     );
+   void AddTweak(std::ostream& os, Indent const& indent,
+                 const char* config, std::string const& file,
+                 TweakMethod tweak);
+   void AddTweak(std::ostream& os, Indent const& indent,
+                 const char* config, std::vector<std::string> const& files,
+                 TweakMethod tweak);
+   std::string GetDestDirPath(std::string const& file);
+   void PreReplacementTweaks(std::ostream& os, Indent const& indent,
+                             const char* config, std::string const& file);
+   void PostReplacementTweaks(std::ostream& os, Indent const& indent,
+                              const char* config, std::string const& file);
    void AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
                                 const char* config,

Index: cmInstallTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.cxx,v
retrieving revision 1.74
retrieving revision 1.75
diff -C 2 -d -r1.74 -r1.75
*** cmInstallTargetGenerator.cxx	21 Oct 2009 17:10:51 -0000	1.74
--- cmInstallTargetGenerator.cxx	21 Oct 2009 17:11:42 -0000	1.75
***************
*** 79,86 ****
    toDir += "/";
  
-   // Track whether post-install operations should be added to the
-   // script.
-   bool tweakInstalledFile = true;
- 
    // Compute the list of files to install for this target.
    std::vector<std::string> filesFrom;
--- 79,82 ----
***************
*** 224,228 ****
            filesFrom.push_back(fromName);
            filesTo.push_back(toName);
-           tweakInstalledFile = false;
            }
          else
--- 220,223 ----
***************
*** 272,301 ****
      }
  
-   // Construct the path of the file on disk after installation on
-   // which tweaks may be performed.
-   std::string const& toInstallPath = filesTo[0];
-   std::string toDestDirPath = "$ENV{DESTDIR}";
-   if(toInstallPath[0] != '/' && toInstallPath[0] != '$')
-     {
-     toDestDirPath += "/";
-     }
-   toDestDirPath += toInstallPath;
- 
    // Add pre-installation tweaks.
!   if(tweakInstalledFile)
!     {
!     // Collect tweaking rules.
!     cmOStringStream tw;
!     this->AddRPathCheckRule(tw, indent.Next(), config, toDestDirPath);
!     std::string tws = tw.str();
! 
!     // Add the rules, if any.
!     if(!tws.empty())
!       {
!       os << indent << "IF(EXISTS \"" << toDestDirPath << "\")\n";
!       os << tws;
!       os << indent << "ENDIF(EXISTS \"" << toDestDirPath << "\")\n";
!       }
!     }
  
    // Write code to install the target file.
--- 267,273 ----
      }
  
    // Add pre-installation tweaks.
!   this->AddTweak(os, indent, config, filesTo,
!                  &cmInstallTargetGenerator::PreReplacementTweaks);
  
    // Write code to install the target file.
***************
*** 310,331 ****
  
    // Add post-installation tweaks.
!   if(tweakInstalledFile)
!     {
!     // Collect tweaking rules.
!     cmOStringStream tw;
!     this->AddInstallNamePatchRule(tw, indent.Next(), config, toDestDirPath);
!     this->AddChrpathPatchRule(tw, indent.Next(), config, toDestDirPath);
!     this->AddRanlibRule(tw, indent.Next(), toDestDirPath);
!     this->AddStripRule(tw, indent.Next(), toDestDirPath);
!     std::string tws = tw.str();
! 
!     // Add the rules, if any.
!     if(!tws.empty())
!       {
!       os << indent << "IF(EXISTS \"" << toDestDirPath << "\")\n";
!       os << tws;
!       os << indent << "ENDIF(EXISTS \"" << toDestDirPath << "\")\n";
!       }
!     }
  }
  
--- 282,287 ----
  
    // Add post-installation tweaks.
!   this->AddTweak(os, indent, config, filesTo,
!                  &cmInstallTargetGenerator::PostReplacementTweaks);
  }
  
***************
*** 409,412 ****
--- 365,454 ----
  void
  cmInstallTargetGenerator
+ ::AddTweak(std::ostream& os, Indent const& indent, const char* config,
+            std::string const& file, TweakMethod tweak)
+ {
+   cmOStringStream 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 const& indent, const char* config,
+            std::vector<std::string> const& files, TweakMethod tweak)
+ {
+   if(files.size() == 1)
+     {
+     // Tweak a single file.
+     this->AddTweak(os, indent, config, this->GetDestDirPath(files[0]), tweak);
+     }
+   else
+     {
+     // Generate a foreach loop to tweak multiple files.
+     cmOStringStream 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::vector<std::string>::const_iterator i = files.begin();
+           i != files.end(); ++i)
+         {
+         os << indent2 << "\"" << this->GetDestDirPath(*i) << "\"\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 const& indent,
+                                                     const char* config,
+                                                     std::string const& file)
+ {
+   this->AddRPathCheckRule(os, indent, config, file);
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
+                                                      Indent const& indent,
+                                                      const char* config,
+                                                      std::string const& file)
+ {
+   this->AddInstallNamePatchRule(os, indent, config, file);
+   this->AddChrpathPatchRule(os, indent, config, file);
+   this->AddRanlibRule(os, indent, file);
+   this->AddStripRule(os, indent, file);
+ }
+ 
+ //----------------------------------------------------------------------------
+ void
+ cmInstallTargetGenerator
  ::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
                            const char* config, std::string const& toDestDirPath)



More information about the Cmake-commits mailing list