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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/lib_finder/pkgconfigmanager.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 lib_finder plugin for Code::Blocks Studio
 
3
* Copyright (C) 2007  Bartlomiej Swiecki
 
4
*
 
5
* wxSmith is free software; you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License as published by
 
7
* the Free Software Foundation; either version 2 of the License, or
 
8
* (at your option) any later version.
 
9
*
 
10
* wxSmith is distributed in the hope that it will be useful,
 
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
* GNU General Public License for more details.
 
14
*
 
15
* You should have received a copy of the GNU General Public License
 
16
* along with wxSmith; if not, write to the Free Software
 
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 
18
*
 
19
* $Revision: 4504 $
 
20
* $Id: wxsmithpluginregistrants.cpp 4504 2007-10-02 21:52:30Z byo $
 
21
* $HeadURL: svn+ssh://byo@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/wxSmith/plugin/wxsmithpluginregistrants.cpp $
 
22
*/
 
23
 
 
24
#include "pkgconfigmanager.h"
 
25
#include <wx/utils.h>
 
26
#include <wx/tokenzr.h>
 
27
#include <wx/intl.h>
 
28
 
 
29
PkgConfigManager::PkgConfigManager()
 
30
{
 
31
    m_PkgConfigVersion = -1;
 
32
}
 
33
 
 
34
PkgConfigManager::~PkgConfigManager()
 
35
{
 
36
}
 
37
 
 
38
void PkgConfigManager::RefreshData()
 
39
{
 
40
    if ( !DetectVersion() /*|| !LoadLibraries() */)
 
41
    {
 
42
        m_PkgConfigVersion = -1;
 
43
    }
 
44
}
 
45
 
 
46
bool PkgConfigManager::DetectVersion()
 
47
{
 
48
    wxArrayString Output;
 
49
    if ( wxExecute(_T("pkg-config --version"),Output,wxEXEC_NODISABLE) != 0 )
 
50
    {
 
51
        // Some error, we can not talk to pkg-config
 
52
        return false;
 
53
    }
 
54
 
 
55
    if ( Output.Count() < 1 )
 
56
    {
 
57
        // Did not receive version string
 
58
        return false;
 
59
    }
 
60
 
 
61
    wxStringTokenizer VerTok(Output[0],_T("."));
 
62
    long VersionNumbers[4] = { 0,0,0,0 };
 
63
    int CurrentVersionToken = 0;
 
64
 
 
65
    while ( VerTok.HasMoreTokens() && CurrentVersionToken<4 )
 
66
    {
 
67
        if ( !VerTok.GetNextToken().ToLong(&VersionNumbers[CurrentVersionToken++],10) )
 
68
        {
 
69
            // Incorrect version
 
70
            return false;
 
71
        }
 
72
    }
 
73
 
 
74
    if ( CurrentVersionToken==0 )
 
75
    {
 
76
        // No suitable version number found
 
77
        return false;
 
78
    }
 
79
 
 
80
    m_PkgConfigVersion =
 
81
        ((VersionNumbers[0]&0xFFL) << 24) |
 
82
        ((VersionNumbers[1]&0xFFL) << 16) |
 
83
        ((VersionNumbers[2]&0xFFL) <<  8) |
 
84
        ((VersionNumbers[3]&0xFFL) <<  0);
 
85
 
 
86
    return true;
 
87
}
 
88
 
 
89
bool PkgConfigManager::DetectLibraries(ResultMap& Results)
 
90
{
 
91
    if ( !IsPkgConfig() ) return false;
 
92
 
 
93
    wxArrayString Output;
 
94
    if ( wxExecute(_T("pkg-config --list-all"),Output,wxEXEC_NODISABLE) != 0 )
 
95
    {
 
96
        // Some error, we can not talk to pkg-config
 
97
        return false;
 
98
    }
 
99
 
 
100
    Results.Clear();
 
101
    for ( size_t i=0; i<Output.Count(); i++ )
 
102
    {
 
103
        wxString Name;
 
104
        wxString& Line = Output[i];
 
105
 
 
106
        // Get the name
 
107
        // NOTE: This may not be accurate since library name is mapped to filename
 
108
        //       so white chars can be used as part of the name
 
109
        size_t j;
 
110
        for ( j=0; j<Line.Length(); j++ )
 
111
        {
 
112
            wxChar ch = Line[j];
 
113
            if ( ch==_T('\0') || ch==_T(' ') || ch==_T('\t') )
 
114
            {
 
115
                break;
 
116
            }
 
117
            Name += ch;
 
118
        }
 
119
        if ( Name.IsEmpty() )
 
120
        {
 
121
            // Woow, what was that ?
 
122
            continue;
 
123
        }
 
124
 
 
125
        // Eat white
 
126
        while ( j<Line.Length() && (Line[j]==_T(' ') || Line[j]==_T('\t')) ) j++;
 
127
        // After that, we have description
 
128
 
 
129
        LibraryResult* Result = new LibraryResult();
 
130
        Result->Type = rtPkgConfig;
 
131
//        Result->LibraryName =
 
132
        Result->ShortCode = Name;
 
133
        Result->PkgConfigVar = Name;
 
134
        Result->Description = Line.Mid(j);
 
135
        Results.GetShortCode(Name).push_back(Result);
 
136
    }
 
137
 
 
138
    return true;
 
139
}
 
140
 
 
141
void PkgConfigManager::Clear()
 
142
{
 
143
}
 
144
 
 
145
bool PkgConfigManager::UpdateTarget(const wxString& VarName,CompileTargetBase* Target,bool Force)
 
146
{
 
147
    Target->AddCompilerOption(_T("`pkg-config ") + VarName + _T(" --cflags`"));
 
148
    Target->AddLinkerOption  (_T("`pkg-config ") + VarName + _T(" --libs`"  ));
 
149
    return true;
 
150
}