Code::Blocks  SVN r11506
compilerICC.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: 11399 $
6  * $Id: compilerICC.cpp 11399 2018-05-08 21:54:03Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerICC.cpp $
8  */
9 
10 #include <sdk.h>
11 #ifndef CB_PRECOMP
12  #include <wx/intl.h>
13  #include <wx/msgdlg.h>
14  #include <wx/regex.h>
15 
16  #include "compilerfactory.h"
17  #include "logmanager.h"
18  #include "manager.h"
19  #include "macrosmanager.h"
20 #endif // CB_PRECOMP
21 
22 #include <wx/config.h>
23 #include <wx/fileconf.h>
24 
25 #include "compilerICC.h"
26 
28 {
29  public:
30  wxIccDirTraverser(wxArrayString& folders) : m_Dirs(folders)
31  {
32  m_SepChar = (platform::windows == 1) ? _T('\\') : _T('/');
33  }
34 
35  wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) override
36  {
37  return wxDIR_CONTINUE;
38  }
39 
40  wxDirTraverseResult OnDir(const wxString& dirname) override
41  {
42  if (m_Dirs.Index(dirname) == wxNOT_FOUND &&
43  dirname.AfterLast(m_SepChar).Contains(_T(".")))
44  {
45  m_Dirs.Add(dirname);
46  }
47  return wxDIR_CONTINUE;
48  }
49 
50  private:
53 };
54 
56  : Compiler(_("Intel C/C++ Compiler"), _T("icc"))
57 {
58  m_Weight = 40;
59  Reset();
60 }
61 
63 {
64  //dtor
65 }
66 
68 {
69  return (new CompilerICC(*this));
70 }
71 
73 {
75 
76  if (platform::windows)
77  {
78  if ( wxDirExists(_T("C:\\Program Files\\Intel\\Compiler")) )
79  {
80  wxDir icc_dir(_T("C:\\Program Files\\Intel\\Compiler\\C++"));
81  if (icc_dir.IsOpened())
82  {
83  wxArrayString dirs;
84  wxIccDirTraverser IccDirTraverser(dirs);
85  icc_dir.Traverse(IccDirTraverser);
86  if (!dirs.IsEmpty())
87  {
88  // Now sort the array in reverse order to get the latest version's path
89  dirs.Sort(true);
90  m_MasterPath = dirs[0];
91  m_MasterPath.Append(_T("\\IA32"));
92  }
93  }
94  }
95 
96  int version = 0;
98  {
99  wxString iccEnvVar;
100  if (version==0)
101  {
102  // Try default w/o version number
103  iccEnvVar = _T("ICPP_COMPILER");
104  version = 8;
105  }
106  else if (version>15)
107  break; // exit while-loop
108  else
109  {
110  // Try ICPP_COMPILER80 ... ICPP_COMPILER12
111  iccEnvVar.Printf(wxT("ICPP_COMPILER%d0"), version);
112  version++;
113  }
114 
115  // Read the ICPP_COMPILER[XX] environment variable
116  if ( !wxGetEnv(iccEnvVar, &m_MasterPath) )
118  }
119 
120  // Now check for the installation of MSVC
121  const wxString msvcIds[4] = { _T("msvc6"),
122  _T("msvctk"),
123  _T("msvc8"),
124  _T("msvc10") };
125  bool msvcFound = false;
126  for (unsigned int which_msvc = 0; which_msvc < array_size(msvcIds); ++which_msvc)
127  {
128  Compiler* vcComp = CompilerFactory::GetCompiler(msvcIds[which_msvc]);
129  if (!vcComp)
130  continue; // compiler not registered? try next one
131 
132  wxString vcMasterNoMacros = vcComp->GetMasterPath();
133  Manager::Get()->GetMacrosManager()->ReplaceMacros(vcMasterNoMacros);
134  if ( !wxFileExists(vcMasterNoMacros + sep + wxT("bin") + sep + vcComp->GetPrograms().C)
135  && !wxFileExists(vcMasterNoMacros + sep + vcComp->GetPrograms().C) )
136  continue; // this MSVC is not installed; try next one
137 
138  const wxString& vcMasterPath = vcComp->GetMasterPath();
139  if (m_ExtraPaths.Index(vcMasterPath) == wxNOT_FOUND)
140  m_ExtraPaths.Add(vcMasterPath);
141  if ( !vcMasterPath.EndsWith(wxT("bin"))
142  && m_ExtraPaths.Index(vcMasterPath + sep + wxT("bin")) == wxNOT_FOUND )
143  {
144  m_ExtraPaths.Add(vcMasterPath + sep + wxT("bin"));
145  }
146  AddIncludeDir(vcMasterPath + _T("\\Include"));
147  AddLibDir(vcMasterPath + _T("\\Lib"));
148  AddResourceIncludeDir(vcMasterPath + _T("\\Include"));
149 
150  const wxArrayString& vcExtraPaths = vcComp->GetExtraPaths();
151  for (size_t i = 0; i < vcExtraPaths.GetCount(); ++i)
152  {
153  if ( m_ExtraPaths.Index(vcExtraPaths[i]) == wxNOT_FOUND
154  && wxDirExists(vcExtraPaths[i]) )
155  {
156  m_ExtraPaths.Add(vcExtraPaths[i]);
157  }
158  }
159  const wxArrayString& vcIncludeDirs = vcComp->GetIncludeDirs();
160  for (size_t i = 0; i < vcIncludeDirs.GetCount(); ++i)
161  {
162  if (wxDirExists(vcIncludeDirs[i]))
163  {
164  if (m_IncludeDirs.Index(vcIncludeDirs[i]) == wxNOT_FOUND)
165  AddIncludeDir(vcIncludeDirs[i]);
166 
167  if (m_ResIncludeDirs.Index(vcIncludeDirs[i]) == wxNOT_FOUND)
168  AddResourceIncludeDir(vcIncludeDirs[i]);
169  }
170  }
171  const wxArrayString& vcLibDirs = vcComp->GetLibDirs();
172  for (size_t i = 0; i < vcLibDirs.GetCount(); ++i)
173  {
174  if ( m_LibDirs.Index(vcLibDirs[i]) == wxNOT_FOUND
175  && wxDirExists(vcLibDirs[i]) )
176  {
177  AddLibDir(vcLibDirs[i]);
178  }
179  }
180  msvcFound = true;
181  break;
182  }
183 
185  {
186  // Just a final guess for the default installation dir
187  wxString Programs = _T("C:\\Program Files");
188  // what's the "Program Files" location
189  // TO DO : support 64 bit -> 32 bit apps are in "ProgramFiles(x86)"
190  // 64 bit apps are in "ProgramFiles"
191  wxGetEnv(_T("ProgramFiles"), &Programs);
192  m_MasterPath = Programs + _T("\\Intel\\Compiler\\C++\\9.0");
193  }
194  else if (!msvcFound)
195  {
196  cbMessageBox(_T("It seems your computer doesn't have a MSVC compiler installed.\n\n"
197  "The ICC compiler requires MSVC for proper functioning and\n"
198  "it may not work without it."),
199  _T("Error"), wxOK | wxICON_ERROR);
200  }
201  }
202  else
203  {
204  m_MasterPath = _T("/opt/intel/cc/9.0");
205  if (wxDirExists(_T("/opt/intel")))
206  {
207  wxDir icc_dir(_T("/opt/intel/cc"));
208  if (icc_dir.IsOpened())
209  {
210  wxArrayString dirs;
211  wxIccDirTraverser IccDirTraverser(dirs);
212  icc_dir.Traverse(IccDirTraverser);
213  if (!dirs.IsEmpty())
214  {
215  // Now sort the array in reverse order to get the latest version's path
216  dirs.Sort(true);
217  m_MasterPath = dirs[0];
218  }
219  }
220  }
221  }
222 
224  if (ret == adrGuessed)
225  ret = wxFileExists(m_MasterPath + sep + _T("bin") + sep + _T("ia32") + sep + m_Programs.C) ? adrDetected : adrGuessed;
226  if (ret == adrGuessed)
227  ret = wxFileExists(m_MasterPath + sep + _T("bin") + sep + _T("intel64") + sep + m_Programs.C) ? adrDetected : adrGuessed;
228 
229  if (ret == adrDetected)
230  {
231  if ( wxFileExists(m_MasterPath + sep + _T("bin") + sep + _T("ia32") + sep + m_Programs.C) )
232  m_ExtraPaths.Add(m_MasterPath + sep + _T("bin") + sep + _T("ia32"));
233  if ( wxFileExists(m_MasterPath + sep + _T("bin") + sep + _T("intel64") + sep + m_Programs.C) )
234  m_ExtraPaths.Add(m_MasterPath + sep + _T("bin") + sep + _T("intel64"));
235 
236  if ( wxDirExists(m_MasterPath + sep + _T("include")) )
237  {
238  m_IncludeDirs.Insert(m_MasterPath + sep + _T("include"), 0);
239  m_ResIncludeDirs.Insert(m_MasterPath + sep + _T("include"), 0);
240  }
241  if ( wxDirExists(m_MasterPath + sep + _T("compiler") + sep + _T("include")) )
242  {
243  m_IncludeDirs.Insert(m_MasterPath + sep + _T("compiler") + sep + _T("include"), 0);
244  m_ResIncludeDirs.Insert(m_MasterPath + sep + _T("compiler") + sep + _T("include"), 0);
245  }
246 
247  if ( wxDirExists(m_MasterPath + sep + _T("lib")) )
248  {
249  m_IncludeDirs.Insert(m_MasterPath + sep + _T("lib"), 0);
250  m_ResIncludeDirs.Insert(m_MasterPath + sep + _T("lib"), 0);
251  }
252 
253  if ( wxDirExists(m_MasterPath + sep + _T("compiler") + sep + _T("lib")) )
254  m_LibDirs.Insert(m_MasterPath + sep + _T("compiler") + sep + _T("lib"), 0);
255  if ( wxDirExists(m_MasterPath + sep + _T("compiler") + sep + _T("lib") + sep + _T("ia32")) )
256  m_LibDirs.Insert(m_MasterPath + sep + _T("compiler") + sep + _T("lib") + sep + _T("ia32"), 0);
257  if ( wxDirExists(m_MasterPath + sep + _T("compiler") + sep + _T("lib") + sep + _T("intel64")) )
258  m_LibDirs.Insert(m_MasterPath + sep + _T("compiler") + sep + _T("lib") + sep + _T("intel64"), 0);
259  }
260  // Try to detect the debugger. If not detected successfully the debugger plugin will
261  // complain, so only the autodetection of compiler is considered in return value
262  wxString path;
263  wxString dbg;
264  if (platform::windows)
265  {
266  dbg = _T("idb.exe");
267  wxGetEnv(_T("IDB_PATH"), &path);
268  if ( !path.IsEmpty() && wxDirExists(path) )
269  {
270  int version = 9;
271  while ( true )
272  {
273  wxString idbPath = path + sep + _T("IDB") + sep + wxString::Format(_T("%d.0"), version) + sep + _T("IA32");
274  if ( wxDirExists(idbPath) )
275  {
276  path = idbPath; // found
277  break; // exit while-loop
278  }
279  else if (version>15)
280  break; // exit while-loop
281  else
282  version++;
283  }
284  }
285  }
286  else
287  {
288  dbg = _T("idb");
289  path = _T("/opt/intel/idb/9.0");
290  if ( wxDirExists(_T("/opt/intel")) )
291  {
292  wxDir icc_debug_dir(_T("/opt/intel/idb"));
293  if (icc_debug_dir.IsOpened())
294  {
295  wxArrayString debug_dirs;
296  wxIccDirTraverser IccDebugDirTraverser(debug_dirs);
297  icc_debug_dir.Traverse(IccDebugDirTraverser);
298  if (!debug_dirs.IsEmpty())
299  {
300  // Now sort the array in reverse order to get the latest version's path
301  debug_dirs.Sort(true);
302  path = debug_dirs[0];
303  }
304  }
305  }
306  }
307 
308  if ( wxFileExists(path + sep + _T("bin") + sep + dbg) )
309  m_ExtraPaths.Add(path);
310 
311  return ret;
312 }
wxString AfterLast(wxUniChar ch) const
bool wxGetEnv(const wxString &var, wxString *value)
virtual const wxString & GetMasterPath() const
Get the compiler&#39;s master path (must contain "bin", "include" and "lib")
Definition: compiler.h:295
const int version
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
bool IsOpened() const
#define wxICON_ERROR
bool wxFileExists(const wxString &filename)
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
wxArrayString m_ResIncludeDirs
wxIccDirTraverser(wxArrayString &folders)
Definition: compilerICC.cpp:30
bool wxDirExists(const wxString &dirname)
static Compiler * GetCompiler(size_t index)
virtual void Reset()
Reset settings to defaults.
Definition: compiler.cpp:157
#define _T(string)
virtual void AddIncludeDir(const wxString &option)
CompilerPrograms m_Programs
Definition: compiler.h:412
#define wxT(string)
#define wxNOT_FOUND
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
Definition: compilerICC.cpp:67
AutoDetectResult
Definition: compiler.h:190
wxArrayString & m_Dirs
Definition: compilerICC.cpp:51
wxUSE_UNICODE_dependent wxChar
size_t Traverse(wxDirTraverser &sink, const wxString &filespec=wxEmptyString, int flags=wxDIR_DEFAULT) const
virtual void AddResourceIncludeDir(const wxString &option)
bool Contains(const wxString &str) const
void Insert(wxString lItem, size_t nIndex, size_t copies=1)
virtual void AddLibDir(const wxString &option)
static const wxString sep
virtual const CompilerPrograms & GetPrograms() const
Get the compiler&#39;s programs.
Definition: compiler.h:299
virtual const wxArrayString & GetExtraPaths() const
Get the compiler&#39;s extra paths.
Definition: compiler.h:297
wxArrayString m_ExtraPaths
Definition: compiler.h:410
bool IsEmpty() const
static wxUniChar GetPathSeparator(wxPathFormat format=wxPATH_NATIVE)
#define wxOK
MacrosManager * GetMacrosManager() const
Definition: manager.cpp:454
const wxString & _(const wxString &string)
wxDirTraverseResult
void ReplaceMacros(wxString &buffer, ProjectBuildTarget *target=nullptr, bool subrequest=false)
virtual const wxArrayString & GetIncludeDirs() const
Abstract base class for compilers.
Definition: compiler.h:274
wxDirTraverseResult OnFile(const wxString &WXUNUSED(filename)) override
Definition: compilerICC.cpp:35
wxString & Append(const char *psz)
wxDirTraverseResult OnDir(const wxString &dirname) override
Definition: compilerICC.cpp:40
bool IsEmpty() const
virtual const wxArrayString & GetLibDirs() const
void Clear()
virtual ~CompilerICC()
Definition: compilerICC.cpp:62
wxString C
Definition: compiler.h:199
bool EndsWith(const wxString &suffix, wxString *rest=NULL) const
wxString m_MasterPath
Definition: compiler.h:409
size_t Add(const wxString &str, size_t copies=1)
void Sort(bool reverseOrder=false)
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
Definition: compilerICC.cpp:72
size_t GetCount() const
int m_Weight
Definition: compiler.h:422
int Printf(const wxString &pszFormat,...)
wxArrayString m_IncludeDirs
static wxString Format(const wxString &format,...)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395