summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.cxx18
-rw-r--r--Source/CPack/cmCPackGenerator.cxx41
-rw-r--r--Source/CPack/cmCPackGenerator.h13
-rw-r--r--Source/CPack/cmCPackRPMGenerator.cxx30
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx71
-rw-r--r--Source/cmFileCommand.cxx418
-rw-r--r--Source/cmFileCommand.h15
-rw-r--r--Source/kwsys/kwsysDateStamp.cmake4
8 files changed, 465 insertions, 145 deletions
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index febf205..3c670a1 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -121,9 +121,11 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
<< std::endl);
// Begin the archive for this group
std::string packageFileName= std::string(toplevel);
- packageFileName += "/"
- +std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
- +"-"+compGIt->first + this->GetOutputExtension();
+ packageFileName += "/"+
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compGIt->first,
+ true)
+ + this->GetOutputExtension();
// open a block in order to automatically close archive
// at the end of the block
{
@@ -154,9 +156,11 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
std::string packageFileName = std::string(toplevel);
localToplevel += "/"+ compIt->first;
- packageFileName += "/"
- +std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
- +"-"+compIt->first + this->GetOutputExtension();
+ packageFileName += "/"+
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compIt->first,
+ false)
+ + this->GetOutputExtension();
{
DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive);
// Add the files of this component to the archive
@@ -177,7 +181,7 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne(bool allComponent)
packageFileNames.push_back(std::string(toplevel));
packageFileNames[0] += "/"
+std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
- +"-ALL" + this->GetOutputExtension();
+ + this->GetOutputExtension();
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Packaging all groups in one package..."
"(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE is set)"
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 69d9b8c..86200c1 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -1309,10 +1309,51 @@ int cmCPackGenerator::PrepareGroupingKind()
return 1;
}
+//----------------------------------------------------------------------
std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
const std::string& componentName) {
return componentName;
}
+//----------------------------------------------------------------------
+std::string cmCPackGenerator::GetComponentPackageFileName(
+ const std::string& initialPackageFileName,
+ const std::string& groupOrComponentName,
+ bool isGroupName) {
+
+ /*
+ * the default behavior is to use the
+ * component [group] name as a suffix
+ */
+ std::string suffix="-"+groupOrComponentName;
+ /* check if we should use DISPLAY name */
+ std::string dispNameVar = "CPACK_"+Name+"_USE_DISPLAY_NAME_IN_FILENAME";
+ if (IsOn(dispNameVar.c_str()))
+ {
+ /* the component Group case */
+ if (isGroupName)
+ {
+ std::string groupDispVar = "CPACK_COMPONENT_GROUP_"
+ + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
+ const char* groupDispName = GetOption(groupDispVar.c_str());
+ if (groupDispName)
+ {
+ suffix = "-"+std::string(groupDispName);
+ }
+ }
+ /* the [single] component case */
+ else
+ {
+ std::string dispVar = "CPACK_COMPONENT_"
+ + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
+ const char* dispName = GetOption(dispVar.c_str());
+ if(dispName)
+ {
+ suffix = "-"+std::string(dispName);
+ }
+ }
+ }
+ return initialPackageFileName + suffix;
+}
//----------------------------------------------------------------------
bool cmCPackGenerator::SupportsComponentInstallation() const
diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h
index d4b1b16..0497d1c 100644
--- a/Source/CPack/cmCPackGenerator.h
+++ b/Source/CPack/cmCPackGenerator.h
@@ -145,6 +145,19 @@ protected:
const std::string& componentName);
/**
+ * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME
+ * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if
+ * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON.
+ * @param[in] initialPackageFileName
+ * @param[in] groupOrComponentName
+ * @param[in] isGroupName
+ */
+ virtual std::string GetComponentPackageFileName(
+ const std::string& initialPackageFileName,
+ const std::string& groupOrComponentName,
+ bool isGroupName);
+
+ /**
* Package the list of files and/or components which
* has been prepared by the beginning of DoPackage.
* @pre @ref toplevel has been filled-in
diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx
index 2d675c1..0b0c6b1 100644
--- a/Source/CPack/cmCPackRPMGenerator.cxx
+++ b/Source/CPack/cmCPackRPMGenerator.cxx
@@ -31,6 +31,21 @@ int cmCPackRPMGenerator::InitializeInternal()
{
this->SetOption("CPACK_SET_DESTDIR", "I_ON");
}
+ /* Replace space in CPACK_PACKAGE_NAME in order to avoid
+ * rpmbuild scream on unwanted space in filename issue
+ * Moreover RPM file do not usually embed space in filename
+ */
+ if (this->GetOption("CPACK_PACKAGE_NAME")) {
+ std::string packageName=this->GetOption("CPACK_PACKAGE_NAME");
+ cmSystemTools::ReplaceString(packageName," ","-");
+ this->SetOption("CPACK_PACKAGE_NAME",packageName.c_str());
+ }
+ /* same for CPACK_PACKAGE_FILE_NAME */
+ if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
+ std::string packageName=this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ cmSystemTools::ReplaceString(packageName," ","-");
+ this->SetOption("CPACK_PACKAGE_FILE_NAME",packageName.c_str());
+ }
return this->Superclass::InitializeInternal();
}
@@ -60,8 +75,10 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
cmSystemTools::GetParentDirectory(toplevel.c_str())
);
std::string outputFileName(
- std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
- +"-"+compGIt->first + this->GetOutputExtension()
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compGIt->first,
+ true)
+ + this->GetOutputExtension()
);
localToplevel += "/"+ compGIt->first;
@@ -98,9 +115,10 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
cmSystemTools::GetParentDirectory(toplevel.c_str())
);
std::string outputFileName(
- std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")
- )
- +"-"+compIt->first + this->GetOutputExtension());
+ GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
+ compIt->first,
+ false)
+ + this->GetOutputExtension());
localToplevel += "/"+ compIt->first;
/* replace the TEMP DIRECTORY with the component one */
@@ -158,7 +176,7 @@ int cmCPackRPMGenerator::PackageComponentsAllInOne(bool allComponent)
);
std::string outputFileName(
std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
- +"-ALL"+ this->GetOutputExtension()
+ + this->GetOutputExtension()
);
// all GROUP in one vs all COMPONENT in one
localToplevel += "/"+compInstDirName;
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index eb78647..c4ea425 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -102,7 +102,7 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const
fout <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<projectDescription>\n"
- "\t<name>" << name << "</name>\n"
+ "\t<name>" << this->EscapeForXML(name) << "</name>\n"
"\t<comment></comment>\n"
"\t<projects>\n"
"\t</projects>\n"
@@ -376,11 +376,10 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
"\t</natures>\n"
;
- // TODO: refactor this
+ fout << "\t<linkedResources>\n";
// create linked resources
if (this->IsOutOfSourceBuild)
{
- fout << "\t<linkedResources>\n";
// create a linked resource to CMAKE_SOURCE_DIR
// (this is not done anymore for each project because of
// http://public.kitware.com/Bug/view.php?id=9978 and because I found it
@@ -399,18 +398,48 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
this->SrcLinkedResources.push_back(sourceLinkedResourceName);
}
- // for EXECUTABLE_OUTPUT_PATH when not in binary dir
- this->AppendOutLinkedResource(fout,
- mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY"),
- mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"));
- // for LIBRARY_OUTPUT_PATH when not in binary dir
- this->AppendOutLinkedResource(fout,
- mf->GetSafeDefinition("CMAKE_LIBRARY_OUTPUT_DIRECTORY"),
- mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH"));
+ }
+
+ // for each sub project create a linked resource to the source dir
+ // - only if it is an out-of-source build
+ this->AppendLinkedResource(fout, "[Subprojects]",
+ "virtual:/virtual");
- fout << "\t</linkedResources>\n";
+ for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it != this->GlobalGenerator->GetProjectMap().end();
+ ++it)
+ {
+ std::string linkSourceDirectory = this->GetEclipsePath(
+ it->second[0]->GetMakefile()->GetStartDirectory());
+ // a linked resource must not point to a parent directory of .project or
+ // .project itself
+ if ((this->HomeOutputDirectory != linkSourceDirectory) &&
+ !cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
+ linkSourceDirectory.c_str()))
+ {
+ std::string linkName = "[Subprojects]/";
+ linkName += it->first;
+ this->AppendLinkedResource(fout, linkName,
+ this->GetEclipsePath(linkSourceDirectory));
+ this->SrcLinkedResources.push_back(it->first);
+ }
}
+ // I'm not sure this makes too much sense. There can be different
+ // output directories in different subdirs, so we would need more of them.
+
+ // for EXECUTABLE_OUTPUT_PATH when not in binary dir
+ this->AppendOutLinkedResource(fout,
+ mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY"),
+ mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"));
+ // for LIBRARY_OUTPUT_PATH when not in binary dir
+ this->AppendOutLinkedResource(fout,
+ mf->GetSafeDefinition("CMAKE_LIBRARY_OUTPUT_DIRECTORY"),
+ mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH"));
+
+ fout << "\t</linkedResources>\n";
+
fout << "</projectDescription>\n";
}
@@ -551,14 +580,15 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
it != this->SrcLinkedResources.end();
++it)
{
- fout << "<pathentry kind=\"src\" path=\"" << *it << "\"/>\n";
+ fout << "<pathentry kind=\"src\" path=\"" << this->EscapeForXML(*it)
+ << "\"/>\n";
// exlude source directory from output search path
// - only if not named the same as an output directory
if (!cmSystemTools::FileIsDirectory(
std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
{
- excludeFromOut += *it + "/|";
+ excludeFromOut += this->EscapeForXML(*it) + "/|";
}
}
excludeFromOut += "**/CMakeFiles/";
@@ -573,7 +603,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
it != this->OutLinkedResources.end();
++it)
{
- fout << "<pathentry kind=\"out\" path=\"" << *it << "\"/>\n";
+ fout << "<pathentry kind=\"out\" path=\"" << this->EscapeForXML(*it)
+ << "\"/>\n";
}
// add pre-processor definitions to allow eclipse to gray out sections
@@ -1055,11 +1086,13 @@ void cmExtraEclipseCDT4Generator
{
fout <<
"\t\t<link>\n"
- "\t\t\t<name>" << name << "</name>\n"
+ "\t\t\t<name>"
+ << cmExtraEclipseCDT4Generator::EscapeForXML(name)
+ << "</name>\n"
"\t\t\t<type>2</type>\n"
- "\t\t\t<location>"
- << path
- << "</location>\n"
+ "\t\t\t<locationURI>"
+ << cmExtraEclipseCDT4Generator::EscapeForXML(path)
+ << "</locationURI>\n"
"\t\t</link>\n"
;
}
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 37fced2..a72feb1 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -75,6 +75,10 @@ bool cmFileCommand
{
return this->HandleDownloadCommand(args);
}
+ else if ( subCommand == "UPLOAD" )
+ {
+ return this->HandleUploadCommand(args);
+ }
else if ( subCommand == "READ" )
{
return this->HandleReadCommand(args);
@@ -2432,53 +2436,66 @@ bool cmFileCommand::HandleCMakePathCommand(std::vector<std::string>
this->Makefile->AddDefinition(var, value.c_str());
return true;
}
+
+
#if defined(CMAKE_BUILD_WITH_CMAKE)
-// Stuff for curl download
+// Stuff for curl download/upload
typedef std::vector<char> cmFileCommandVectorOfChar;
-namespace{
+
+namespace {
+
size_t
- cmFileCommandWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
- void *data)
- {
+ cmWriteToFileCallback(void *ptr, size_t size, size_t nmemb,
+ void *data)
+ {
register int realsize = (int)(size * nmemb);
std::ofstream* fout = static_cast<std::ofstream*>(data);
const char* chPtr = static_cast<char*>(ptr);
fout->write(chPtr, realsize);
return realsize;
- }
+ }
+
+
+ size_t
+ cmWriteToMemoryCallback(void *ptr, size_t size, size_t nmemb,
+ void *data)
+ {
+ register int realsize = (int)(size * nmemb);
+ cmFileCommandVectorOfChar *vec
+ = static_cast<cmFileCommandVectorOfChar*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ vec->insert(vec->end(), chPtr, chPtr + realsize);
+ return realsize;
+ }
static size_t
cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
- size_t size, void *data)
- {
+ size_t size, void *data)
+ {
cmFileCommandVectorOfChar *vec
= static_cast<cmFileCommandVectorOfChar*>(data);
vec->insert(vec->end(), chPtr, chPtr + size);
-
return size;
- }
+ }
class cURLProgressHelper
{
public:
- cURLProgressHelper(cmFileCommand *fc)
+ cURLProgressHelper(cmFileCommand *fc, const char *text)
{
this->CurrentPercentage = -1;
this->FileCommand = fc;
+ this->Text = text;
}
bool UpdatePercentage(double value, double total, std::string &status)
{
int OldPercentage = this->CurrentPercentage;
- if (0.0 == total)
- {
- this->CurrentPercentage = 100;
- }
- else
+ if (total > 0.0)
{
this->CurrentPercentage = static_cast<int>(value/total*100.0 + 0.5);
}
@@ -2488,7 +2505,8 @@ namespace{
if (updated)
{
cmOStringStream oss;
- oss << "[download " << this->CurrentPercentage << "% complete]";
+ oss << "[" << this->Text << " " << this->CurrentPercentage
+ << "% complete]";
status = oss.str();
}
@@ -2503,14 +2521,15 @@ namespace{
private:
int CurrentPercentage;
cmFileCommand *FileCommand;
+ std::string Text;
};
static int
- cmFileCommandCurlProgressCallback(void *clientp,
- double dltotal, double dlnow,
- double ultotal, double ulnow)
- {
+ cmFileDownloadProgressCallback(void *clientp,
+ double dltotal, double dlnow,
+ double ultotal, double ulnow)
+ {
cURLProgressHelper *helper =
reinterpret_cast<cURLProgressHelper *>(clientp);
@@ -2526,12 +2545,33 @@ namespace{
}
return 0;
- }
+ }
+
+
+ static int
+ cmFileUploadProgressCallback(void *clientp,
+ double dltotal, double dlnow,
+ double ultotal, double ulnow)
+ {
+ cURLProgressHelper *helper =
+ reinterpret_cast<cURLProgressHelper *>(clientp);
+
+ static_cast<void>(dltotal);
+ static_cast<void>(dlnow);
+
+ std::string status;
+ if (helper->UpdatePercentage(ulnow, ultotal, status))
+ {
+ cmFileCommand *fc = helper->GetFileCommand();
+ cmMakefile *mf = fc->GetMakefile();
+ mf->DisplayStatus(status.c_str(), -1);
+ }
+
+ return 0;
+ }
}
-#endif
-#if defined(CMAKE_BUILD_WITH_CMAKE)
namespace {
class cURLEasyGuard
@@ -2563,9 +2603,18 @@ namespace {
#endif
+#define check_curl_result(result, errstr) \
+ if (result != CURLE_OK) \
+ { \
+ std::string e(errstr); \
+ e += ::curl_easy_strerror(result); \
+ this->SetError(e.c_str()); \
+ return false; \
+ }
+
+
bool
-cmFileCommand::HandleDownloadCommand(std::vector<std::string>
- const& args)
+cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
std::vector<std::string>::const_iterator i = args.begin();
@@ -2704,88 +2753,37 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string>
cURLEasyGuard g_curl(curl);
::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set url: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set url: ");
res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
- cmFileCommandWriteMemoryCallback);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set write function: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ cmWriteToFileCallback);
+ check_curl_result(res, "DOWNLOAD cannot set write function: ");
res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
cmFileCommandCurlDebugCallback);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set debug function: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set debug function: ");
cmFileCommandVectorOfChar chunkDebug;
res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&fout);
-
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set write data: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set write data: ");
res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set debug data: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set debug data: ");
res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set follow-redirect option: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set follow-redirect option: ");
if(verboseLog.size())
{
res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set verbose: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set verbose: ");
}
if(timeout > 0)
{
res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
-
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set timeout: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set timeout: ");
}
// Need the progress helper's scope to last through the duration of
@@ -2793,39 +2791,20 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string>
// scope intentionally, rather than inside the "if(showProgress)"
// block...
//
- cURLProgressHelper helper(this);
+ cURLProgressHelper helper(this, "download");
if(showProgress)
{
- res = ::curl_easy_setopt(curl,
- CURLOPT_NOPROGRESS, 0);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set noprogress value: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ check_curl_result(res, "DOWNLOAD cannot set noprogress value: ");
res = ::curl_easy_setopt(curl,
- CURLOPT_PROGRESSFUNCTION, cmFileCommandCurlProgressCallback);
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set progress function: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ CURLOPT_PROGRESSFUNCTION, cmFileDownloadProgressCallback);
+ check_curl_result(res, "DOWNLOAD cannot set progress function: ");
res = ::curl_easy_setopt(curl,
CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
- if (res != CURLE_OK)
- {
- std::string e = "DOWNLOAD cannot set progress data: ";
- e += ::curl_easy_strerror(res);
- this->SetError(e.c_str());
- return false;
- }
+ check_curl_result(res, "DOWNLOAD cannot set progress data: ");
}
res = ::curl_easy_perform(curl);
@@ -2901,3 +2880,220 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string>
return false;
#endif
}
+
+
+bool
+cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
+{
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ if(args.size() < 3)
+ {
+ this->SetError("UPLOAD must be called with at least three arguments.");
+ return false;
+ }
+ std::vector<std::string>::const_iterator i = args.begin();
+ ++i;
+ std::string filename = *i;
+ ++i;
+ std::string url = *i;
+ ++i;
+
+ long timeout = 0;
+ std::string logVar;
+ std::string statusVar;
+ bool showProgress = false;
+
+ while(i != args.end())
+ {
+ if(*i == "TIMEOUT")
+ {
+ ++i;
+ if(i != args.end())
+ {
+ timeout = atol(i->c_str());
+ }
+ else
+ {
+ this->SetError("UPLOAD missing time for TIMEOUT.");
+ return false;
+ }
+ }
+ else if(*i == "LOG")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("UPLOAD missing VAR for LOG.");
+ return false;
+ }
+ logVar = *i;
+ }
+ else if(*i == "STATUS")
+ {
+ ++i;
+ if( i == args.end())
+ {
+ this->SetError("UPLOAD missing VAR for STATUS.");
+ return false;
+ }
+ statusVar = *i;
+ }
+ else if(*i == "SHOW_PROGRESS")
+ {
+ showProgress = true;
+ }
+
+ ++i;
+ }
+
+ // Open file for reading:
+ //
+ FILE *fin = fopen(filename.c_str(), "rb");
+ if(!fin)
+ {
+ std::string errStr = "UPLOAD cannot open file '";
+ errStr += filename + "' for reading.";
+ this->SetError(errStr.c_str());
+ return false;
+ }
+
+ struct stat st;
+ if(::stat(filename.c_str(), &st))
+ {
+ std::string errStr = "UPLOAD cannot stat file '";
+ errStr += filename + "'.";
+ this->SetError(errStr.c_str());
+ return false;
+ }
+
+ ::CURL *curl;
+ ::curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = ::curl_easy_init();
+ if(!curl)
+ {
+ this->SetError("UPLOAD error initializing curl.");
+ return false;
+ }
+
+ cURLEasyGuard g_curl(curl);
+
+ // enable HTTP ERROR parsing
+ ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+
+ // enable uploading
+ res = ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+ check_curl_result(res, "UPLOAD cannot set upload flag: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ check_curl_result(res, "UPLOAD cannot set url: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ cmWriteToMemoryCallback);
+ check_curl_result(res, "UPLOAD cannot set write function: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ cmFileCommandCurlDebugCallback);
+ check_curl_result(res, "UPLOAD cannot set debug function: ");
+
+ cmFileCommandVectorOfChar chunkResponse;
+ cmFileCommandVectorOfChar chunkDebug;
+
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunkResponse);
+ check_curl_result(res, "UPLOAD cannot set write data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
+ check_curl_result(res, "UPLOAD cannot set debug data: ");
+
+ res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ check_curl_result(res, "UPLOAD cannot set follow-redirect option: ");
+
+ if(logVar.size())
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ check_curl_result(res, "UPLOAD cannot set verbose: ");
+ }
+
+ if(timeout > 0)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
+ check_curl_result(res, "UPLOAD cannot set timeout: ");
+ }
+
+ // Need the progress helper's scope to last through the duration of
+ // the curl_easy_perform call... so this object is declared at function
+ // scope intentionally, rather than inside the "if(showProgress)"
+ // block...
+ //
+ cURLProgressHelper helper(this, "upload");
+
+ if(showProgress)
+ {
+ res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ check_curl_result(res, "UPLOAD cannot set noprogress value: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSFUNCTION, cmFileUploadProgressCallback);
+ check_curl_result(res, "UPLOAD cannot set progress function: ");
+
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
+ check_curl_result(res, "UPLOAD cannot set progress data: ");
+ }
+
+ // now specify which file to upload
+ res = ::curl_easy_setopt(curl, CURLOPT_INFILE, fin);
+ check_curl_result(res, "UPLOAD cannot set input file: ");
+
+ // and give the size of the upload (optional)
+ res = ::curl_easy_setopt(curl,
+ CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
+ check_curl_result(res, "UPLOAD cannot set input file size: ");
+
+ res = ::curl_easy_perform(curl);
+
+ /* always cleanup */
+ g_curl.release();
+ ::curl_easy_cleanup(curl);
+
+ if(statusVar.size())
+ {
+ cmOStringStream result;
+ result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
+ this->Makefile->AddDefinition(statusVar.c_str(),
+ result.str().c_str());
+ }
+
+ ::curl_global_cleanup();
+
+ fclose(fin);
+ fin = NULL;
+
+ if(logVar.size())
+ {
+ std::string log;
+
+ if(chunkResponse.size())
+ {
+ chunkResponse.push_back(0);
+ log += "Response:\n";
+ log += &*chunkResponse.begin();
+ log += "\n";
+ }
+
+ if(chunkDebug.size())
+ {
+ chunkDebug.push_back(0);
+ log += "Debug:\n";
+ log += &*chunkDebug.begin();
+ log += "\n";
+ }
+
+ this->Makefile->AddDefinition(logVar.c_str(), log.c_str());
+ }
+
+ return true;
+#else
+ this->SetError("UPLOAD not supported by bootstrap cmake.");
+ return false;
+#endif
+}
diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h
index b11dcde..1b6dbbf 100644
--- a/Source/cmFileCommand.h
+++ b/Source/cmFileCommand.h
@@ -82,6 +82,8 @@ public:
" file(TO_NATIVE_PATH path result)\n"
" file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log]\n"
" [EXPECTED_MD5 sum] [SHOW_PROGRESS])\n"
+ " file(UPLOAD filename url [TIMEOUT timeout] [STATUS status]\n"
+ " [LOG log] [SHOW_PROGRESS])\n"
"WRITE will write a message into a file called 'filename'. It "
"overwrites the file if it already exists, and creates the file "
"if it does not exist.\n"
@@ -165,6 +167,18 @@ public:
"If SHOW_PROGRESS is specified, progress information will be printed "
"as status messages until the operation is complete."
"\n"
+ "UPLOAD will upload the given file to the given URL. "
+ "If LOG var is specified a log of the upload will be put in var. "
+ "If STATUS var is specified the status of the operation will"
+ " be put in var. The status is returned in a list of length 2. "
+ "The first element is the numeric return value for the operation, "
+ "and the second element is a string value for the error. A 0 "
+ "numeric error means no error in the operation. "
+ "If TIMEOUT time is specified, the operation will "
+ "timeout after time seconds, time should be specified as an integer. "
+ "If SHOW_PROGRESS is specified, progress information will be printed "
+ "as status messages until the operation is complete."
+ "\n"
"The file() command also provides COPY and INSTALL signatures:\n"
" file(<COPY|INSTALL> files... DESTINATION <dir>\n"
" [FILE_PERMISSIONS permissions...]\n"
@@ -223,6 +237,7 @@ protected:
bool HandleCopyCommand(std::vector<std::string> const& args);
bool HandleInstallCommand(std::vector<std::string> const& args);
bool HandleDownloadCommand(std::vector<std::string> const& args);
+ bool HandleUploadCommand(std::vector<std::string> const& args);
};
diff --git a/Source/kwsys/kwsysDateStamp.cmake b/Source/kwsys/kwsysDateStamp.cmake
index 8d4ad8b..990a201 100644
--- a/Source/kwsys/kwsysDateStamp.cmake
+++ b/Source/kwsys/kwsysDateStamp.cmake
@@ -15,7 +15,7 @@
SET(KWSYS_DATE_STAMP_YEAR 2011)
# KWSys version date month component. Format is MM.
-SET(KWSYS_DATE_STAMP_MONTH 02)
+SET(KWSYS_DATE_STAMP_MONTH 03)
# KWSys version date day component. Format is DD.
-SET(KWSYS_DATE_STAMP_DAY 22)
+SET(KWSYS_DATE_STAMP_DAY 01)