diff options
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/cmCPackGenerator.cxx | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index d6b58f2..e6aba89 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -14,6 +14,7 @@ #include "cmCPackComponentGroup.h" #include "cmCPackLog.h" +#include "cmCryptoHash.h" #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -163,6 +164,14 @@ int cmCPackGenerator::PrepareNames() << std::endl); return 0; } + const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); + if (algoSignature) { + if (cmCryptoHash::New(algoSignature).get() == CM_NULLPTR) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " + << algoSignature << std::endl); + return 0; + } + } this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1"); @@ -980,6 +989,10 @@ int cmCPackGenerator::DoPackage() return 0; } + /* Prepare checksum algorithm*/ + const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); + CM_AUTO_PTR<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); + /* * Copy the generated packages to final destination * - there may be several of them @@ -992,8 +1005,9 @@ int cmCPackGenerator::DoPackage() /* now copy package one by one */ for (it = packageFileNames.begin(); it != packageFileNames.end(); ++it) { std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); + std::string filename(cmSystemTools::GetFilenameName(*it)); tempPackageFileName = it->c_str(); - tmpPF += "/" + cmSystemTools::GetFilenameName(*it); + tmpPF += "/" + filename; const char* packageFileName = tmpPF.c_str(); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): " << (tempPackageFileName ? tempPackageFileName : "(NULL)") @@ -1009,6 +1023,23 @@ int cmCPackGenerator::DoPackage() } cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: " << packageFileName << " generated." << std::endl); + + /* Generate checksum file */ + if (crypto.get() != CM_NULLPTR) { + std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); + hashFile += + "/" + filename.substr(0, filename.rfind(this->GetOutputExtension())); + hashFile += "." + cmSystemTools::LowerCase(algo); + cmsys::ofstream outF(hashFile.c_str()); + if (!outF) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create checksum file: " + << hashFile << std::endl); + return 0; + } + outF << crypto->HashFile(packageFileName) << " " << filename << "\n"; + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- checksum file: " + << hashFile << " generated." << std::endl); + } } return 1; |