~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/compilergcc/compilerMINGWgenerator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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$
 
6
 * $Id$
 
7
 * $HeadURL$
 
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
 
 
23
CompilerMINGWGenerator::CompilerMINGWGenerator()
 
24
{
 
25
    //ctor
 
26
    m_VerStr = wxEmptyString;
 
27
}
 
28
 
 
29
CompilerMINGWGenerator::~CompilerMINGWGenerator()
 
30
{
 
31
    //dtor
 
32
}
 
33
 
 
34
wxString CompilerMINGWGenerator::SetupIncludeDirs(Compiler* compiler, ProjectBuildTarget* target)
 
35
{
 
36
    wxString result = CompilerCommandGenerator::SetupIncludeDirs(compiler, target);
 
37
    m_VerStr = compiler->GetVersionString();
 
38
    wxString pch_prepend;
 
39
    bool IsGcc4 = m_VerStr.Left(1).IsSameAs(_T("4"));
 
40
 
 
41
    // for PCH to work, the very first include dir *must* be the object output dir
 
42
    // *only* if PCH is generated in the object output dir
 
43
    if (target &&
 
44
        target->GetParentProject()->GetModeForPCH() == pchObjectDir)
 
45
    {
 
46
        wxArrayString includedDirs; // avoid adding duplicate dirs...
 
47
        wxString sep = wxFILE_SEP_PATH;
 
48
        // find all PCH in project
 
49
        int count = target->GetParentProject()->GetFilesCount();
 
50
        for (int i = 0; i < count; ++i)
 
51
        {
 
52
            ProjectFile* f = target->GetParentProject()->GetFile(i);
 
53
            if (FileTypeOf(f->relativeFilename) == ftHeader &&
 
54
                f->compile)
 
55
            {
 
56
                // it is a PCH; add it's object dir to includes
 
57
                wxString dir = wxFileName(target->GetObjectOutput() + sep + f->GetObjName()).GetPath();
 
58
                if (includedDirs.Index(dir) == wxNOT_FOUND)
 
59
                {
 
60
                    includedDirs.Add(dir);
 
61
                    QuoteStringIfNeeded(dir);
 
62
                    if (!IsGcc4)
 
63
                        pch_prepend << compiler->GetSwitches().includeDirs << dir << _T(' ');
 
64
                    else
 
65
                        pch_prepend << _T("-iquote") << dir << _T(' ');
 
66
                }
 
67
            }
 
68
        }
 
69
        // for gcc-4.0+, use the following:
 
70
        // pch_prepend << _T("-iquote") << dir << _T(' ');
 
71
        // for earlier versions, -I- must be used
 
72
        if (!IsGcc4)
 
73
            pch_prepend << _T("-I- ");
 
74
        count = (int)includedDirs.GetCount();
 
75
        for (int i = 0; i < count; ++i)
 
76
        {
 
77
            QuoteStringIfNeeded(includedDirs[i]);
 
78
            pch_prepend << compiler->GetSwitches().includeDirs << includedDirs[i] << _T(' ');
 
79
        }
 
80
        pch_prepend << _T("-I. ");
 
81
        result.Prepend(pch_prepend);
 
82
    }
 
83
 
 
84
    // add in array
 
85
    return result;
 
86
}