cmBuildNameCommand.cxx 2.61 KB
Newer Older
1 2
/*=========================================================================

3
  Program:   CMake - Cross-Platform Makefile Generator
4 5 6 7 8
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

9 10
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11

Will Schroeder's avatar
Will Schroeder committed
12 13 14
     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.
15 16 17 18 19

=========================================================================*/
#include "cmBuildNameCommand.h"

// cmBuildNameCommand
20
bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args)
21 22 23 24 25 26
{
  if(args.size() < 1 )
    {
    this->SetError("called with incorrect number of arguments");
    return false;
    }
27
  const char* cacheValue = m_Makefile->GetDefinition(args[0].c_str());
28 29
  if(cacheValue)
    {
30 31 32 33 34 35 36 37
    // do we need to correct the value? 
    cmRegularExpression reg("[()/]");
    if (reg.find(cacheValue))
      {
      std::string cv = cacheValue;
      cmSystemTools::ReplaceString(cv,"/", "_");
      cmSystemTools::ReplaceString(cv,"(", "_");
      cmSystemTools::ReplaceString(cv,")", "_");
38
      m_Makefile->AddCacheDefinition(args[0].c_str(),
39 40 41
                                     cv.c_str(),
                                     "Name of build.",
                                     cmCacheManager::STRING);
42
      }
43 44
    return true;
    }
45 46

  
47
  std::string buildname = "WinNT";
48 49 50
  if(m_Makefile->GetDefinition("UNIX"))
    {
    buildname = "";
Dan Blezek's avatar
Dan Blezek committed
51
    cmSystemTools::RunCommand("uname -a",
52
                              buildname);
Dan Blezek's avatar
Dan Blezek committed
53 54 55 56 57
    if(buildname.length())
      {
      std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
      cmRegularExpression reg( RegExp.c_str() );
      if(reg.find(buildname.c_str()))
58 59 60
        {
        buildname = reg.match(1) + "-" + reg.match(2);
        }
Dan Blezek's avatar
Dan Blezek committed
61
      }
62
    }
Bill Hoffman's avatar
Bill Hoffman committed
63
  std::string compiler = "${CMAKE_CXX_COMPILER}";
Dan Blezek's avatar
Dan Blezek committed
64
  m_Makefile->ExpandVariablesInString ( compiler );
Bill Hoffman's avatar
Bill Hoffman committed
65
  buildname += "-";
66 67 68 69 70 71 72
  buildname += cmSystemTools::GetFilenameName(compiler);
  cmSystemTools::ReplaceString(buildname,
                               "/", "_");
  cmSystemTools::ReplaceString(buildname,
                               "(", "_");
  cmSystemTools::ReplaceString(buildname,
                               ")", "_");
Dan Blezek's avatar
Dan Blezek committed
73
  
74
  m_Makefile->AddCacheDefinition(args[0].c_str(),
75 76 77
                                 buildname.c_str(),
                                 "Name of build.",
                                 cmCacheManager::STRING);
78 79 80
  return true;
}