cmBuildNameCommand.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = m_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. m_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(m_Makefile->GetDefinition("UNIX"))
  43. {
  44. buildname = "";
  45. cmSystemTools::RunCommand("uname -a",
  46. buildname);
  47. if(buildname.length())
  48. {
  49. std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
  50. cmsys::RegularExpression reg( RegExp.c_str() );
  51. if(reg.find(buildname.c_str()))
  52. {
  53. buildname = reg.match(1) + "-" + reg.match(2);
  54. }
  55. }
  56. }
  57. std::string compiler = "${CMAKE_CXX_COMPILER}";
  58. m_Makefile->ExpandVariablesInString ( compiler );
  59. buildname += "-";
  60. buildname += cmSystemTools::GetFilenameName(compiler);
  61. cmSystemTools::ReplaceString(buildname,
  62. "/", "_");
  63. cmSystemTools::ReplaceString(buildname,
  64. "(", "_");
  65. cmSystemTools::ReplaceString(buildname,
  66. ")", "_");
  67. m_Makefile->AddCacheDefinition(args[0].c_str(),
  68. buildname.c_str(),
  69. "Name of build.",
  70. cmCacheManager::STRING);
  71. return true;
  72. }