2021-03-17 22:22:43 +00:00
|
|
|
/* ###
|
2021-09-27 12:16:14 +00:00
|
|
|
* IP: Public Domain
|
2021-03-17 22:22:43 +00:00
|
|
|
*/
|
2019-09-10 20:03:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Establish Visual Studio configuration environment for Windows native builds
|
|
|
|
*
|
|
|
|
* NOTE: We do not rely on the VisualCpp plugin to identify paths since it has
|
|
|
|
* proven in the past to be unreliable when multiple versions of Visual Studio
|
|
|
|
* and SDKs are installed.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-01 14:14:42 +00:00
|
|
|
if (!hasProperty("VISUAL_STUDIO_INSTALL_DIR")) {
|
2019-09-10 20:03:25 +00:00
|
|
|
configureVisualStudio()
|
|
|
|
}
|
|
|
|
|
|
|
|
def configureVisualStudio() {
|
|
|
|
|
2021-07-07 13:25:39 +00:00
|
|
|
if (isCurrentWindows()) {
|
2019-11-13 16:22:38 +00:00
|
|
|
|
|
|
|
// Initialize variables
|
|
|
|
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = ""
|
|
|
|
rootProject.ext.VISUAL_STUDIO_TOOLS_VERSION_DEFAULT = ""
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_DIR_DEFAULT = ""
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_VERSION_DEFAULT = ""
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_VERSION_OVERRIDE = ""
|
|
|
|
rootProject.ext.VISUAL_STUDIO_VCVARS_CMD = ""
|
2019-09-10 20:03:25 +00:00
|
|
|
|
2019-11-01 14:14:42 +00:00
|
|
|
// Use vswhere.exe to search for latest Visual Studio installation
|
|
|
|
println "Searching for latest Visual Studio and required components..."
|
2023-07-17 15:59:01 +00:00
|
|
|
def programFiles = System.getenv()["ProgramFiles(x86)"] ?: "C:\\Program Files (x86)"
|
|
|
|
def vswherePath = findProperty("vswherePath") ?: "${programFiles}\\Microsoft Visual Studio\\Installer\\vswhere.exe"
|
2019-11-01 14:14:42 +00:00
|
|
|
if (!file(vswherePath).exists()) {
|
2023-07-17 15:59:01 +00:00
|
|
|
println " -> Visual Studio vswhere.exe not found at \"${vswherePath}\""
|
|
|
|
println " -> To manually specify the location of vswhere.exe, add \"-PvswherePath=<vswhere path>\" to the Gradle command line arguments"
|
2019-11-13 16:22:38 +00:00
|
|
|
return
|
2019-11-01 14:14:42 +00:00
|
|
|
}
|
2023-07-20 12:58:13 +00:00
|
|
|
def vswhereProcess = "\"${vswherePath}\" -products * -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -format json -utf8".execute()
|
2022-12-07 17:40:53 +00:00
|
|
|
def vswhereOutput = vswhereProcess.text.trim()
|
|
|
|
def vswhereExit = vswhereProcess.exitValue()
|
|
|
|
if (vswhereExit != 0) {
|
|
|
|
if (vswhereExit == 87) { // ERROR_INVALID_PARAMATER
|
|
|
|
println " -> Visual Studio vswhere.exe was passed an unsupported argument!"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println " -> Visual Studio vswhere.exe returned an error code (${vswhereExit})!"
|
|
|
|
}
|
|
|
|
println " -> Please confirm ${vswherePath} is version 2.5 or later."
|
|
|
|
println " -> Please check README.md or InstallationGuide.html to verify you are using a supported version of Visual Studio."
|
|
|
|
return
|
|
|
|
}
|
2019-11-01 14:14:42 +00:00
|
|
|
def vswhereJson = new groovy.json.JsonSlurper().parseText(vswhereOutput);
|
|
|
|
if (vswhereJson.isEmpty()) {
|
2022-10-08 09:33:04 +00:00
|
|
|
println " -> Visual Studio not found!"
|
2019-11-13 16:22:38 +00:00
|
|
|
return
|
2019-11-01 14:14:42 +00:00
|
|
|
}
|
|
|
|
def vsInstallDir = vswhereJson[0].installationPath
|
|
|
|
println " -> Installation Directory: ${vsInstallDir}"
|
|
|
|
|
|
|
|
// Use vcvarsall.bat to determine the latest Visual Studio's default SDK and tool versions
|
|
|
|
def vcvarsPath = "${vsInstallDir}\\VC\\Auxiliary\\Build\\vcvarsall.bat"
|
|
|
|
def vcvarsCmd = "\"${vcvarsPath}\" x86_amd64"
|
|
|
|
def vcvarsEnvCmd = "cmd /v:ON /c ${vcvarsCmd} > nul && cmd /c echo"
|
|
|
|
def sdkDir = "${vcvarsEnvCmd} !WindowsSdkDir!".execute().text.trim()
|
|
|
|
println " -> SDK Directory (default): ${sdkDir}"
|
|
|
|
def sdkVersion = "${vcvarsEnvCmd} !WindowsSDKVersion!".execute().text.trim().replace('\\', '')
|
|
|
|
println " -> SDK Version (default): ${sdkVersion}"
|
2019-09-10 20:03:25 +00:00
|
|
|
|
2019-11-01 14:14:42 +00:00
|
|
|
// Check Gradle properties for override values
|
|
|
|
def windowsTargetPlatformVersion = findProperty("WindowsTargetPlatformVersion")
|
|
|
|
println " -> SDK Version (override): " + (windowsTargetPlatformVersion ?: "N/A")
|
2019-09-10 20:03:25 +00:00
|
|
|
|
2019-11-01 14:14:42 +00:00
|
|
|
// Save Visual Studio information so other projects can access it
|
|
|
|
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = vsInstallDir
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_DIR_DEFAULT = sdkDir
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_VERSION_DEFAULT = sdkVersion
|
|
|
|
rootProject.ext.VISUAL_STUDIO_SDK_VERSION_OVERRIDE = windowsTargetPlatformVersion
|
|
|
|
rootProject.ext.VISUAL_STUDIO_VCVARS_CMD = vcvarsCmd
|
2019-09-10 20:03:25 +00:00
|
|
|
}
|
|
|
|
}
|