@@ -59,265 +59,90 @@ if project.enabled:
5959 test .enabled = False
6060 engine .addBuildSuccessCallback (project .build )
6161
62- def getVisualStudio2015Compiler (targetArchitecture, ucrtVersion, windows10SdkVersion, vcInstallDir = None, windows10SdkBaseDir = None):
63-
64- from cake .msvs import getWindowsKitsDir, getMsvcProductDir
65- from cake .library .compilers .msvc import MsvcCompiler
66-
67- if vcInstallDir is None :
68- vcInstallDir = getMsvcProductDir (" VisualStudio\\ 14.0" )
69-
70- if windows10SdkBaseDir is None :
71- windows10SdkBaseDir = getWindowsKitsDir (version = " 10" )
72-
73- vcIncludeDir = cake .path .join (vcInstallDir, " include" )
74-
75- windows10SdkIncludeDirs = cake .path .join (windows10SdkBaseDir, " Include" , windows10SdkVersion, [" um" , " shared" ])
76-
77- ucrtIncludeDir = cake .path .join (windows10SdkBaseDir, " Include" , ucrtVersion, " ucrt" )
78-
79- if cake .system .isWindows64 ():
80- vcNativeBinDir = cake .path .join (vcInstallDir, " bin" , " amd64" )
81- else :
82- vcNativeBinDir = cake .path .join (vcInstallDir, " bin" )
83-
84- if targetArchitecture == " x64" :
85- if cake .system .isWindows64 ():
86- vcBinDir = vcNativeBinDir
87- else :
88- vcBinDir = cake .path .join (vcInstallDir, " bin" , " x86_amd64" )
89- vcLibDir = cake .path .join (vcInstallDir, " lib" , " amd64" )
90- windows10SdkBinDir = cake .path .join (windows10SdkBaseDir, " bin" , " x64" )
91- windows10SdkLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , windows10SdkVersion, " um" , " x64" )
92- ucrtLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , ucrtVersion, " ucrt" , " x64" )
93- elif targetArchitecture == " x86" :
94- if cake .system .isWindows64 ():
95- vcBinDir = cake .path .join (vcInstallDir, " bin" , " amd64_x86" )
96- else :
97- vcBinDir = vcNativeBinDir
98- vcLibDir = cake .path .join (vcInstallDir, " lib" )
99- windows10SdkBinDir = cake .path .join (windows10SdkBaseDir, " bin" , " x86" )
100- windows10SdkLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , windows10SdkVersion, " um" , " x86" )
101- ucrtLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , ucrtVersion, " ucrt" , " x86" )
102-
103- vcBinPaths = [vcBinDir]
104- if vcNativeBinDir != vcBinDir :
105- vcBinPaths .append (vcNativeBinDir)
106-
107- return MsvcCompiler (
108- configuration = configuration,
109- clExe = cake .path .join (vcBinDir, " cl.exe" ),
110- libExe = cake .path .join (vcBinDir, " lib.exe" ),
111- linkExe = cake .path .join (vcBinDir, " link.exe" ),
112- rcExe = cake .path .join (windows10SdkBinDir, " rc.exe" ),
113- mtExe = cake .path .join (windows10SdkBinDir, " mt.exe" ),
114- bscExe = None,
115- binPaths = vcBinPaths + [windows10SdkBinDir],
116- includePaths = [vcIncludeDir, ucrtIncludeDir] + windows10SdkIncludeDirs,
117- libraryPaths = [vcLibDir, ucrtLibDir, windows10SdkLibDir],
118- architecture = targetArchitecture,
119- )
120-
121- def findMsvc2017InstallDir (targetArchitecture):
122- """ Find the location of the MSVC 2017 install directory.
123-
124- Returns path of the latest VC install directory that contains a compiler
125- for the specified target architecture. Throws CompilerNotFoundError if
126- couldn't find any MSVC 2017 version.
127- """
128- # TODO: We are supposed to use the new COM API to lookup the installed
129- # locations of the VS 2017 build tools but I haven't figured out how to
130- # do this successfully from Python yet.
131- # We'll just use some simple heuristics to try and find it in the mean-time.
132- if cake .system .isWindows64 ():
133- programFiles = os .environ .get (' ProgramFiles(x86)' , r' C:\P rogram Files (x86)' )
134- else :
135- programFiles = os .environ .get (' ProgramFiles' , r' C:\P rogram Files' )
136-
137- vs2017BasePath = cake .path .join (programFiles, ' Microsoft Visual Studio' , ' 2017' )
138-
139- for edition in (' Enterprise' , ' Professional' , ' Community' ):
140- msvcBasePath = cake .path .join (vs2017BasePath, edition, r' VC\T ools\M SVC' )
141- if os .path .isdir (msvcBasePath):
142- versions = [v for v in os .listdir (msvcBasePath) if v .startswith (' 14.10.' )]
143- versions .sort (key = lambda x : int (x[len (' 14.10.' ): ]), reverse = True)
144- for version in versions :
145- msvcPath = cake .path .join (msvcBasePath, version)
146- if cake .system .isWindows64 ():
147- if os .path .isdir (cake .path .join (msvcPath, ' bin' , ' HostX64' , targetArchitecture)):
148- return msvcPath
149- else :
150- if os .path .isdir (cake .path .join (msvcPath, ' bin' , ' HostX86' , targetArchitecture)):
151- return msvcPath
152- else :
153- raise CompilerNotFoundError ()
154-
155- def getVisualStudio2017Compiler (targetArchitecture, ucrtVersion, windows10SdkVersion, vcInstallDir = None, windows10SdkBaseDir = None):
156-
157- from cake .msvs import getWindowsKitsDir
158- from cake .library .compilers .msvc import MsvcCompiler
159-
160- if vcInstallDir is None :
161- vcInstallDir = findMsvc2017InstallDir (targetArchitecture)
162-
163- if windows10SdkBaseDir is None :
164- windows10SdkBaseDir = getWindowsKitsDir (version = " 10" )
165-
166- vcIncludeDir = cake .path .join (vcInstallDir, " include" )
167-
168- windows10SdkIncludeDirs = cake .path .join (windows10SdkBaseDir, " Include" , windows10SdkVersion, [" um" , " shared" ])
169-
170- ucrtIncludeDir = cake .path .join (windows10SdkBaseDir, " Include" , ucrtVersion, " ucrt" )
171-
172- if cake .system .isWindows64 ():
173- vcNativeBinDir = cake .path .join (vcInstallDir, " bin" , " HostX64" , " x64" )
174- else :
175- vcNativeBinDir = cake .path .join (vcInstallDir, " bin" , " HostX86" , " x86" )
176-
177- if targetArchitecture == " x64" :
178- if cake .system .isWindows64 ():
179- vcBinDir = vcNativeBinDir
180- else :
181- vcBinDir = cake .path .join (vcInstallDir, " bin" , " HostX86" , " x64" )
182- vcLibDir = cake .path .join (vcInstallDir, " lib" , " x64" )
183- windows10SdkBinDir = cake .path .join (windows10SdkBaseDir, " bin" , " x64" )
184- windows10SdkLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , windows10SdkVersion, " um" , " x64" )
185- ucrtLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , ucrtVersion, " ucrt" , " x64" )
186- elif targetArchitecture == " x86" :
187- if cake .system .isWindows64 ():
188- vcBinDir = cake .path .join (vcInstallDir, " bin" , " HostX64" , " x86" )
189- else :
190- vcBinDir = vcNativeBinDir
191- vcLibDir = cake .path .join (vcInstallDir, " lib" , " x86" )
192- windows10SdkBinDir = cake .path .join (windows10SdkBaseDir, " bin" , " x86" )
193- windows10SdkLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , windows10SdkVersion, " um" , " x86" )
194- ucrtLibDir = cake .path .join (windows10SdkBaseDir, " Lib" , ucrtVersion, " ucrt" , " x86" )
195-
196- vcBinPaths = [vcBinDir]
197- if vcNativeBinDir != vcBinDir :
198- vcBinPaths .append (vcNativeBinDir)
199-
200- return MsvcCompiler (
201- configuration = configuration,
202- clExe = cake .path .join (vcBinDir, " cl.exe" ),
203- libExe = cake .path .join (vcBinDir, " lib.exe" ),
204- linkExe = cake .path .join (vcBinDir, " link.exe" ),
205- rcExe = cake .path .join (windows10SdkBinDir, " rc.exe" ),
206- mtExe = cake .path .join (windows10SdkBinDir, " mt.exe" ),
207- bscExe = None,
208- binPaths = vcBinPaths + [windows10SdkBinDir],
209- includePaths = [vcIncludeDir, ucrtIncludeDir] + windows10SdkIncludeDirs,
210- libraryPaths = [vcLibDir, ucrtLibDir, windows10SdkLibDir],
211- architecture = targetArchitecture,
212- )
213-
21462if cake .system .isWindows () or cake .system .isCygwin ():
215- for msvcVer in (" 14.10" ,):
216- for arch in (" x64" , " x86" ):
217- try :
218- msvcVariant = baseVariant .clone (
219- platform = " windows" ,
220- compiler = " msvc" + msvcVer,
221- compilerFamily = " msvc" ,
222- architecture = arch,
63+ # Uncomment the next line to use an experimental MSVC compiler version
64+ # downloaded from the http://vcppdogfooding.azurewebsites.net/ NuGet repository.
65+ # Unzip the .nuget file to a folder and specify the path here.
66+ nugetPath = None # r'C:\Path\To\VisualCppTools.14.0.25224-Pre'
67+
68+ for arch in (" x64" , " x86" ):
69+ try :
70+ if nugetPath :
71+ from cake .library .compilers .msvc import getVisualStudio2015Compiler
72+ compiler = getVisualStudio2015Compiler (
73+ configuration,
74+ targetArchitecture = arch,
75+ vcInstallDir = cake .path .join (extractedNugetPath, ' Lib' , ' native' ),
22376 )
224-
225- project = msvcVariant .tools [" project" ]
226- project .solutionPlatformName = " Windows " + arch + " (Msvc " + msvcVer + " )"
227- if arch == " x86" :
228- project .projectPlatformName = " Win32"
229- elif arch == " x64" :
230- project .projectPlatformName = " x64"
231-
232- windows10SdkVersion = " 10.0.10586.0"
233- ucrtVersion = windows10SdkVersion
234-
235- if msvcVer == " 14.0" :
236- msvcVariant .tools [" compiler" ] = compiler = getVisualStudio2015Compiler (
237- targetArchitecture = arch,
238- ucrtVersion = ucrtVersion,
239- windows10SdkVersion = windows10SdkVersion,
240- vcInstallDir = None, # Or path to unzipped .nuget package
241- windows10SdkBaseDir = None, # Or path to unzipped Windows 10 SDK
242- )
243- elif msvcVer == " 14.10" :
244- nugetPath = None
245-
246- # Uncomment the next line to use an experimental MSVC compiler version
247- # downloaded from the http://vcppdogfooding.azurewebsites.net/ NuGet repository.
248- # Unzip the .nuget file to a folder and specify the path here.
249- # nugetPath = r'C:\Path\To\VisualCppTools.14.0.25224-Pre'
250-
251- if nugetPath :
252- # NuGet package for VS 2017 has same layout as VS 2015.
253- compiler = getVisualStudio2015Compiler (
254- targetArchitecture = arch,
255- ucrtVersion = ucrtVersion,
256- windows10SdkVersion = windows10SdkVersion,
257- vcInstallDir = cake .path .join (nugetPath, ' lib' , ' native' ),
258- windows10SdkBaseDir = None, # Or path to unzipped Windows 10 SDK
259- )
260- else :
261- # Otherwise, try to use the installed MSVC compiler
262- compiler = getVisualStudio2017Compiler (
263- targetArchitecture = arch,
264- ucrtVersion = ucrtVersion,
265- windows10SdkVersion = windows10SdkVersion,
266- vcInstallDir = None, # Or path to unzipped .nuget package
267- windows10SdkBaseDir = None, # Or path to unzipped Windows 10 SDK
268- )
269- msvcVariant .tools [" compiler" ] = compiler
270-
271- if engine .options .createProjects :
272- compiler .enabled = False
273-
274- compiler .enableRtti = True
275- compiler .enableExceptions = True
276- compiler .outputMapFile = True
277- compiler .outputFullPath = True
278- compiler .messageStyle = compiler .MSVS_CLICKABLE
279- compiler .warningLevel = ' 3'
280- compiler .warningsAsErrors = True
281-
282- # Enable experimental C++ coroutines via command-line flag.
283- compiler .addCppFlag (' /await' )
284-
285- # Enable C++17 features like std::optional<>
286- compiler .addCppFlag (' /std:c++latest' )
287-
288- env = msvcVariant .tools [" env" ]
289- env[" COMPILER" ] = " msvc"
290- env[" COMPILER_VERSION" ] = msvcVer
291- env[" PLATFORM" ] = " windows"
292- env[" ARCHITECTURE" ] = arch
293-
294- # Visual Studio - Debug
295- msvcDebugVariant = msvcVariant .clone (release = " debug" )
296- msvcDebugVariant .tools [" env" ][" RELEASE" ] = " debug"
297- compiler = msvcDebugVariant .tools [" compiler" ]
298- compiler .debugSymbols = True
299- compiler .useIncrementalLinking = True
300- compiler .optimisation = compiler .NO_OPTIMISATION
301- compiler .runtimeLibraries = ' debug-dll'
302- project = msvcDebugVariant .tools [" project" ]
303- project .projectConfigName = " Windows (" + arch + " ) Msvc " + msvcVer + " (Debug)"
304- project .solutionConfigName = " Debug"
305- configuration .addVariant (msvcDebugVariant)
306-
307- # Visual Studio - Optimised
308- msvcOptVariant = msvcVariant .clone (release = " optimised" )
309- msvcOptVariant .tools [" env" ][" RELEASE" ] = " optimised"
310- compiler = msvcOptVariant .tools [" compiler" ]
311- compiler .debugSymbols = True
312- compiler .useIncrementalLinking = False
313- compiler .useFunctionLevelLinking = True
314- compiler .optimisation = compiler .FULL_OPTIMISATION
315- compiler .runtimeLibraries = ' release-dll'
316- compiler .addDefine (' NDEBUG' )
317- project = msvcOptVariant .tools [" project" ]
318- project .projectConfigName = " Windows (" + arch + " ) Msvc " + msvcVer + " (Optimised)"
319- project .solutionConfigName = " Optimised"
320- configuration .addVariant (msvcOptVariant)
321-
322- except CompilerNotFoundError :
323- pass
77+ else :
78+ from cake .library .compilers .msvc import getVisualStudio2017Compiler
79+ compiler = getVisualStudio2017Compiler (configuration, targetArchitecture = arch)
80+
81+ msvcVariant = baseVariant .clone (
82+ platform = " windows" ,
83+ compiler = " msvc" ,
84+ architecture = arch,
85+ )
86+
87+ msvcVariant .tools [" compiler" ] = compiler
88+
89+ project = msvcVariant .tools [" project" ]
90+ project .solutionPlatformName = " Windows " + arch
91+ if arch == " x86" :
92+ project .projectPlatformName = " Win32"
93+ elif arch == " x64" :
94+ project .projectPlatformName = " x64"
95+
96+ if engine .options .createProjects :
97+ compiler .enabled = False
98+
99+ compiler .enableRtti = True
100+ compiler .enableExceptions = True
101+ compiler .outputMapFile = True
102+ compiler .outputFullPath = True
103+ compiler .messageStyle = compiler .MSVS_CLICKABLE
104+ compiler .warningLevel = ' 3'
105+ compiler .warningsAsErrors = True
106+
107+ # Enable experimental C++ coroutines via command-line flag.
108+ compiler .addCppFlag (' /await' )
109+
110+ # Enable C++17 features like std::optional<>
111+ compiler .addCppFlag (' /std:c++latest' )
112+
113+ env = msvcVariant .tools [" env" ]
114+ env[" COMPILER" ] = " msvc"
115+ env[" COMPILER_VERSION" ] = " 15"
116+ env[" PLATFORM" ] = " windows"
117+ env[" ARCHITECTURE" ] = arch
118+
119+ # Visual Studio - Debug
120+ msvcDebugVariant = msvcVariant .clone (release = " debug" )
121+ msvcDebugVariant .tools [" env" ][" RELEASE" ] = " debug"
122+ compiler = msvcDebugVariant .tools [" compiler" ]
123+ compiler .debugSymbols = True
124+ compiler .useIncrementalLinking = True
125+ compiler .optimisation = compiler .NO_OPTIMISATION
126+ compiler .runtimeLibraries = ' debug-dll'
127+ project = msvcDebugVariant .tools [" project" ]
128+ project .projectConfigName = " Windows (" + arch + " ) Msvc (Debug)"
129+ project .solutionConfigName = " Msvc Debug"
130+ configuration .addVariant (msvcDebugVariant)
131+
132+ # Visual Studio - Optimised
133+ msvcOptVariant = msvcVariant .clone (release = " optimised" )
134+ msvcOptVariant .tools [" env" ][" RELEASE" ] = " optimised"
135+ compiler = msvcOptVariant .tools [" compiler" ]
136+ compiler .debugSymbols = True
137+ compiler .useIncrementalLinking = False
138+ compiler .useFunctionLevelLinking = True
139+ compiler .optimisation = compiler .FULL_OPTIMISATION
140+ compiler .runtimeLibraries = ' release-dll'
141+ compiler .addDefine (' NDEBUG' )
142+ project = msvcOptVariant .tools [" project" ]
143+ project .projectConfigName = " Windows (" + arch + " ) Msvc (Optimised)"
144+ project .solutionConfigName = " Msvc Optimised"
145+ configuration .addVariant (msvcOptVariant)
146+
147+ except CompilerNotFoundError, e :
148+ print str (e)
0 commit comments