ext.useWpiUtil = { project -> project.tasks.create(name: "downloadWpiUtil") { description = 'Downloads the wpiutil maven dependency.' group = 'WPILib' def depFolder = "${project.buildDir}/dependencies" def utilZip = file("${depFolder}/wpiutil.zip") outputs.file(utilZip) def wpiUtil doFirst { def wpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:${project.isArm ? 'arm' : 'desktop'}@zip") def wpiUtilConfig = project.configurations.detachedConfiguration(wpiUtilDependency) wpiUtilConfig.setTransitive(false) wpiUtil = wpiUtilConfig.files[0].canonicalFile } doLast { copy { from wpiUtil rename 'wpiutil(.+)', 'wpiutil.zip' into depFolder } } } def wpiUtilUnzipLocation = "${project.buildDir}/wpiutil" // Create a task that will unzip the wpiutil files into a temporary build directory project.tasks.create(name: "unzipWpiUtil", type: Copy) { description = 'Unzips the wpiutil maven dependency so that the include files and libraries can be used' group = 'WPILib' dependsOn project.tasks.downloadWpiUtil from zipTree(project.tasks.downloadWpiUtil.outputs.files.singleFile) into wpiUtilUnzipLocation } project.ext.wpiUtil = wpiUtilUnzipLocation project.ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include" project.ext.addWpiUtilStaticLibraryLinks = { compileTask, linker, targetPlatform -> compileTask.dependsOn project.tasks.unzipWpiUtil String path = project.getPlatformPath2(targetPlatform) if (targetPlatform.operatingSystem.windows) { linker.args "${project.wpiUtil}/${path}/wpiutil.lib" } else { linker.args "${project.wpiUtil}/${path}/libwpiutil.a" } } project.ext.addWpiUtilSharedLibraryLinks = { compileTask, linker, targetPlatform -> compileTask.dependsOn project.tasks.unzipWpiUtil String path = project.getPlatformPath2(targetPlatform) if (targetPlatform.operatingSystem.windows) { linker.args "${project.wpiUtil}/${path}/wpiutil.dll" } else { linker.args "${project.wpiUtil}/${path}/libwpiutil.so" } } } ext.getOpenCvPlatformPackage = { targetPlatform -> if (targetPlatform.architecture.arm) { return 'linux-arm' } else if (targetPlatform.operatingSystem.linux) { if (targetPlatform.architecture.amd64) { return 'linux-x86_64' } else { return 'linux-' + targetPlatform.architecture.name } } else if (targetPlatform.operatingSystem.windows) { if (targetPlatform.architecture.amd64) { return 'windows-x86_64' } else { return 'windows-' + targetPlatform.architecture.name } } else if (targetPlatform.operatingSystem.macOsX) { if (targetPlatform.architecture.amd64) { return 'osx-x86_64' } else { return 'osx-' + targetPlatform.architecture.name } } else { return targetPlatform.operatingSystem.name + '-' + targetPlatform.architecture.name } } task downloadOpenCvHeaders() { description = 'Downloads the OpenCV Headers maven dependency.' group = 'WPILib' def depFolder = "${buildDir}/dependencies" def openCvHeadersZip = file("${depFolder}/opencv-headers.zip") outputs.file(openCvHeadersZip) def openCvHeaders doFirst { def openCvHeadersDependency = project.dependencies.create("org.opencv:opencv-headers:3.1.0@jar") def openCvHeadersConfig = project.configurations.detachedConfiguration(openCvHeadersDependency) openCvHeadersConfig.setTransitive(false) openCvHeaders = openCvHeadersConfig.files[0].canonicalFile } doLast { copy { from openCvHeaders rename 'opencv-headers(.+)', 'opencv-headers.zip' into depFolder } } } ext.useOpenCv = { project -> def openCvUnzipLocation = "${project.buildDir}/opencv" project.tasks.create(name: "unzipOpenCvHeaders", type: Copy) { description = 'Unzips the OpenCV maven dependency so that the include files and libraries can be used' group = 'OpenCv' dependsOn downloadOpenCvHeaders from zipTree(downloadOpenCvHeaders.outputs.files.singleFile) into "${openCvUnzipLocation}/include" } project.ext.openCv = openCvUnzipLocation project.ext.openCvInclude = "$openCvUnzipLocation/include" project.ext.addOpenCvLibraryLinks = { compileTask, linker, targetPlatform -> def openCvPlatform = project.getOpenCvPlatformPackage(targetPlatform) def openCvNativesFolder = "${project.openCv}/${openCvPlatform}" if (project.tasks.findByPath("unzipOpenCvNatives_${openCvPlatform}") == null) { project.tasks.create(name: "downloadOpenCvNatives_${openCvPlatform}") { description = 'Downloads the OpenCV natives maven dependency.' group = 'OpenCv' def depFolder = "${project.buildDir}/dependencies" def openCvNativesZip = file("${depFolder}/opencv-natives-${openCvPlatform}.zip") outputs.file(openCvNativesZip) def openCvNatives doFirst { def openCvNativesDependency = project.dependencies.create("org.opencv:opencv-natives:3.1.0:${openCvPlatform}@jar") def openCvNativesConfig = project.configurations.detachedConfiguration(openCvNativesDependency) openCvNativesConfig.setTransitive(false) openCvNatives = openCvNativesConfig.files[0].canonicalFile } doLast { copy { from openCvNatives rename 'opencv-natives(.+)', "opencv-natives-${openCvPlatform}.zip" into depFolder } } } project.tasks.create(name: "unzipOpenCvNatives_${openCvPlatform}", type: Copy) { description = 'Unzips the OpenCV maven dependency so that the include files and libraries can be used' group = 'OpenCv' dependsOn "downloadOpenCvNatives_${openCvPlatform}" from zipTree(project.tasks["downloadOpenCvNatives_${openCvPlatform}"].outputs.files.singleFile) into openCvNativesFolder exclude '**/MANIFEST.MF' } } if (project.includeJava && project.tasks.findByPath("unzipOpenCvJni_${openCvPlatform}") == null) { project.tasks.create(name: "downloadOpenCvJni_${openCvPlatform}") { description = 'Downloads the OpenCV JNI maven dependency.' group = 'OpenCv' def depFolder = "${project.buildDir}/dependencies" def openCvJniZip = file("${depFolder}/opencv-jni-${openCvPlatform}.zip") outputs.file(openCvJniZip) def openCvJni doFirst { def openCvJniDependency = project.dependencies.create("org.opencv:opencv-jni:3.1.0:${openCvPlatform}@jar") def openCvJniConfig = project.configurations.detachedConfiguration(openCvJniDependency) openCvJniConfig.setTransitive(false) openCvJni = openCvJniConfig.files[0].canonicalFile } doLast { copy { from openCvJni rename 'opencv-jni(.+)', "opencv-jni-${openCvPlatform}.zip" into depFolder } } } project.tasks.create(name: "unzipOpenCvJni_${openCvPlatform}", type: Copy) { description = 'Unzips the OpenCV maven dependency so that the include files and libraries can be used' group = 'OpenCv' dependsOn "downloadOpenCvJni_${openCvPlatform}" from zipTree(project.tasks["downloadOpenCvJni_${openCvPlatform}"].outputs.files.singleFile) into openCvNativesFolder exclude '**/MANIFEST.MF' } } compileTask.dependsOn "unzipOpenCvHeaders", "unzipOpenCvNatives_${openCvPlatform}" if (project.includeJava) { compileTask.dependsOn "unzipOpenCvJni_${openCvPlatform}" } if (targetPlatform.operatingSystem.windows) { linker.args "${openCvNativesFolder}/opencv.lib" } else { linker.args "-L${openCvNativesFolder}" linker.args "-lopencv" linker.args "-ldl" } } }