mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-21 19:42:14 +00:00
GT-3277: Building with the latest Visual Studio found on system (closes
#999).
This commit is contained in:
parent
86790ca592
commit
6c26050f91
@ -50,9 +50,9 @@ task CheckToolChain {
|
||||
doFirst {
|
||||
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
|
||||
// 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."
|
||||
if (!file(VISUAL_STUDIO_BASE_DIR).exists() || !file(VISUAL_STUDIO_INSTALL_DIR).exists()) {
|
||||
if (!file(VISUAL_STUDIO_INSTALL_DIR).exists()) {
|
||||
throw new GradleException(msg);
|
||||
}
|
||||
}
|
||||
|
@ -6,43 +6,49 @@
|
||||
* and SDKs are installed.
|
||||
****************************************************************************/
|
||||
|
||||
if (!hasProperty("VISUAL_STUDIO_BASE_DIR")) {
|
||||
if (!hasProperty("VISUAL_STUDIO_INSTALL_DIR")) {
|
||||
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()) {
|
||||
|
||||
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}"
|
||||
|
||||
rootProject.ext.VISUAL_STUDIO_VCVARS_CMD = "\"${VISUAL_STUDIO_INSTALL_DIR}\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x86_amd64"
|
||||
|
||||
// NOTE: Windows 7 targeting requires the use of the Windows 8.1 SDK and setting the
|
||||
// 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}"
|
||||
// Use vswhere.exe to search for latest Visual Studio installation
|
||||
println "Searching for latest Visual Studio and required components..."
|
||||
def vswherePath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"
|
||||
if (!file(vswherePath).exists()) {
|
||||
throw new GradleException("Required file does not exist: " + vswherePath);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -49,14 +49,16 @@ if ("win64".equals(getCurrentPlatformName())) {
|
||||
|
||||
def projectPathWindows = projectPath.replace("/", File.separator)
|
||||
def solutionPathWindows = "${projectPathWindows}\\src\\pdb\\pdb.sln"
|
||||
def platformToolset = 'v' + MSVC_TOOLS_VERSION.substring(0, 4).replace('.', '');
|
||||
def windowsTargetPlatformVersion = findProperty("WindowsTargetPlatformVersion") ?: ""
|
||||
def platformToolset = 'v' + VISUAL_STUDIO_TOOLS_VERSION_DEFAULT.substring(0, 4).replace('.', '');
|
||||
def windowsTargetPlatformVersion = VISUAL_STUDIO_SDK_VERSION_OVERRIDE ?: VISUAL_STUDIO_SDK_VERSION_DEFAULT
|
||||
|
||||
doFirst {
|
||||
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 ->
|
||||
out.println "call " + VISUAL_STUDIO_VCVARS_CMD
|
||||
out.println "msbuild ${solutionPathWindows} /p:Configuration=Release /p:PlatformToolset=${platformToolset} /p:WindowsTargetPlatformVersion=${windowsTargetPlatformVersion}"
|
||||
out.println msbuildCmd
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user