forked from eranif/codelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompilerLocatorMSVCBase.cpp
226 lines (189 loc) · 7.42 KB
/
CompilerLocatorMSVCBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : CompilerLocatorMSVCBase.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "CompilerLocatorMSVCBase.h"
#include "compiler.h"
#include <globals.h>
#include <wx/tokenzr.h>
#ifdef __WXMSW__
# include <wx/msw/registry.h>
#endif
CompilerLocatorMSVCBase::CompilerLocatorMSVCBase()
{
}
CompilerLocatorMSVCBase::~CompilerLocatorMSVCBase()
{
}
void CompilerLocatorMSVCBase::AddTools(const wxString& masterFolder, const wxString& name)
{
wxFileName fnBinFolder(masterFolder, "");
fnBinFolder.RemoveLastDir();
fnBinFolder.RemoveLastDir();
fnBinFolder.AppendDir("VC");
fnBinFolder.AppendDir("bin");
wxString binFolder = fnBinFolder.GetPath();
wxFileName fnIdeFolder(masterFolder, "");
fnIdeFolder.RemoveLastDir();
fnIdeFolder.AppendDir("IDE");
wxFileName installPath(masterFolder, "");
installPath.RemoveLastDir();
installPath.RemoveLastDir();
CompilerPtr compiler( new Compiler(NULL, Compiler::kRegexVC) );
compiler->SetCompilerFamily(COMPILER_FAMILY_VC);
compiler->SetName( name );
compiler->SetInstallationPath(installPath.GetPath());
m_compilers.push_back( compiler );
wxFileName cxx(binFolder, "cl.exe");
// CXX
AddTool(cxx.GetFullPath(), "-nologo -FC -EHs", "CXX", compiler);
// CC
AddTool(cxx.GetFullPath(), "-nologo -FC", "CC", compiler);
// AR
cxx.SetFullName("lib.exe");
AddTool(cxx.GetFullPath(), "-nologo", "AR", compiler);
// SharedObjectLinkerName
cxx.SetFullName("link.exe");
AddTool(cxx.GetFullPath(), "-DLL -nologo", "SharedObjectLinkerName", compiler);
// LinkerName
AddTool(cxx.GetFullPath(), "-nologo", "LinkerName", compiler);
compiler->SetSwitch("ArchiveOutput", "/OUT:");
compiler->SetSwitch("Debug", "/Zi ");
compiler->SetSwitch("Include", "/I");
compiler->SetSwitch("Library", " ");
compiler->SetSwitch("LibraryPath", "/LIBPATH:");
compiler->SetSwitch("Object", "/Fo");
compiler->SetSwitch("Output", "/OUT:");
compiler->SetSwitch("Preprocessor", "/D");
compiler->SetSwitch("Source", "-c ");
compiler->SetObjectSuffix(".obj");
// Add SDK paths
FindSDKs(compiler);
// Add the global include path
wxFileName includePath(binFolder, "");
includePath.RemoveLastDir();
includePath.AppendDir("include");
wxString globalIncPath = compiler->GetGlobalIncludePath();
AddIncOrLibPath(includePath.GetPath(), globalIncPath);
compiler->SetGlobalIncludePath( globalIncPath );
// Add the global include path
wxFileName libpath(binFolder, "");
libpath.RemoveLastDir();
libpath.AppendDir("lib");
wxString globalLibPath = compiler->GetGlobalLibPath();
AddIncOrLibPath(libpath.GetPath(), globalLibPath);
compiler->SetGlobalLibPath( globalLibPath );
// IDE path
compiler->SetPathVariable(fnIdeFolder.GetPath() + ";$PATH");
}
void CompilerLocatorMSVCBase::AddTool(const wxString& toolpath, const wxString& extraArgs, const wxString& toolname, CompilerPtr compiler)
{
wxString tool = toolpath;
::WrapWithQuotes( tool );
if ( !extraArgs.IsEmpty() ) {
tool << " " << extraArgs;
}
compiler->SetTool(toolname, tool);
}
void CompilerLocatorMSVCBase::FindSDKs(CompilerPtr compiler)
{
#ifdef __WXMSW__
wxString sdkDir;
bool sdkfound = false;
wxRegKey key; // defaults to HKCR
// try to detect Platform SDK (old versions)
key.SetName(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Win32SDK\\Directories"));
if (key.Exists() && key.Open(wxRegKey::Read)) {
key.QueryValue(_T("Install Dir"), sdkDir);
if (!sdkDir.IsEmpty() && wxDirExists(sdkDir))
sdkfound = true;
key.Close();
}
// try to detect Platform SDK (newer versions)
wxString msPsdkKeyName[2] = { _T("HKEY_CURRENT_USER\\Software\\Microsoft\\MicrosoftSDK\\InstalledSDKs"),
_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows")
};
wxString msPsdkKeyValue[2] = { _T("Install Dir"), _T("InstallationFolder") };
for (int i = 0; i < 2; ++i) {
key.SetName(msPsdkKeyName[i]);
if (!sdkfound && key.Exists() && key.Open(wxRegKey::Read)) {
wxString name;
long idx;
bool cont = key.GetFirstKey(name, idx);
while(cont) {
wxRegKey subkey(key.GetName(), name);
if (subkey.Open(wxRegKey::Read) &&
(subkey.QueryValue(msPsdkKeyValue[i], sdkDir), !sdkDir.IsEmpty()) &&
wxDirExists(sdkDir)) {
sdkfound = true;
cont = false;
} else
cont = key.GetNextKey(name, idx);
subkey.Close();
}
key.Close();
}
if (sdkfound)
break;
}
if ( !sdkfound ) {
// Guess...
sdkDir = "C:\\Program Files"; // Default
wxGetEnv("ProgramFiles", &sdkDir);
sdkDir += wxT("\\Microsoft SDKs\\Windows\\v");
wxArrayString vers = ::wxStringTokenize("8.1A;8.1;8.0;7.1A;7.1;7.0A;7.0;6.1;6.0A;6.0", ";", wxTOKEN_STRTOK);
for (size_t i = 0; i < vers.GetCount(); ++i) {
wxString sdkVerDir;
sdkVerDir << sdkDir << vers.Item(i);
if ( ::wxDirExists( sdkVerDir ) && ::wxDirExists(sdkVerDir + "\\Include") ) {
sdkDir.swap( sdkVerDir );
sdkfound = true;
break;
}
}
}
if (sdkfound) {
if (sdkDir.GetChar(sdkDir.Length() - 1) != '\\')
sdkDir += wxFILE_SEP_PATH;
wxString incPath = compiler->GetGlobalIncludePath();
AddIncOrLibPath(sdkDir + _T("include"), incPath);
compiler->SetGlobalIncludePath(incPath);
wxString libPath = compiler->GetGlobalLibPath();
AddIncOrLibPath(sdkDir + _T("lib"), libPath);
compiler->SetGlobalLibPath(libPath);
}
#endif // __WXMSW__
}
void CompilerLocatorMSVCBase::AddIncOrLibPath(const wxString& path_to_add, wxString& add_to_me)
{
wxArrayString paths = wxStringTokenize(add_to_me, ";", wxTOKEN_STRTOK);
paths.Add( path_to_add );
wxString joinedPath;
for(size_t i=0; i<paths.GetCount(); ++i) {
joinedPath << paths.Item(i) << ";";
}
if ( !joinedPath.IsEmpty() ) {
joinedPath.RemoveLast();
}
joinedPath.swap( add_to_me );
}