@@ -19,6 +19,13 @@ public class UnrealEnginePython : ModuleRules
1919 "C:/Python27"
2020 } ;
2121
22+ private string [ ] macKnownPaths =
23+ {
24+ "/Library/Frameworks/Python.framework/Versions/3.6" ,
25+ "/Library/Frameworks/Python.framework/Versions/3.5" ,
26+ "/Library/Frameworks/Python.framework/Versions/2.7" ,
27+ } ;
28+
2229 public UnrealEnginePython ( TargetInfo Target )
2330 {
2431
@@ -97,20 +104,18 @@ public UnrealEnginePython(TargetInfo Target)
97104 }
98105 else if ( Target . Platform == UnrealTargetPlatform . Mac )
99106 {
100- if ( pythonHome == "python35" )
101- {
102- string mac_python = "/Library/Frameworks/Python.framework/Versions/3.5/" ;
103- PublicIncludePaths . Add ( Path . Combine ( mac_python , "include" ) ) ;
104- PublicAdditionalLibraries . Add ( Path . Combine ( mac_python , "lib" , "libpython3.5m.dylib" ) ) ;
105- Definitions . Add ( string . Format ( "UNREAL_ENGINE_PYTHON_ON_MAC=3" ) ) ;
106- }
107- else if ( pythonHome == "python27" )
107+ if ( pythonHome == "" )
108108 {
109- string mac_python = "/Library/Frameworks/Python.framework/Versions/2.7/" ;
110- PublicIncludePaths . Add ( Path . Combine ( mac_python , "include" ) ) ;
111- PublicAdditionalLibraries . Add ( Path . Combine ( mac_python , "lib" , "libpython2.7.dylib" ) ) ;
112- Definitions . Add ( string . Format ( "UNREAL_ENGINE_PYTHON_ON_MAC=2" ) ) ;
109+ pythonHome = DiscoverPythonPath ( macKnownPaths ) ;
110+ if ( pythonHome == "" )
111+ {
112+ throw new System . Exception ( "Unable to find Python installation" ) ;
113+ }
113114 }
115+ System . Console . WriteLine ( "Using Python at: " + pythonHome ) ;
116+ PublicIncludePaths . Add ( pythonHome ) ;
117+ PublicAdditionalLibraries . Add ( GetMacPythonLibFile ( pythonHome ) ) ;
118+ Definitions . Add ( string . Format ( "UNREAL_ENGINE_PYTHON_ON_MAC" ) ) ;
114119 }
115120 else if ( Target . Platform == UnrealTargetPlatform . Linux )
116121 {
@@ -148,6 +153,45 @@ private string DiscoverPythonPath(string[] knownPaths)
148153 return "" ;
149154 }
150155
156+ private string GetMacPythonLibFile ( string basePath )
157+ {
158+ // first try with python3
159+ for ( int i = 9 ; i >= 0 ; i -- )
160+ {
161+ string fileName = string . Format ( "libpython3.{0}.dylib" , i ) ;
162+ string fullPath = Path . Combine ( basePath , "lib" , fileName ) ;
163+ if ( File . Exists ( fullPath ) )
164+ {
165+ return fullPath ;
166+ }
167+ fileName = string . Format ( "libpython3.{0}m.dylib" , i ) ;
168+ fullPath = Path . Combine ( basePath , "lib" , fileName ) ;
169+ if ( File . Exists ( fullPath ) )
170+ {
171+ return fullPath ;
172+ }
173+ }
174+
175+ // then python2
176+ for ( int i = 9 ; i >= 0 ; i -- )
177+ {
178+ string fileName = string . Format ( "libpython2.{0}.dylib" , i ) ;
179+ string fullPath = Path . Combine ( basePath , "lib" , fileName ) ;
180+ if ( File . Exists ( fullPath ) )
181+ {
182+ return fullPath ;
183+ }
184+ fileName = string . Format ( "libpython2.{0}m.dylib" , i ) ;
185+ fullPath = Path . Combine ( basePath , "lib" , fileName ) ;
186+ if ( File . Exists ( fullPath ) )
187+ {
188+ return fullPath ;
189+ }
190+ }
191+
192+ throw new System . Exception ( "Invalid Python installation, missing .dylib files" ) ;
193+ }
194+
151195 private string GetWindowsPythonLibFile ( string basePath )
152196 {
153197 // just for usability, report if the pythonHome is not in the system path
0 commit comments