Repository navigation
Expand file tree
/
Copy pathUnrealEnginePython.Build.cs
More file actions
250 lines (222 loc) · 7.93 KB
/
Copy pathUnrealEnginePython.Build.cs
File metadata and controls
250 lines (222 loc) · 7.93 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
// 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 = "";
// 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/";
private string[] windowsKnownPaths =
{
"C:/Program Files/Python36",
"C:/Program Files/Python35",
"C:/Python27"
};
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",
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Sockets",
"Networking"
// ... 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"
});
}
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
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);
}
else if (Target.Platform == UnrealTargetPlatform.Mac)
{
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);
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 (pythonHome == "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 (pythonHome == "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");
}
}