cmBuildNameCommand.cxx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // 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 += "-";
  59. buildname += cmSystemTools::GetFilenameName(compiler);
  60. cmSystemTools::ReplaceString(buildname,
  61. "/", "_");
  62. cmSystemTools::ReplaceString(buildname,
  63. "(", "_");
  64. cmSystemTools::ReplaceString(buildname,
  65. ")", "_");
  66. m_Makefile->AddCacheDefinition(args[0].c_str(),
  67. buildname.c_str(),
  68. "Name of build.",
  69. cmCacheManager::STRING);
  70. return true;
  71. }