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