diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e3b8aed..0442788be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -269,6 +269,7 @@ IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") SET(CPACK_NSIS_CONTACT "cmake@cmake.org") 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) diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index 6bf578e32..e3163a494 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/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 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 stripFilesVector; + cmSystemTools::ExpandListArgument(stripFiles, + stripFilesVector); + std::vector::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; } diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 31345f3e8..5f2541ffc 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/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 dirs; this->GetListOfSubdirectories(toplevel, dirs); std::vector::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(); diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 1d6cb3574..dff14139c 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/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(); } diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 944e319fb..5044d3a85 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/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(); } diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index 8297cc400..d8ad47f55 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/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);