cmBuildNameCommand.cxx 2.6 KB

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