Code::Blocks  SVN r11506
compilerIAR.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: 9263 $
6  * $Id: compilerIAR.cpp 9263 2013-08-17 09:20:28Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerIAR.cpp $
8  */
9 
10 #include <sdk.h>
11 #include <prep.h>
12 #include "compilerIAR.h"
13 #include <wx/dir.h>
14 #include <wx/intl.h>
15 #include <wx/regex.h>
16 #include <wx/config.h>
17 #include <wx/fileconf.h>
18 #include <wx/msgdlg.h>
19 
20 #ifdef __WXMSW__
21  #include <wx/msw/registry.h>
22 #endif
23 
25  : Compiler(_("IAR ") + arch + _(" Compiler"), _T("iar") + arch)
26 {
27  m_Weight = 75;
28  m_Arch = arch;
29  Reset();
30 }
31 
33 {
34  //dtor
35 }
36 
38 {
39  return (new CompilerIAR(*this));
40 }
41 
43 {
44  if (platform::windows)
45  {
47 #ifdef __WXMSW__ // for wxRegKey
48  wxRegKey key; // defaults to HKCR
49  key.SetName(wxT("HKEY_LOCAL_MACHINE\\Software\\IAR Systems\\Installed Products"));
50  if (key.Exists() && key.Open(wxRegKey::Read))
51  {
52  wxString subkeyname;
53  long idx;
54  if (key.GetFirstKey(subkeyname, idx))
55  {
56  do
57  {
58  wxRegKey keys;
59  keys.SetName(key.GetName() + wxFILE_SEP_PATH + subkeyname);
60  if (!keys.Exists() || !keys.Open(wxRegKey::Read))
61  continue;
62  keys.QueryValue(wxT("TargetDir"), m_MasterPath);
63  if (!m_MasterPath.IsEmpty())
64  {
65  if (wxFileExists(m_MasterPath + wxFILE_SEP_PATH + wxT("bin") + wxFILE_SEP_PATH + m_Programs.C))
66  break;
68  }
69  } while (key.GetNextKey(subkeyname, idx));
70  }
71  }
72 #endif // __WXMSW__
73  wxString env_path = wxGetenv(_T("ProgramFiles(x86)"));
74  if (m_MasterPath.IsEmpty())
75  {
76  wxDir dir(env_path + wxT("\\IAR Systems"));
77  if (wxDirExists(dir.GetName()) && dir.IsOpened())
78  {
79  wxString filename;
80  bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
81  while (cont)
82  {
83  if ( filename.StartsWith(wxT("Embedded Workbench")) )
84  {
85  wxFileName fn(dir.GetName() + wxFILE_SEP_PATH + filename + wxFILE_SEP_PATH +
86  m_Arch + wxFILE_SEP_PATH + wxT("bin") + wxFILE_SEP_PATH + m_Programs.C);
87  if ( wxFileName::IsFileExecutable(fn.GetFullPath())
88  && (m_MasterPath.IsEmpty() || fn.GetPath() > m_MasterPath) )
89  {
90  m_MasterPath = dir.GetName() + wxFILE_SEP_PATH + filename + wxFILE_SEP_PATH + m_Arch;
91  }
92  }
93  cont = dir.GetNext(&filename);
94  }
95  }
96  }
97  if (m_MasterPath.IsEmpty())
98  {
99  // just a guess; the default installation dir
100  m_MasterPath = env_path + wxT("\\IAR Systems\\Embedded Workbench\\" + m_Arch);
101  }
102 
103  if ( wxDirExists(m_MasterPath) )
104  {
105  AddIncludeDir(m_MasterPath + wxFILE_SEP_PATH + wxT("include"));
106  AddLibDir(m_MasterPath + wxFILE_SEP_PATH + wxT("lib") + wxFILE_SEP_PATH + wxT("clib"));
107  m_ExtraPaths.Add(m_MasterPath + wxFILE_SEP_PATH + wxT("bin"));
108  }
109  }
110  else
111  {
112  m_MasterPath=_T("/usr/local"); // default
113  }
114  if (m_Arch == wxT("8051"))
115  {
116  AddLinkerOption(wxT("-f \"") + m_MasterPath + wxFILE_SEP_PATH + wxT("config") + wxFILE_SEP_PATH +
117  wxT("devices") + wxFILE_SEP_PATH + wxT("_generic") + wxFILE_SEP_PATH +
118  wxT("lnk51ew_plain.xcl\""));
119  }
120  else // IAR
121  {
122  AddCompilerOption(wxT("--no_wrap_diagnostics"));
123  }
124  return wxFileExists(m_MasterPath + wxFILE_SEP_PATH + wxT("bin") + wxFILE_SEP_PATH + m_Programs.C) ? adrDetected : adrGuessed;
125 }
wxString GetName(bool bShortPrefix=true) const
bool IsOpened() const
bool GetFirst(wxString *filename, const wxString &filespec=wxEmptyString, int flags=wxDIR_DEFAULT) const
bool wxFileExists(const wxString &filename)
bool GetFirstKey(wxString &strKeyName, long &lIndex)
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
Definition: compilerIAR.cpp:42
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
#define wxT(string)
AutoDetectResult
Definition: compiler.h:190
bool IsFileExecutable() const
virtual void AddCompilerOption(const wxString &option)
virtual void AddLibDir(const wxString &option)
wxArrayString m_ExtraPaths
Definition: compiler.h:410
wxString m_Arch
Definition: compilerIAR.h:19
wxString wxEmptyString
wxString GetName() const
CompilerIAR(wxString arch)
Definition: compilerIAR.cpp:24
const wxString & _(const wxString &string)
Abstract base class for compilers.
Definition: compiler.h:274
bool GetNext(wxString *filename) const
bool IsEmpty() const
void Clear()
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 StartsWith(const wxString &prefix, wxString *rest=NULL) const
bool Open(AccessMode mode=Write)
char * wxGetenv(const char *name)
virtual void AddLinkerOption(const wxString &option)
int m_Weight
Definition: compiler.h:422
virtual ~CompilerIAR()
Definition: compilerIAR.cpp:32
void SetName(const wxString &strKey)
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
Definition: compilerIAR.cpp:37