Code::Blocks  SVN r11506
compilerMSVC8.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: compilerMSVC8.cpp 8649 2012-12-12 19:18:18Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerMSVC8.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "compilerMSVC8.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++ 2005/2008"), _T("msvc8"))
22 {
23  m_Weight = 12;
24  Reset();
25 }
26 
28 {
29  //dtor
30 }
31 
33 {
34  return (new CompilerMSVC8(*this));
35 }
36 
38 {
40  wxString idepath;
41 
42  // Read the VCToolkitInstallDir environment variable
43  wxGetEnv(_T("VS90COMNTOOLS"), &m_MasterPath);
44  if(m_MasterPath.IsEmpty())
45  {
46  wxGetEnv(_T("VS80COMNTOOLS"), &m_MasterPath);
47  }
48 
49  if ( !m_MasterPath.IsEmpty() )
50  {
52 
53  name.RemoveLastDir();
54  name.AppendDir(_T("IDE"));
55  idepath = name.GetPath();
56  if ( !wxDirExists(idepath) )
57  idepath = _T("");
58 
59  name.RemoveLastDir();
60  name.RemoveLastDir();
61  name.AppendDir(_T("VC"));
62  m_MasterPath = name.GetPath();
63  if ( !wxDirExists(m_MasterPath) )
64  m_MasterPath = _T("");
65  }
66 
67  if (m_MasterPath.IsEmpty())
68  {
69  // just a guess; the default installation dir
70  wxString Programs = _T("C:\\Program Files");
71  // what's the "Program Files" location
72  // TO DO : support 64 bit -> 32 bit apps are in "ProgramFiles(x86)"
73  // 64 bit apps are in "ProgramFiles"
74  wxGetEnv(_T("ProgramFiles"), &Programs);
75  m_MasterPath = Programs + _T("\\Microsoft Visual Studio 9.0\\VC");
76  idepath = Programs + _T("\\Microsoft Visual Studio 9.0\\Common7\\IDE");
78  {
79  m_MasterPath = Programs + _T("\\Microsoft Visual Studio 8\\VC");
80  idepath = Programs + _T("\\Microsoft Visual Studio 8\\Common7\\IDE");
81  }
82  }
83 
84  if (!m_MasterPath.IsEmpty())
85  {
86  bool sdkfound = false;
87  wxString dir;
88 
89  // we need to add the IDE path, as the compiler requires some DLL present there
90  m_ExtraPaths.Add(idepath);
91 
92 #ifdef __WXMSW__
93  wxRegKey key; // defaults to HKCR
94  // try to detect Platform SDK (old versions)
95  key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Win32SDK\\Directories"));
96  if (key.Exists() && key.Open(wxRegKey::Read))
97  {
98  key.QueryValue(_T("Install Dir"), dir);
99  if (!dir.IsEmpty() && wxDirExists(dir))
100  sdkfound = true;
101  key.Close();
102  }
103 
104  // try to detect Platform SDK (newer versions)
105  wxString msPsdkKeyName[2] = { _T("HKEY_CURRENT_USER\\Software\\Microsoft\\MicrosoftSDK\\InstalledSDKs"),
106  _T("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows") };
107  wxString msPsdkKeyValue[2] = { _T("Install Dir"), _T("InstallationFolder") };
108  for (int i = 0; i < 2; ++i)
109  {
110  key.SetName(msPsdkKeyName[i]);
111  if (!sdkfound && key.Exists() && key.Open(wxRegKey::Read))
112  {
113  wxString name;
114  long idx;
115  bool cont = key.GetFirstKey(name, idx);
116 
117  while(cont)
118  {
119  wxRegKey subkey(key.GetName(), name);
120 
121  if (subkey.Open(wxRegKey::Read) &&
122  (subkey.QueryValue(msPsdkKeyValue[i], dir), !dir.IsEmpty()) &&
123  wxDirExists(dir))
124  {
125  sdkfound = true;
126  cont = false;
127  }
128  else
129  cont = key.GetNextKey(name, idx);
130 
131  subkey.Close();
132  }
133  key.Close();
134  }
135 
136  if (sdkfound)
137  break;
138  }
139 #endif // __WXMSW__
140 
141  // take a guess
142  if (!sdkfound)
143  {
144  dir = wxT("C:\\Program Files");
145  wxGetEnv(wxT("ProgramFiles"), &dir);
146  dir += wxT("\\Microsoft SDKs\\Windows\\v");
147  wxArrayString vers = GetArrayFromString(wxT("7.1;7.0A;7.0;6.1;6.0A;6.0"));
148  for (size_t i = 0; i < vers.GetCount(); ++i)
149  {
150  if (wxDirExists(dir + vers[i]))
151  {
152  dir += vers[i];
153  sdkfound = true;
154  break;
155  }
156  }
157  }
158 
159  // add include dirs for MS Platform SDK too (let them come before compiler's path)
160  if (sdkfound)
161  {
162  if (dir.GetChar(dir.Length() - 1) != '\\')
163  dir += sep;
164  AddIncludeDir(dir + _T("include"));
165  AddResourceIncludeDir(dir + _T("include"));
166  AddLibDir(dir + _T("lib"));
167  m_ExtraPaths.Add(dir + _T("bin"));
168  }
169 
170  // now the compiler's include directories
171  AddIncludeDir(m_MasterPath + sep + _T("include"));
172  AddLibDir(m_MasterPath + sep + _T("lib"));
173  AddResourceIncludeDir(m_MasterPath + sep + _T("include"));
174 
175 #ifdef __WXMSW__
176  // add extra paths for "Debugging tools" too
177  key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\DebuggingTools"));
178  if (key.Exists() && key.Open(wxRegKey::Read))
179  {
180  key.QueryValue(_T("WinDbg"), dir);
181  if (!dir.IsEmpty() && wxDirExists(dir))
182  {
183  if (dir.GetChar(dir.Length() - 1) == '\\')
184  dir.Remove(dir.Length() - 1, 1);
185  m_ExtraPaths.Add(dir);
186  }
187  }
188  key.Close();
189 #endif // __WXMSW__
190  }
191 
192  return wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C) ? adrDetected : adrGuessed;
193 }
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
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)
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
CompilerPrograms m_Programs
Definition: compiler.h:412
wxString & Remove(size_t pos)
void Close()
Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
#define wxT(string)
AutoDetectResult
Definition: compiler.h:190
virtual void AddResourceIncludeDir(const wxString &option)
bool AppendDir(const wxString &dir)
void RemoveLastDir()
virtual ~CompilerMSVC8()
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)
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)