Repository navigation
Expand file tree
/
Copy pathUnrealEnginePython.Build.cs
More file actions
321 lines (281 loc) · 10.7 KB
/
Copy pathUnrealEnginePython.Build.cs
File metadata and controls
321 lines (281 loc) · 10.7 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.IO;
public class UnrealEnginePython : ModuleRules
{
// leave this string as empty for triggering auto-discovery of python installations...
private string PythonHome = "";
bool UseThirdPartyPython = true; //embedded
//Or use the one included in third party folder
protected string ThirdPartyPythonHome
{
get
{
return Path.GetFullPath(Path.Combine(ThirdPartyPath, PythonType));
}
}
// otherwise specify the path of your python installation
//private string PythonHome = "C:/Program Files/Python36";
// this is an example for Homebrew on Mac
//private string PythonHome = "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/";
//Swap python versions here
private string PythonType = "Python35";
//private string PythonType = "python27";
private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
}
private string[] windowsKnownPaths =
{
"C:/Program Files/Python36",
"C:/Program Files/Python35",
"C:/Python27",
"C:/IntelPython35"
};
private string[] macKnownPaths =
{
"/Library/Frameworks/Python.framework/Versions/3.6",
"/Library/Frameworks/Python.framework/Versions/3.5",
"/Library/Frameworks/Python.framework/Versions/2.7",
};
public UnrealEnginePython(TargetInfo Target)
{
PublicIncludePaths.AddRange(
new string[] {
"UnrealEnginePython/Public",
// ... add public include paths required here ...
}
);
PrivateIncludePaths.AddRange(
new string[] {
"UnrealEnginePython/Private",
PythonHome,
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Sockets",
"Networking",
"Projects"
// ... add other public dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"InputCore",
"Slate",
"SlateCore",
"MovieScene",
"LevelSequence",
// ... add private dependencies that you statically link with here ...
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
if (UEBuildConfiguration.bBuildEditor)
{
PrivateDependencyModuleNames.AddRange(new string[]{
"UnrealEd",
"LevelEditor",
"BlueprintGraph",
"Projects",
"Sequencer",
"SequencerWidgets",
"AssetTools",
"LevelSequenceEditor",
"MovieSceneTools",
"MovieSceneTracks",
"CinematicCamera",
"EditorStyle",
"UMGEditor",
});
}
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
if(UseThirdPartyPython)
{
PythonHome = ThirdPartyPythonHome;
System.Console.WriteLine("Using Python at: " + PythonHome);
PublicIncludePaths.Add(PythonHome);
string libPath = Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType.ToLower()));
System.Console.WriteLine("full lib path: " + libPath);
PublicLibraryPaths.Add(Path.GetDirectoryName(libPath));
PublicAdditionalLibraries.Add(libPath);
}
else if (PythonHome == "")
{
PythonHome = DiscoverPythonPath(windowsKnownPaths);
if (PythonHome == "")
{
throw new System.Exception("Unable to find Python installation");
}
System.Console.WriteLine("Using Python at: " + PythonHome);
PublicIncludePaths.Add(PythonHome);
string libPath = GetWindowsPythonLibFile(PythonHome);
PublicLibraryPaths.Add(Path.GetDirectoryName(libPath));
PublicAdditionalLibraries.Add(libPath);
}
}
//other platforms
else
{
if (PythonHome == "")
{
PythonHome = DiscoverPythonPath(macKnownPaths);
if (PythonHome == "")
{
throw new System.Exception("Unable to find Python installation");
}
System.Console.WriteLine("Using Python at: " + PythonHome);
PublicIncludePaths.Add(PythonHome);
PublicAdditionalLibraries.Add(Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType)));
}
else if (Target.Platform == UnrealTargetPlatform.Mac)
{
if (PythonType == "Python35")
{
string mac_python = "/Library/Frameworks/Python.framework/Versions/3.5/";
PublicIncludePaths.Add(Path.Combine(mac_python, "include"));
PublicAdditionalLibraries.Add(Path.Combine(mac_python, "lib", "libpython3.5m.dylib"));
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC=3"));
}
else if (PythonType == "Python27")
{
string mac_python = "/Library/Frameworks/Python.framework/Versions/2.7/";
PublicIncludePaths.Add(Path.Combine(mac_python, "include"));
PublicAdditionalLibraries.Add(Path.Combine(mac_python, "lib", "libpython2.7.dylib"));
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC=2"));
}
System.Console.WriteLine("Using Python at: " + PythonHome);
PublicIncludePaths.Add(PythonHome);
string libPath = GetMacPythonLibFile(PythonHome);
PublicLibraryPaths.Add(Path.GetDirectoryName(libPath));
PublicDelayLoadDLLs.Add(libPath);
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC"));
}
else if (Target.Platform == UnrealTargetPlatform.Linux)
{
if (PythonType == "Python35")
{
PublicIncludePaths.Add("/usr/include/python3.5m");
PublicAdditionalLibraries.Add("/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so");
}
else if (PythonType == "Python27")
{
PublicIncludePaths.Add("/usr/include/python2.7");
PublicAdditionalLibraries.Add("/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so");
}
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_LINUX"));
}
}
}
private string DiscoverPythonPath(string[] knownPaths)
{
foreach (string path in knownPaths)
{
string headerFile = Path.Combine(path, "include", "Python.h");
if (File.Exists(headerFile))
{
return path;
}
// this is mainly useful for OSX
headerFile = Path.Combine(path, "Headers", "Python.h");
if (File.Exists(headerFile))
{
return path;
}
}
return "";
}
private string GetMacPythonLibFile(string basePath)
{
// first try with python3
for (int i = 9; i >= 0; i--)
{
string fileName = string.Format("libpython3.{0}.dylib", i);
string fullPath = Path.Combine(basePath, "lib", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
fileName = string.Format("libpython3.{0}m.dylib", i);
fullPath = Path.Combine(basePath, "lib", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
}
// then python2
for (int i = 9; i >= 0; i--)
{
string fileName = string.Format("libpython2.{0}.dylib", i);
string fullPath = Path.Combine(basePath, "lib", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
fileName = string.Format("libpython2.{0}m.dylib", i);
fullPath = Path.Combine(basePath, "lib", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
}
throw new System.Exception("Invalid Python installation, missing .dylib files");
}
private string GetWindowsPythonLibFile(string basePath)
{
// just for usability, report if the PythonHome is not in the system path
string[] allPaths = System.Environment.GetEnvironmentVariable("PATH").Split(';');
// this will transform the slashes in backslashes...
string checkedPath = Path.GetFullPath(basePath);
if (checkedPath.EndsWith("\\"))
{
checkedPath = checkedPath.Remove(checkedPath.Length - 1);
}
bool found = false;
foreach (string item in allPaths)
{
if (item == checkedPath || item == checkedPath + "\\")
{
found = true;
break;
}
}
if (!found)
{
System.Console.WriteLine("[WARNING] Your Python installation is not in the system PATH environment variable, very probably the plugin will fail to load");
}
// first try with python3
for (int i = 9; i >= 0; i--)
{
string fileName = string.Format("python3{0}.lib", i);
string fullPath = Path.Combine(basePath, "libs", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
}
// then python2
for (int i = 9; i >= 0; i--)
{
string fileName = string.Format("python2{0}.lib", i);
string fullPath = Path.Combine(basePath, "libs", fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
}
throw new System.Exception("Invalid Python installation, missing .lib files");
}
}