diff --git a/GPL/nativeBuildProperties.gradle b/GPL/nativeBuildProperties.gradle index 48c3827b84..132c9e2f75 100644 --- a/GPL/nativeBuildProperties.gradle +++ b/GPL/nativeBuildProperties.gradle @@ -39,39 +39,42 @@ ext.getEnvironmentValue = { envLines, name -> return null } +project.ext.VISUAL_STUDIO_INSTALL_DIR = "/" +project.ext.VISUAL_STUDIO_VCVARS_CMD = "UNKNOWN" +project.ext.MSVC_SDK_VERSION = "UNKNOWN" +project.ext.MSVC_TOOLS_VERSION = "UNKNOWN" + // Ok, this is stupid, but mac and linux can't handle files paths that start with c: // These paths are actually only used when running on windows, but the paths gets evaulated // as a file no matter what platform you run gradle on. So the best solution I can think of is as // follows. +/* if (org.gradle.internal.os.OperatingSystem.current().isWindows()) { project.ext.VISUAL_STUDIO_INSTALL_DIR = project.ext.VISUAL_STUDIO_BASE_DIR + "\\Professional" if (!file(project.ext.VISUAL_STUDIO_INSTALL_DIR).exists()) { project.ext.VISUAL_STUDIO_INSTALL_DIR = project.ext.VISUAL_STUDIO_BASE_DIR + "\\Community" } - println "Visual Studio Path: ${VISUAL_STUDIO_INSTALL_DIR}" + if (file(project.ext.VISUAL_STUDIO_INSTALL_DIR).exists()) { - project.ext.VISUAL_STUDIO_VCVARS_CMD = "\"${VISUAL_STUDIO_INSTALL_DIR}\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x86_amd64" + println "Visual Studio Path: ${VISUAL_STUDIO_INSTALL_DIR}" + + project.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). - project.ext.WINVER = "0x0601" + // 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). + project.ext.WINVER = "0x0601" - // Rely on vcvars script to supply SDK versions - def c = VISUAL_STUDIO_VCVARS_CMD + " && env" - String envText = c.execute().text - String[] envLines = c.execute().text.split("\n") - project.ext.MSVC_SDK_VERSION = getEnvironmentValue(envLines, "WINDOWSSDKVERSION") - println "Visual Studio SDK Version: ${MSVC_SDK_VERSION}" - project.ext.MSVC_TOOLS_VERSION = getEnvironmentValue(envLines, "VCTOOLSVERSION") - println "Visual Studio VCTools Version: ${MSVC_TOOLS_VERSION}" -} -else { - project.ext.VISUAL_STUDIO_INSTALL_DIR = "/" - project.ext.VISUAL_STUDIO_VCVARS_CMD = "NA" - project.ext.MSVC_SDK_VERSION = "?" - project.ext.MSVC_TOOLS_VERSION = "?" + // Rely on vcvars script to supply SDK versions + def c = VISUAL_STUDIO_VCVARS_CMD + " && env" + String envText = c.execute().text + String[] envLines = c.execute().text.split("\n") + project.ext.MSVC_SDK_VERSION = getEnvironmentValue(envLines, "WINDOWSSDKVERSION") + println "Visual Studio SDK Version: ${MSVC_SDK_VERSION}" + project.ext.MSVC_TOOLS_VERSION = getEnvironmentValue(envLines, "VCTOOLSVERSION") + println "Visual Studio VCTools Version: ${MSVC_TOOLS_VERSION}" + } } /**************************************************************************** @@ -101,6 +104,21 @@ model { } } +/******************************************************************************************* + * Task: verify presence of correct tool chain version for current platform + ******************************************************************************************/ +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: ${project.ext.VISUAL_STUDIO_BASE_DIR}\n" + + "Adjust path in Ghidra/GPL/nativeBuildProperties.gradle if needed." + assert file(project.ext.VISUAL_STUDIO_BASE_DIR).exists() : msg + assert file(project.ext.VISUAL_STUDIO_INSTALL_DIR).exists() : msg + } + } +} + /******************************************************************************************* * If task1 contains the given platform name, then it needs to be executed before * task2. The task1 must be of type LinkExecutable or LinkSharedLibrary so that the @@ -110,6 +128,7 @@ model { def addTaskDependencyForMyPlatform(task1, task2, platform) { if (platform.equals(task1.targetPlatform.get().name)) { task2.dependsOn task1.path + task1.dependsOn CheckToolChain } } @@ -141,6 +160,7 @@ tasks.addRule("Pattern: buildNatives_]: build all natives for giv String platform = taskName - "buildNatives_" task(taskName) { myTask -> + project.tasks.withType(LinkExecutable) { t -> addTaskDependencyForMyPlatform(t, myTask, platform) } @@ -150,6 +170,7 @@ tasks.addRule("Pattern: buildNatives_]: build all natives for giv project.tasks.each { t -> if (isNativeBinaryMakeTask(t, platform)) { myTask.dependsOn t.path + t.dependsOn CheckToolChain } } @@ -163,15 +184,7 @@ tasks.addRule("Pattern: buildNatives_]: build all natives for giv project.tasks.whenTaskAdded { t -> if (isNativeBinaryMakeTask(t, platform)) { myTask.dependsOn t.path - } - } - 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: ${project.ext.VISUAL_STUDIO_BASE_DIR}\n" + - "Adjust path in Ghidra/GPL/nativeBuildProperties.gradle if needed." - assert file(project.ext.VISUAL_STUDIO_BASE_DIR).exists() : msg - assert file(project.ext.VISUAL_STUDIO_INSTALL_DIR).exists() : msg + t.dependsOn CheckToolChain } } } @@ -207,3 +220,6 @@ tasks.addRule("Pattern: prebuildNatives_]: build all natives for } } } + +def currentPlatform = getCurrentPlatformName() +assemble.dependsOn "buildNatives_$currentPlatform"