cmBuildNameCommand.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmBuildNameCommand.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include "cmMakefile.h"
  7. #include "cmStateTypes.h"
  8. #include "cmSystemTools.h"
  9. class cmExecutionStatus;
  10. // cmBuildNameCommand
  11. bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
  12. cmExecutionStatus&)
  13. {
  14. if (args.empty()) {
  15. this->SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. const char* cacheValue = this->Makefile->GetDefinition(args[0]);
  19. if (cacheValue) {
  20. // do we need to correct the value?
  21. cmsys::RegularExpression reg("[()/]");
  22. if (reg.find(cacheValue)) {
  23. std::string cv = cacheValue;
  24. std::replace(cv.begin(), cv.end(), '/', '_');
  25. std::replace(cv.begin(), cv.end(), '(', '_');
  26. std::replace(cv.begin(), cv.end(), ')', '_');
  27. this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
  28. cmStateEnums::STRING);
  29. }
  30. return true;
  31. }
  32. std::string buildname = "WinNT";
  33. if (this->Makefile->GetDefinition("UNIX")) {
  34. buildname.clear();
  35. cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
  36. if (!buildname.empty()) {
  37. std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
  38. cmsys::RegularExpression reg(RegExp.c_str());
  39. if (reg.find(buildname.c_str())) {
  40. buildname = reg.match(1) + "-" + reg.match(2);
  41. }
  42. }
  43. }
  44. std::string compiler = "${CMAKE_CXX_COMPILER}";
  45. this->Makefile->ExpandVariablesInString(compiler);
  46. buildname += "-";
  47. buildname += cmSystemTools::GetFilenameName(compiler);
  48. std::replace(buildname.begin(), buildname.end(), '/', '_');
  49. std::replace(buildname.begin(), buildname.end(), '(', '_');
  50. std::replace(buildname.begin(), buildname.end(), ')', '_');
  51. this->Makefile->AddCacheDefinition(args[0], buildname.c_str(),
  52. "Name of build.", cmStateEnums::STRING);
  53. return true;
  54. }