cmBuildNameCommand.cxx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(this->Disallowed(cmPolicies::CMP0036,
  17. "The build_name command should not be called; see CMP0036."))
  18. { return true; }
  19. if(args.size() < 1 )
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. const char* cacheValue = this->Makefile->GetDefinition(args[0]);
  25. if(cacheValue)
  26. {
  27. // do we need to correct the value?
  28. cmsys::RegularExpression reg("[()/]");
  29. if (reg.find(cacheValue))
  30. {
  31. std::string cv = cacheValue;
  32. cmSystemTools::ReplaceString(cv,"/", "_");
  33. cmSystemTools::ReplaceString(cv,"(", "_");
  34. cmSystemTools::ReplaceString(cv,")", "_");
  35. this->Makefile->AddCacheDefinition(args[0],
  36. cv.c_str(),
  37. "Name of build.",
  38. cmCacheManager::STRING);
  39. }
  40. return true;
  41. }
  42. std::string buildname = "WinNT";
  43. if(this->Makefile->GetDefinition("UNIX"))
  44. {
  45. buildname = "";
  46. cmSystemTools::RunSingleCommand("uname -a", &buildname);
  47. if(!buildname.empty())
  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. this->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. this->Makefile->AddCacheDefinition(args[0],
  68. buildname.c_str(),
  69. "Name of build.",
  70. cmCacheManager::STRING);
  71. return true;
  72. }