Code::Blocks  SVN r11506
compilerMSVC10.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 8649 $
6  * $Id: compilerMSVC10.cpp 8649 2012-12-12 19:18:18Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerMSVC10.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "compilerMSVC10.h"
12 #include <wx/wx.h>
13 #include <wx/intl.h>
14 #include <wx/regex.h>
15 #include <wx/config.h>
16 #ifdef __WXMSW__
17  #include <wx/msw/registry.h>
18 #endif // __WXMSW__
19 
21  : Compiler(_("Microsoft Visual C++ 2010"), _T("msvc10"))
22 {
23  m_Weight = 16;
24  Reset();
25 }
26 
28 {
29  //dtor
30 }
31 
33 {
34  return (new CompilerMSVC10(*this));
35 }
36 
38 {
40  wxString idepath;
41 
42  // Read the VS2010 environment variable
43  wxGetEnv(_T("VS100COMNTOOLS"), &m_MasterPath);
44 
45  if ( !m_MasterPath.IsEmpty() )
46  {
48 
49  name.RemoveLastDir();
50  name.AppendDir(_T("IDE"));
51  idepath = name.GetPath();
52  if ( !wxDirExists(idepath) )
53  idepath = _T("");
54 
55  name.RemoveLastDir();
56  name.RemoveLastDir();
57  name.AppendDir(_T("VC"));
58  m_MasterPath = name.GetPath();
59  if ( !wxDirExists(m_MasterPath) )
60  m_MasterPath = _T("");
61  }
62 
63  if (m_MasterPath.IsEmpty())
64  {
65  // just a guess; the default installation dir
66  wxString Programs = _T("C:\\Program Files");
67  // what's the "Program Files" location
68  wxGetEnv(_T("ProgramFiles"), &Programs);
69  m_MasterPath = Programs + _T("\\Microsoft Visual Studio 10.0\\VC");
70  idepath = Programs + _T("\\Microsoft Visual Studio 10.0\\Common7\\IDE");
71  }
72 
73  if (!m_MasterPath.IsEmpty())
74  {
75  bool sdkfound = false;
76  wxString dir;
77 
78  // we need to add the IDE path, as the compiler requires some DLL present there
79  m_ExtraPaths.Add(idepath);
80 
81 #ifdef __WXMSW__
82  wxRegKey key; // defaults to HKCR
83  // try to detect Platform SDK (old versions)
84  key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Win32SDK\\Directories"));
85  if (key.Exists() && key.Open(wxRegKey::Read))
86  {
87  key.QueryValue(_T("Install Dir"), dir);
88  if (!dir.IsEmpty() && wxDirExists(dir))
89  sdkfound = true;
90  key.Close();
91  }
92 
93  // try to detect Platform SDK (newer versions)
94  wxString msPsdkKeyName[2] = { _T("HKEY_CURRENT_USER\\Software\\Microsoft\\MicrosoftSDK\\InstalledSDKs"),
95  _T("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows") };
96  wxString msPsdkKeyValue[2] = { _T("Install Dir"), _T("InstallationFolder") };
97  for (int i = 0; i < 2; ++i)
98  {
99  if (sdkfound)
100  break;
101 
102  key.SetName(msPsdkKeyName[i]);
103  if (key.Exists() && key.Open(wxRegKey::Read))
104  {
105  wxString name;
106  long idx;
107  bool cont = key.GetFirstKey(name, idx);
108 
109  while(cont)
110  {
111  wxRegKey subkey(key.GetName(), name);
112 
113  if (subkey.Open(wxRegKey::Read) &&
114  (subkey.QueryValue(msPsdkKeyValue[i], dir), !dir.IsEmpty()) &&
115  wxDirExists(dir))
116  {
117  sdkfound = true;
118  cont = false;
119  }
120  else
121  cont = key.GetNextKey(name, idx);
122 
123  subkey.Close();
124  }
125  key.Close();
126  }
127  }
128 #endif // __WXMSW__
129 
130  // take a guess
131  if (!sdkfound)
132  {
133  dir = wxT("C:\\Program Files");
134  wxGetEnv(wxT("ProgramFiles"), &dir);
135  dir += wxT("\\Microsoft SDKs\\Windows\\v");
136  wxArrayString vers = GetArrayFromString(wxT("7.1;7.0A;7.0;6.1;6.0A;6.0"));
137  for (size_t i = 0; i < vers.GetCount(); ++i)
138  {
139  if (wxDirExists(dir + vers[i]))
140  {
141  dir += vers[i];
142  sdkfound = true;
143  break;
144  }
145  }
146  }
147 
148  // add include dirs for MS Platform SDK too (let them come before compiler's path)
149  if (sdkfound)
150  {
151  if (dir.GetChar(dir.Length() - 1) != '\\')
152  dir += sep;
153  AddIncludeDir(dir + _T("include"));
154  AddResourceIncludeDir(dir + _T("include"));
155  AddLibDir(dir + _T("lib"));
156  m_ExtraPaths.Add(dir + _T("bin"));
157  }
158 
159  // now the compiler's include directories
160  AddIncludeDir(m_MasterPath + sep + _T("include"));
161  AddLibDir(m_MasterPath + sep + _T("lib"));
162  AddResourceIncludeDir(m_MasterPath + sep + _T("include"));
163 
164 #ifdef __WXMSW__
165  // add extra paths for "Debugging tools" too
166  key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\DebuggingTools"));
167  if (key.Exists() && key.Open(wxRegKey::Read))
168  {
169  key.QueryValue(_T("WinDbg"), dir);
170  if (!dir.IsEmpty() && wxDirExists(dir))
171  {
172  if (dir.GetChar(dir.Length() - 1) == '\\')
173  dir.Remove(dir.Length() - 1, 1);
174  m_ExtraPaths.Add(dir);
175  }
176  }
177  key.Close();
178 #endif // __WXMSW__
179  }
180 
181  return wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C) ? adrDetected : adrGuessed;
182 }
wxString GetName(bool bShortPrefix=true) const
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
Definition: globals.cpp:134
virtual ~CompilerMSVC10()
bool wxGetEnv(const wxString &var, wxString *value)
bool wxFileExists(const wxString &filename)
bool GetFirstKey(wxString &strKeyName, long &lIndex)
size_t Length() const
bool wxDirExists(const wxString &dirname)
virtual void Reset()
Reset settings to defaults.
Definition: compiler.cpp:157
#define _T(string)
virtual void AddIncludeDir(const wxString &option)
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
CompilerPrograms m_Programs
Definition: compiler.h:412
wxString & Remove(size_t pos)
void Close()
#define wxT(string)
AutoDetectResult
Definition: compiler.h:190
virtual void AddResourceIncludeDir(const wxString &option)
bool AppendDir(const wxString &dir)
void RemoveLastDir()
virtual void AddLibDir(const wxString &option)
static const wxString sep
static wxFileName DirName(const wxString &dir, wxPathFormat format=wxPATH_NATIVE)
wxArrayString m_ExtraPaths
Definition: compiler.h:410
static wxUniChar GetPathSeparator(wxPathFormat format=wxPATH_NATIVE)
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
const wxString & _(const wxString &string)
Abstract base class for compilers.
Definition: compiler.h:274
bool IsEmpty() const
wxString GetPath(int flags=wxPATH_GET_VOLUME, wxPathFormat format=wxPATH_NATIVE) const
wxString C
Definition: compiler.h:199
bool GetNextKey(wxString &strKeyName, long &lIndex) const
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
size_t Add(const wxString &str, size_t copies=1)
bool Open(AccessMode mode=Write)
size_t GetCount() const
wxUniChar GetChar(size_t n) const
int m_Weight
Definition: compiler.h:422
void SetName(const wxString &strKey)
Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.