cmBuildNameCommand.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "cmState.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 (this->Disallowed(
  16. cmPolicies::CMP0036,
  17. "The build_name command should not be called; see CMP0036.")) {
  18. return true;
  19. }
  20. if (args.empty()) {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. const char* cacheValue = this->Makefile->GetDefinition(args[0]);
  25. if (cacheValue) {
  26. // do we need to correct the value?
  27. cmsys::RegularExpression reg("[()/]");
  28. if (reg.find(cacheValue)) {
  29. std::string cv = cacheValue;
  30. std::replace(cv.begin(), cv.end(), '/', '_');
  31. std::replace(cv.begin(), cv.end(), '(', '_');
  32. std::replace(cv.begin(), cv.end(), ')', '_');
  33. this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
  34. cmStateEnums::STRING);
  35. }
  36. return true;
  37. }
  38. std::string buildname = "WinNT";
  39. if (this->Makefile->GetDefinition("UNIX")) {
  40. buildname = "";
  41. cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
  42. if (!buildname.empty()) {
  43. std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
  44. cmsys::RegularExpression reg(RegExp.c_str());
  45. if (reg.find(buildname.c_str())) {
  46. buildname = reg.match(1) + "-" + reg.match(2);
  47. }
  48. }
  49. }
  50. std::string compiler = "${CMAKE_CXX_COMPILER}";
  51. this->Makefile->ExpandVariablesInString(compiler);
  52. buildname += "-";
  53. buildname += cmSystemTools::GetFilenameName(compiler);
  54. std::replace(buildname.begin(), buildname.end(), '/', '_');
  55. std::replace(buildname.begin(), buildname.end(), '(', '_');
  56. std::replace(buildname.begin(), buildname.end(), ')', '_');
  57. this->Makefile->AddCacheDefinition(args[0], buildname.c_str(),
  58. "Name of build.", cmStateEnums::STRING);
  59. return true;
  60. }