diff options
author | Nils Gladitz <nilsgladitz@gmail.com> | 2014-08-25 20:44:06 (GMT) |
---|---|---|
committer | Nils Gladitz <nilsgladitz@gmail.com> | 2014-08-28 13:13:54 (GMT) |
commit | 328e8694335ca76fb29ebd5fafe4456a89ac25c7 (patch) | |
tree | ebd88c211455ff0a7a1ce8081b1c48bcd01fc214 /Source/cmStringCommand.cxx | |
parent | c2a47a9ac3fef38d9da6260725708c2246c1b9c1 (diff) | |
download | CMake-328e8694335ca76fb29ebd5fafe4456a89ac25c7.zip CMake-328e8694335ca76fb29ebd5fafe4456a89ac25c7.tar.gz CMake-328e8694335ca76fb29ebd5fafe4456a89ac25c7.tar.bz2 |
StringUuid: Implement new string(UUID) sub-command.
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r-- | Source/cmStringCommand.cxx | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 65912da..90a8f85 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -20,6 +20,7 @@ #include <time.h> #include <cmTimestamp.h> +#include <cmUuid.h> //---------------------------------------------------------------------------- bool cmStringCommand @@ -105,6 +106,10 @@ bool cmStringCommand { return this->HandleGenexStripCommand(args); } + else if(subCommand == "UUID") + { + return this->HandleUuidCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e); @@ -981,3 +986,114 @@ bool cmStringCommand return true; } + +bool cmStringCommand +::HandleUuidCommand(std::vector<std::string> const& args) +{ +#if defined(CMAKE_BUILD_WITH_CMAKE) + unsigned int argsIndex = 1; + + if(args.size() < 2) + { + this->SetError("UUID sub-command requires an output variable."); + return false; + } + + const std::string &outputVariable = args[argsIndex++]; + + std::string uuidNamespaceString; + std::string uuidName; + std::string uuidType; + bool uuidUpperCase = false; + + while(args.size() > argsIndex) + { + if(args[argsIndex] == "NAMESPACE") + { + ++argsIndex; + if(argsIndex >= args.size()) + { + this->SetError("UUID sub-command, NAMESPACE requires a value."); + return false; + } + uuidNamespaceString = args[argsIndex++]; + } + else if(args[argsIndex] == "NAME") + { + ++argsIndex; + if(argsIndex >= args.size()) + { + this->SetError("UUID sub-command, NAME requires a value."); + return false; + } + uuidName = args[argsIndex++]; + } + else if(args[argsIndex] == "TYPE") + { + ++argsIndex; + if(argsIndex >= args.size()) + { + this->SetError("UUID sub-command, TYPE requires a value."); + return false; + } + uuidType = args[argsIndex++]; + } + else if(args[argsIndex] == "UPPER") + { + ++argsIndex; + uuidUpperCase = true; + } + else + { + std::string e = "UUID sub-command does not recognize option " + + args[argsIndex] + "."; + this->SetError(e); + return false; + } + } + + std::string uuid; + cmUuid uuidGenerator; + + std::vector<unsigned char> uuidNamespace; + if(!uuidGenerator.StringToBinary(uuidNamespaceString, uuidNamespace)) + { + this->SetError("UUID sub-command, malformed NAMESPACE UUID."); + return false; + } + + if(uuidType == "MD5") + { + uuid = uuidGenerator.FromMd5(uuidNamespace, uuidName); + } + else if(uuidType == "SHA1") + { + uuid = uuidGenerator.FromSha1(uuidNamespace, uuidName); + } + else + { + std::string e = "UUID sub-command, unknown TYPE '" + uuidType + "'."; + this->SetError(e); + return false; + } + + if(uuid.empty()) + { + this->SetError("UUID sub-command, generation failed."); + return false; + } + + if(uuidUpperCase) + { + uuid = cmSystemTools::UpperCase(uuid); + } + + this->Makefile->AddDefinition(outputVariable, uuid.c_str()); + return true; +#else + cmOStringStream e; + e << args[0] << " not available during bootstrap"; + this->SetError(e.str().c_str()); + return false; +#endif +} |