cmBuildNameCommand.cxx 2.1 KB

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