Code::Blocks  SVN r11506
compilerMINGWgenerator.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: 11069 $
6  * $Id: compilerMINGWgenerator.cpp 11069 2017-05-28 15:26:44Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilerMINGWgenerator.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "compilerMINGWgenerator.h"
12 #include <wx/intl.h>
13 #include "cbexception.h"
14 #include "cbproject.h"
15 #include "compilerfactory.h"
16 #include "compiler.h"
17 #include "manager.h"
18 #include "configmanager.h"
19 #include "logmanager.h"
20 #include "macrosmanager.h"
21 #include "scriptingmanager.h"
22 
24 {
25  //ctor
27 }
28 
30 {
31  //dtor
32 }
33 
35 {
36  wxString result = CompilerCommandGenerator::SetupIncludeDirs(compiler, target);
37  m_VerStr = compiler->GetVersionString();
38  wxString pch_prepend = wxEmptyString;
39  long gcc_major = 4;
40  if ( !m_VerStr.IsEmpty() )
41  m_VerStr.BeforeFirst('.').ToLong(&gcc_major);
42  bool HasPCH = false; // We don't know yet if there are any header files to be compiled...
43 
44  // for PCH to work, the very first include dir *must* be the object output dir
45  // *only* if PCH is generated in the object output dir
46  if (target &&
48  {
49  wxArrayString includedDirs; // avoid adding duplicate dirs...
50  wxString sep = wxFILE_SEP_PATH;
51  // find all PCH in project
52  for (ProjectFile *f : target->GetParentProject()->GetFilesList())
53  {
54  if (f->compile && FileTypeOf(f->relativeFilename) == ftHeader)
55  {
56  // it is a PCH; add it's object dir to includes
57  wxFileName fn(f->GetObjName());
58  wxString objName = (compiler->GetSwitches().UseFlatObjects) ? fn.GetFullName() : fn.GetFullPath();
59  wxString dir = wxFileName(target->GetObjectOutput() + sep + objName).GetPath();
60  if (includedDirs.Index(dir) == wxNOT_FOUND)
61  {
62  includedDirs.Add(dir);
64  if ( gcc_major < 4 )
65  pch_prepend << compiler->GetSwitches().includeDirs << dir << _T(' ');
66  else
67  pch_prepend << _T("-iquote") << dir << _T(' ');
68  }
69  HasPCH = true; // there is at least one header file to be compiled
70  }
71  }
72  // for gcc-4.0+, use the following:
73  // pch_prepend << _T("-iquote") << dir << _T(' ');
74  // for earlier versions, -I- must be used
75  if ( gcc_major < 4 )
76  pch_prepend << _T("-I- ");
77  int count = (int)includedDirs.GetCount();
78  for (int i = 0; i < count; ++i)
79  {
80  QuoteStringIfNeeded(includedDirs[i]);
81  pch_prepend << compiler->GetSwitches().includeDirs << includedDirs[i] << _T(' ');
82  }
83  pch_prepend << _T("-I. ");
84  }
85 
86  // add in array
87  if (HasPCH)
88  result.Prepend(pch_prepend);
89 
90  return result;
91 }
virtual FilesList & GetFilesList()
Provides an easy way to iterate all the files belonging in this target.
Definition: cbproject.h:685
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
PCHMode GetModeForPCH() const
Definition: cbproject.h:301
#define _T(string)
DLLIMPORT FileType FileTypeOf(const wxString &filename)
Definition: globals.cpp:285
#define wxNOT_FOUND
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
virtual cbProject * GetParentProject()
virtual wxString SetupIncludeDirs(Compiler *compiler, ProjectBuildTarget *target)
Setup compiler include dirs for build target.
wxString BeforeFirst(wxUniChar ch, wxString *rest=NULL) const
static const wxString sep
wxString includeDirs
Definition: compiler.h:212
wxString wxEmptyString
const wxString GetVersionString() const
Get the compiler version string.
Definition: compiler.h:365
DLLIMPORT void QuoteStringIfNeeded(wxString &str)
Definition: globals.cpp:260
virtual wxString SetupIncludeDirs(Compiler *compiler, ProjectBuildTarget *target)
Setup compiler include dirs for build target.
In a dir (named by the PCH) on the same level as the source header (default).
Definition: cbproject.h:86
bool ToLong(long *val, int base=10) const
Abstract base class for compilers.
Definition: compiler.h:274
bool IsEmpty() const
virtual const CompilerSwitches & GetSwitches() const
Get the compiler&#39;s generic switches.
Definition: compiler.h:301
wxString & Prepend(const wxString &str)
size_t Add(const wxString &str, size_t copies=1)
Represents a Code::Blocks project build target.
size_t GetCount() const
virtual wxString GetObjectOutput() const
Read the target&#39;s objects output dir.
bool UseFlatObjects
Definition: compiler.h:230