CMake: Stylistic changes and documentation tweaks
...for the contributed file and string TIMESTAMP sub-commands.
This commit is contained in:
parent
711e2b3b5c
commit
d842d90622
|
@ -87,8 +87,7 @@ public:
|
||||||
" [TLS_VERIFY on|off] [TLS_CAINFO file])\n"
|
" [TLS_VERIFY on|off] [TLS_CAINFO file])\n"
|
||||||
" file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n"
|
" file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n"
|
||||||
" [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n"
|
" [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n"
|
||||||
" file(TIMESTAMP <filename> <output variable>"
|
" file(TIMESTAMP filename variable [<format string>] [UTC])\n"
|
||||||
" [<format string>] [UTC])\n"
|
|
||||||
"WRITE will write a message into a file called 'filename'. It "
|
"WRITE will write a message into a file called 'filename'. It "
|
||||||
"overwrites the file if it already exists, and creates the file "
|
"overwrites the file if it already exists, and creates the file "
|
||||||
"if it does not exist. (If the file is a build input, use "
|
"if it does not exist. (If the file is a build input, use "
|
||||||
|
@ -203,9 +202,9 @@ public:
|
||||||
"as status messages until the operation is complete."
|
"as status messages until the operation is complete."
|
||||||
"\n"
|
"\n"
|
||||||
"TIMESTAMP will write a string representation of "
|
"TIMESTAMP will write a string representation of "
|
||||||
"the modification time of <filename> to <output varaible>.\n"
|
"the modification time of filename to variable.\n"
|
||||||
"Should the command be unable to obtain a timestamp "
|
"Should the command be unable to obtain a timestamp "
|
||||||
"<output variable> will be set to the empty string \"\".\n"
|
"variable will be set to the empty string \"\".\n"
|
||||||
"See documentation of the string TIMESTAMP sub-command for more details."
|
"See documentation of the string TIMESTAMP sub-command for more details."
|
||||||
"\n"
|
"\n"
|
||||||
"The file() command also provides COPY and INSTALL signatures:\n"
|
"The file() command also provides COPY and INSTALL signatures:\n"
|
||||||
|
|
|
@ -145,9 +145,9 @@ public:
|
||||||
" by all regular expression-related commands, including \n"
|
" by all regular expression-related commands, including \n"
|
||||||
" e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).\n"
|
" e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).\n"
|
||||||
"TIMESTAMP will write a string representation of "
|
"TIMESTAMP will write a string representation of "
|
||||||
"the current date and/or time to <output variable>.\n"
|
"the current date and/or time to the output variable.\n"
|
||||||
"Should the command be unable to obtain a timestamp "
|
"Should the command be unable to obtain a timestamp "
|
||||||
"<output variable> will be set to the empty string \"\".\n"
|
"the output variable will be set to the empty string \"\".\n"
|
||||||
"The optional UTC flag requests the current date/time "
|
"The optional UTC flag requests the current date/time "
|
||||||
"representation to be in Coordinated Universal Time (UTC) "
|
"representation to be in Coordinated Universal Time (UTC) "
|
||||||
"rather than local time.\n"
|
"rather than local time.\n"
|
||||||
|
|
|
@ -21,62 +21,68 @@ std::string cmTimestamp::CurrentTime(
|
||||||
const std::string& formatString, bool utcFlag)
|
const std::string& formatString, bool utcFlag)
|
||||||
{
|
{
|
||||||
time_t currentTimeT = time(0);
|
time_t currentTimeT = time(0);
|
||||||
if(currentTimeT == time_t(-1)) return std::string();
|
if(currentTimeT == time_t(-1))
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag);
|
return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
std::string cmTimestamp::FileModificationTime(const char* path,
|
std::string cmTimestamp::FileModificationTime(const char* path,
|
||||||
const std::string& formatString, bool utcFlag)
|
const std::string& formatString, bool utcFlag)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct _stat info;
|
#define STAT _stat
|
||||||
std::memset(&info, 0, sizeof(info));
|
|
||||||
|
|
||||||
if(_stat(path, &info) != 0)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
time_t currentTimeT = info.st_mtime;
|
|
||||||
#else
|
#else
|
||||||
struct stat info;
|
#define STAT stat
|
||||||
std::memset(&info, 0, sizeof(info));
|
|
||||||
|
|
||||||
if(stat(path, &info) != 0)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
time_t currentTimeT = info.st_mtime;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag);
|
struct STAT info;
|
||||||
|
std::memset(&info, 0, sizeof(info));
|
||||||
|
|
||||||
|
if(STAT(path, &info) != 0)
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateTimestampFromTimeT(info.st_mtime, formatString, utcFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
|
std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
|
||||||
std::string formatString, bool utcFlag)
|
std::string formatString, bool utcFlag)
|
||||||
{
|
{
|
||||||
if(formatString.empty())
|
if(formatString.empty())
|
||||||
{
|
{
|
||||||
formatString = "%Y-%m-%dT%H:%M:%S";
|
formatString = "%Y-%m-%dT%H:%M:%S";
|
||||||
if(utcFlag) formatString += "Z";
|
if(utcFlag)
|
||||||
|
{
|
||||||
|
formatString += "Z";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm timeStruct;
|
struct tm timeStruct;
|
||||||
std::memset(&timeStruct, 0, sizeof(timeStruct));
|
std::memset(&timeStruct, 0, sizeof(timeStruct));
|
||||||
|
|
||||||
|
struct tm* ptr = (struct tm*) 0;
|
||||||
if(utcFlag)
|
if(utcFlag)
|
||||||
{
|
{
|
||||||
tm* ptr = gmtime(&timeT);
|
ptr = gmtime(&timeT);
|
||||||
if(ptr == 0) return std::string();
|
|
||||||
|
|
||||||
timeStruct = *ptr;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct tm* ptr = localtime(&timeT);
|
ptr = localtime(&timeT);
|
||||||
if(ptr == 0) return std::string();
|
|
||||||
|
|
||||||
timeStruct = *ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ptr == 0)
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
timeStruct = *ptr;
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
for(std::string::size_type i = 0; i < formatString.size(); ++i)
|
for(std::string::size_type i = 0; i < formatString.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
string(TIMESTAMP output UTC)
|
|
||||||
message("~${output}~")
|
|
Loading…
Reference in New Issue