cmBuildNameCommand.cxx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. // cmBuildNameCommand
  15. bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. const char* cacheValue = m_Makefile->GetDefinition(args[0].c_str());
  23. if(cacheValue)
  24. {
  25. // do we need to correct the value?
  26. cmRegularExpression reg("[()/]");
  27. if (reg.find(cacheValue))
  28. {
  29. std::string cv = cacheValue;
  30. cmSystemTools::ReplaceString(cv,"/", "_");
  31. cmSystemTools::ReplaceString(cv,"(", "_");
  32. cmSystemTools::ReplaceString(cv,")", "_");
  33. m_Makefile->AddCacheDefinition(args[0].c_str(),
  34. cv.c_str(),
  35. "Name of build.",
  36. cmCacheManager::STRING);
  37. }
  38. return true;
  39. }
  40. std::string buildname = "WinNT";
  41. if(m_Makefile->GetDefinition("UNIX"))
  42. {
  43. buildname = "";
  44. cmSystemTools::RunCommand("uname -a",
  45. buildname);
  46. if(buildname.length())
  47. {
  48. std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
  49. cmRegularExpression 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. m_Makefile->ExpandVariablesInString ( compiler );
  58. buildname += cmSystemTools::GetFilenameName(compiler);
  59. cmSystemTools::ReplaceString(buildname,
  60. "/", "_");
  61. cmSystemTools::ReplaceString(buildname,
  62. "(", "_");
  63. cmSystemTools::ReplaceString(buildname,
  64. ")", "_");
  65. m_Makefile->AddCacheDefinition(args[0].c_str(),
  66. buildname.c_str(),
  67. "Name of build.",
  68. cmCacheManager::STRING);
  69. return true;
  70. }