Browse Source

ENH: Add support for stipping and make more things overwritable

Andy Cedilnik 19 years ago
parent
commit
2324e7ec5d

+ 1 - 0
CMakeLists.txt

@@ -269,6 +269,7 @@ IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
     SET(CPACK_NSIS_CONTACT "[email protected]")
     SET(CPACK_NSIS_MODIFY_PATH ON)
   ELSE(WIN32 AND NOT UNIX)
+    SET(CPACK_STRIP_FILES "bin/ccmake;bin/cmake;bin/cpack;bin/ctest")
     SET(CPACK_PACKAGE_EXECUTABLES "ccmake" "CMake")
   ENDIF(WIN32 AND NOT UNIX)
   INCLUDE(CPack)

+ 54 - 9
Source/CPack/cmCPackGenericGenerator.cxx

@@ -68,15 +68,15 @@ int cmCPackGenericGenerator::PrepareNames()
   std::string outFile = topDirectory + "/" + outName;
   std::string installPrefix = tempDirectory + this->GetInstallPrefix();
 
-  this->SetOption("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
-  this->SetOption("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
-  this->SetOption("CPACK_OUTPUT_FILE_NAME", outName.c_str());
-  this->SetOption("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
-  this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str());
-  this->SetOption("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
-  this->SetOption("CPACK_NATIVE_INSTALL_DIRECTORY",
+  this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
+  this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
+  this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
+  this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
+  this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str());
+  this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
+  this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
     cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
-  this->SetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str());
+  this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str());
 
   cmCPackLogger(cmCPackLog::LOG_DEBUG,
     "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
@@ -108,7 +108,7 @@ int cmCPackGenericGenerator::PrepareNames()
       {
       ostr << cmSystemTools::MakeXMLSafe(line.c_str()) << std::endl;
       }
-    this->SetOption("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
+    this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
     }
   if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
     {
@@ -119,6 +119,13 @@ int cmCPackGenericGenerator::PrepareNames()
     return 0;
     }
 
+  std::vector<std::string> path;
+  std::string pkgPath = cmSystemTools::FindProgram("strip", path, false);
+  if ( !pkgPath.empty() )
+    {
+    this->SetOptionIfNotSet("CPACK_STRIP_COMMAND", pkgPath.c_str());
+    }
+
   return 1;
 }
 
@@ -432,6 +439,44 @@ int cmCPackGenericGenerator::InstallProject()
     {
     cmSystemTools::PutEnv("DESTDIR=");
     }
+
+  const char* stripExecutable = this->GetOption("CPACK_STRIP_COMMAND");
+  const char* stripFiles
+    = this->GetOption("CPACK_STRIP_FILES");
+  if ( stripFiles && *stripFiles && stripExecutable && *stripExecutable )
+    {
+    cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Strip files" << std::endl);
+    std::vector<std::string> stripFilesVector;
+    cmSystemTools::ExpandListArgument(stripFiles,
+      stripFilesVector);
+    std::vector<std::string>::iterator it;
+    for ( it = stripFilesVector.begin();
+      it != stripFilesVector.end();
+      ++it )
+      {
+      std::string fileName = tempInstallDirectory;
+      fileName += "/" + *it;
+      cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+        "    Strip file: " << fileName.c_str()
+        << std::endl);
+      std::string stripCommand = stripExecutable;
+      stripCommand += " \"";
+      stripCommand += fileName + "\"";
+      int retVal = 1;
+      std::string output;
+      bool resB = cmSystemTools::RunSingleCommand(stripCommand.c_str(), &output,
+        &retVal, 0, this->GeneratorVerbose, 0);
+      if ( !resB || retVal )
+        {
+        cmCPackLogger(cmCPackLog::LOG_ERROR,
+          "Problem running install command: " << stripCommand.c_str()
+          << std::endl
+          << "Error was: \"" << output.c_str() << "\""
+          << std::endl);
+        return 0;
+        }
+      }
+    }
   return res;
 }
 

+ 5 - 5
Source/CPack/cmCPackNSISGenerator.cxx

@@ -78,7 +78,7 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName,
     }
   cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: "
     << str.str().c_str() << std::endl);
-  this->SetOption("CPACK_NSIS_DELETE_FILES", str.str().c_str());
+  this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str());
   std::vector<std::string> dirs;
   this->GetListOfSubdirectories(toplevel, dirs);
   std::vector<std::string>::const_iterator sit;
@@ -96,7 +96,7 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName,
     }
   cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: "
     << dstr.str().c_str() << std::endl);
-  this->SetOption("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str());
+  this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str());
 
   cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName
     << " to " << nsisFileName << std::endl);
@@ -193,7 +193,7 @@ int cmCPackNSISGenerator::InitializeInternal()
     return 0;
     }
 
-  this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
+  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
   const char* cpackPackageExecutables
     = this->GetOption("CPACK_PACKAGE_EXECUTABLES");
   if ( cpackPackageExecutables )
@@ -226,8 +226,8 @@ int cmCPackNSISGenerator::InitializeInternal()
       deleteStr << "  Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
         << ".lnk\"" << std::endl;
       }
-    this->SetOption("CPACK_NSIS_CREATE_ICONS", str.str().c_str());
-    this->SetOption("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str());
+    this->SetOptionIfNotSet("CPACK_NSIS_CREATE_ICONS", str.str().c_str());
+    this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str());
     }
 
   return this->Superclass::InitializeInternal();

+ 2 - 2
Source/CPack/cmCPackPackageMakerGenerator.cxx

@@ -213,7 +213,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
       << std::endl);
     return 0;
     }
-  this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
+  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
   pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
   if ( pkgPath.empty() )
     {
@@ -221,7 +221,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
       << std::endl);
     return 0;
     }
-  this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
+  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
 
   return this->Superclass::InitializeInternal();
 }

+ 1 - 1
Source/CPack/cmCPackSTGZGenerator.cxx

@@ -51,7 +51,7 @@ int cmCPackSTGZGenerator::InitializeInternal()
     return 0;
     }
   this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
-  this->SetOption("CPACK_AT_SIGN", "@");
+  this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
 
   return this->Superclass::InitializeInternal();
 }

+ 1 - 1
Source/CPack/cmCPackZIPGenerator.cxx

@@ -79,7 +79,7 @@ int cmCPackZIPGenerator::InitializeInternal()
       << std::endl);
     return 0;
     }
-  this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
+  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
   cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
     << pkgPath.c_str()
     << std::endl);