2
* This file is part of lib_finder plugin for Code::Blocks Studio
3
* Copyright (C) 2007 Bartlomiej Swiecki
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.
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.
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
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 $
24
#include "pkgconfigmanager.h"
26
#include <wx/tokenzr.h>
29
PkgConfigManager::PkgConfigManager()
31
m_PkgConfigVersion = -1;
34
PkgConfigManager::~PkgConfigManager()
38
void PkgConfigManager::RefreshData()
40
if ( !DetectVersion() /*|| !LoadLibraries() */)
42
m_PkgConfigVersion = -1;
46
bool PkgConfigManager::DetectVersion()
49
if ( wxExecute(_T("pkg-config --version"),Output,wxEXEC_NODISABLE) != 0 )
51
// Some error, we can not talk to pkg-config
55
if ( Output.Count() < 1 )
57
// Did not receive version string
61
wxStringTokenizer VerTok(Output[0],_T("."));
62
long VersionNumbers[4] = { 0,0,0,0 };
63
int CurrentVersionToken = 0;
65
while ( VerTok.HasMoreTokens() && CurrentVersionToken<4 )
67
if ( !VerTok.GetNextToken().ToLong(&VersionNumbers[CurrentVersionToken++],10) )
74
if ( CurrentVersionToken==0 )
76
// No suitable version number found
81
((VersionNumbers[0]&0xFFL) << 24) |
82
((VersionNumbers[1]&0xFFL) << 16) |
83
((VersionNumbers[2]&0xFFL) << 8) |
84
((VersionNumbers[3]&0xFFL) << 0);
89
bool PkgConfigManager::DetectLibraries(ResultMap& Results)
91
if ( !IsPkgConfig() ) return false;
94
if ( wxExecute(_T("pkg-config --list-all"),Output,wxEXEC_NODISABLE) != 0 )
96
// Some error, we can not talk to pkg-config
101
for ( size_t i=0; i<Output.Count(); i++ )
104
wxString& Line = Output[i];
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
110
for ( j=0; j<Line.Length(); j++ )
113
if ( ch==_T('\0') || ch==_T(' ') || ch==_T('\t') )
119
if ( Name.IsEmpty() )
121
// Woow, what was that ?
126
while ( j<Line.Length() && (Line[j]==_T(' ') || Line[j]==_T('\t')) ) j++;
127
// After that, we have description
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);
141
void PkgConfigManager::Clear()
145
bool PkgConfigManager::UpdateTarget(const wxString& VarName,CompileTargetBase* Target,bool Force)
147
Target->AddCompilerOption(_T("`pkg-config ") + VarName + _T(" --cflags`"));
148
Target->AddLinkerOption (_T("`pkg-config ") + VarName + _T(" --libs`" ));