summaryrefslogtreecommitdiffstats
path: root/Source/CPack
diff options
context:
space:
mode:
authorPetr Orlov <zfmeze@gmail.com>2016-08-31 15:05:15 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-19 14:22:50 (GMT)
commit1c63aa4d43f101a0d58b5b88d3119c72cadf5517 (patch)
tree0c347a5de4650e490bb47183e3d39563b1c42113 /Source/CPack
parent4682b42bdb5a9b7ca9f6ef5f65c019eec4f92a62 (diff)
downloadCMake-1c63aa4d43f101a0d58b5b88d3119c72cadf5517.zip
CMake-1c63aa4d43f101a0d58b5b88d3119c72cadf5517.tar.gz
CMake-1c63aa4d43f101a0d58b5b88d3119c72cadf5517.tar.bz2
CPack: Add option to generate a checksum file next to each package file
Add variable CPACK_PACKAGE_CHECKSUM to activate it.
Diffstat (limited to 'Source/CPack')
-rw-r--r--Source/CPack/cmCPackGenerator.cxx33
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;