cmBuildNameCommand.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmBuildNameCommand.h"
  14. #include <cmsys/RegularExpression.hxx>
  15. // cmBuildNameCommand
  16. bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 1 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. const char* cacheValue = this->Makefile->GetDefinition(args[0].c_str());
  24. if(cacheValue)
  25. {
  26. // do we need to correct the value?
  27. cmsys::RegularExpression reg("[()/]");
  28. if (reg.find(cacheValue))
  29. {
  30. std::string cv = cacheValue;
  31. cmSystemTools::ReplaceString(cv,"/", "_");
  32. cmSystemTools::ReplaceString(cv,"(", "_");
  33. cmSystemTools::ReplaceString(cv,")", "_");
  34. this->Makefile->AddCacheDefinition(args[0].c_str(),
  35. cv.c_str(),
  36. "Name of build.",
  37. cmCacheManager::STRING);
  38. }
  39. return true;
  40. }
  41. std::string buildname = "WinNT";
  42. if(this->Makefile->GetDefinition("UNIX"))
  43. {
  44. buildname = "";
  45. cmSystemTools::RunSingleCommand("uname -a", &buildname);
  46. if(buildname.length())
  47. {
  48. std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
  49. cmsys::RegularExpression reg( RegExp.c_str() );
  50. if(reg.find(buildname.c_str()))
  51. {
  52. buildname = reg.match(1) + "-" + reg.match(2);
  53. }
  54. }
  55. }
  56. std::string compiler = "${CMAKE_CXX_COMPILER}";
  57. this->Makefile->ExpandVariablesInString ( compiler );
  58. buildname += "-";
  59. buildname += cmSystemTools::GetFilenameName(compiler);
  60. cmSystemTools::ReplaceString(buildname,
  61. "/", "_");
  62. cmSystemTools::ReplaceString(buildname,
  63. "(", "_");
  64. cmSystemTools::ReplaceString(buildname,
  65. ")", "_");
  66. this->Makefile->AddCacheDefinition(args[0].c_str(),
  67. buildname.c_str(),
  68. "Name of build.",
  69. cmCacheManager::STRING);
  70. return true;
  71. }