GT-3277: Building with the latest Visual Studio found on system (closes

#999).
This commit is contained in:
Ryan Kurtz 2019-11-01 10:14:42 -04:00
parent 86790ca592
commit 6c26050f91
3 changed files with 43 additions and 35 deletions

View File

@ -50,9 +50,9 @@ task CheckToolChain {
doFirst { doFirst {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) { if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
// ensure that required MS Visual Studio is installed where expected // ensure that required MS Visual Studio is installed where expected
String msg = "Microsoft Visual Studio install not found: ${VISUAL_STUDIO_BASE_DIR}\n" + String msg = "Microsoft Visual Studio install not found: ${VISUAL_STUDIO_INSTALL_DIR}\n" +
"Adjust path in Ghidra/GPL/vsconfig.gradle if needed." "Adjust path in Ghidra/GPL/vsconfig.gradle if needed."
if (!file(VISUAL_STUDIO_BASE_DIR).exists() || !file(VISUAL_STUDIO_INSTALL_DIR).exists()) { if (!file(VISUAL_STUDIO_INSTALL_DIR).exists()) {
throw new GradleException(msg); throw new GradleException(msg);
} }
} }

View File

@ -6,43 +6,49 @@
* and SDKs are installed. * and SDKs are installed.
****************************************************************************/ ****************************************************************************/
if (!hasProperty("VISUAL_STUDIO_BASE_DIR")) { if (!hasProperty("VISUAL_STUDIO_INSTALL_DIR")) {
configureVisualStudio() configureVisualStudio()
} }
def configureVisualStudio() { def configureVisualStudio() {
rootProject.ext.VISUAL_STUDIO_BASE_DIR = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017"
rootProject.ext.WINDOWS_KITS_DIR = "C:\\Program Files (x86)\\Windows Kits\\10"
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = "/"
rootProject.ext.VISUAL_STUDIO_VCVARS_CMD = "UNKNOWN"
rootProject.ext.MSVC_SDK_VERSION = "UNKNOWN"
rootProject.ext.MSVC_TOOLS_VERSION = "UNKNOWN"
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) { if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = "${VISUAL_STUDIO_BASE_DIR}\\Professional"
if (!file(rootProject.ext.VISUAL_STUDIO_INSTALL_DIR).exists()) {
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = "${VISUAL_STUDIO_BASE_DIR}\\Community"
}
if (file(rootProject.ext.VISUAL_STUDIO_INSTALL_DIR).exists()) {
println "Visual Studio Path: ${VISUAL_STUDIO_INSTALL_DIR}" // Use vswhere.exe to search for latest Visual Studio installation
println "Searching for latest Visual Studio and required components..."
rootProject.ext.VISUAL_STUDIO_VCVARS_CMD = "\"${VISUAL_STUDIO_INSTALL_DIR}\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x86_amd64" def vswherePath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"
if (!file(vswherePath).exists()) {
// NOTE: Windows 7 targeting requires the use of the Windows 8.1 SDK and setting the throw new GradleException("Required file does not exist: " + vswherePath);
// WINVER property a value of "0x0601" which may be specified to the compiler/linker.
// If using a VS Solution this must be specified within the project file(s).
rootProject.ext.WINVER = "0x0601"
// Rely on vcvars script to supply SDK versions
def COMMAND = "cmd /v:ON /c ${VISUAL_STUDIO_VCVARS_CMD} > nul && cmd /c echo"
rootProject.ext.MSVC_SDK_VERSION = "${COMMAND} !WINDOWSSDKVERSION!".execute().text.trim().replace('\\', '')
println "Visual Studio SDK Version: ${MSVC_SDK_VERSION}"
rootProject.ext.MSVC_TOOLS_VERSION = "${COMMAND} !VCTOOLSVERSION!".execute().text.trim().replace('\\', '')
println "Visual Studio VCTools Version: ${MSVC_TOOLS_VERSION}"
} }
def vswhereOutput = "${vswherePath} -latest -format json".execute().text.trim()
def vswhereJson = new groovy.json.JsonSlurper().parseText(vswhereOutput);
if (vswhereJson.isEmpty()) {
throw new GradleException("Failed to find Visual Studio!")
}
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 toolsVersion = "${vcvarsEnvCmd} !VCToolsVersion!".execute().text.trim()
println " -> VCTools Version (default): ${toolsVersion}"
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}"
// Check Gradle properties for override values
def windowsTargetPlatformVersion = findProperty("WindowsTargetPlatformVersion")
println " -> SDK Version (override): " + (windowsTargetPlatformVersion ?: "N/A")
// Save Visual Studio information so other projects can access it
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = vsInstallDir
rootProject.ext.VISUAL_STUDIO_TOOLS_VERSION_DEFAULT = toolsVersion
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
} }
} }

View File

@ -49,14 +49,16 @@ if ("win64".equals(getCurrentPlatformName())) {
def projectPathWindows = projectPath.replace("/", File.separator) def projectPathWindows = projectPath.replace("/", File.separator)
def solutionPathWindows = "${projectPathWindows}\\src\\pdb\\pdb.sln" def solutionPathWindows = "${projectPathWindows}\\src\\pdb\\pdb.sln"
def platformToolset = 'v' + MSVC_TOOLS_VERSION.substring(0, 4).replace('.', ''); def platformToolset = 'v' + VISUAL_STUDIO_TOOLS_VERSION_DEFAULT.substring(0, 4).replace('.', '');
def windowsTargetPlatformVersion = findProperty("WindowsTargetPlatformVersion") ?: "" def windowsTargetPlatformVersion = VISUAL_STUDIO_SDK_VERSION_OVERRIDE ?: VISUAL_STUDIO_SDK_VERSION_DEFAULT
doFirst { doFirst {
file("build/os/win64").mkdirs() file("build/os/win64").mkdirs()
def msbuildCmd = "msbuild ${solutionPathWindows} /p:Configuration=Release /p:PlatformToolset=${platformToolset} /p:WindowsTargetPlatformVersion=${windowsTargetPlatformVersion}"
println msbuildCmd
new File(solutionBatchFilePath).withWriter { out -> new File(solutionBatchFilePath).withWriter { out ->
out.println "call " + VISUAL_STUDIO_VCVARS_CMD out.println "call " + VISUAL_STUDIO_VCVARS_CMD
out.println "msbuild ${solutionPathWindows} /p:Configuration=Release /p:PlatformToolset=${platformToolset} /p:WindowsTargetPlatformVersion=${windowsTargetPlatformVersion}" out.println msbuildCmd
} }
} }