Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import org.gradle.internal.os.OperatingSystem |
| 2 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 3 | nativeUtils.skipInstallPdb = project.hasProperty('buildServer') |
| 4 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 5 | nativeUtils.addWpiNativeUtils() |
| 6 | nativeUtils.withRoboRIO() |
| 7 | nativeUtils.withRaspbian() |
| 8 | nativeUtils.withBionic() |
| 9 | nativeUtils { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 10 | wpi { |
| 11 | configureDependencies { |
| 12 | wpiVersion = "-1" |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 13 | niLibVersion = "2022.4.0" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | opencvVersion = "4.5.2-1" |
| 15 | googleTestVersion = "1.9.0-5-437e100-1" |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 16 | imguiVersion = "1.86-1" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 17 | wpimathVersion = "-1" |
| 18 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 19 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | nativeUtils.wpi.addWarnings() |
| 23 | nativeUtils.wpi.addWarningsAsErrors() |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 24 | |
| 25 | if (project.name != 'wpilibcExamples') { |
| 26 | nativeUtils.wpi.addReleaseSymbolGeneration() |
| 27 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 28 | |
| 29 | nativeUtils.setSinglePrintPerPlatform() |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 30 | nativeUtils.enableSourceLink() |
| 31 | |
| 32 | nativeUtils.platformConfigs.each { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 33 | if (it.name.contains('windows')) { |
| 34 | return |
| 35 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 36 | it.linker.args << '-Wl,-rpath,\'$ORIGIN\'' |
| 37 | if (it.name == 'osxx86-64') { |
| 38 | it.linker.args << "-headerpad_max_install_names" |
| 39 | } |
| 40 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 41 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 42 | nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings") |
| 43 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 44 | model { |
| 45 | components { |
| 46 | all { |
| 47 | nativeUtils.useAllPlatforms(it) |
| 48 | } |
| 49 | } |
| 50 | binaries { |
| 51 | withType(NativeBinarySpec).all { |
| 52 | nativeUtils.usePlatformArguments(it) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 57 | apply plugin: DisableBuildingGTest |
| 58 | |
| 59 | if (project.hasProperty('buildServer')) { |
| 60 | tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) { |
| 61 | def exeFile = file(it.executable) |
| 62 | def folder = exeFile.parentFile |
| 63 | |
| 64 | it.doLast { |
| 65 | folder.deleteDir() |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 70 | ext.appendDebugPathToBinaries = { binaries-> |
| 71 | binaries.withType(StaticLibraryBinarySpec) { |
| 72 | if (it.buildType.name.contains('debug')) { |
| 73 | def staticFileDir = it.staticLibraryFile.parentFile |
| 74 | def staticFileName = it.staticLibraryFile.name |
| 75 | def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.')) |
| 76 | staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.')) |
| 77 | staticFileName = staticFileName + 'd' + staticFileExtension |
| 78 | def newStaticFile = new File(staticFileDir, staticFileName) |
| 79 | it.staticLibraryFile = newStaticFile |
| 80 | } |
| 81 | } |
| 82 | binaries.withType(SharedLibraryBinarySpec) { |
| 83 | if (it.buildType.name.contains('debug')) { |
| 84 | def sharedFileDir = it.sharedLibraryFile.parentFile |
| 85 | def sharedFileName = it.sharedLibraryFile.name |
| 86 | def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.')) |
| 87 | sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.')) |
| 88 | sharedFileName = sharedFileName + 'd' + sharedFileExtension |
| 89 | def newSharedFile = new File(sharedFileDir, sharedFileName) |
| 90 | |
| 91 | def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile |
| 92 | def sharedLinkFileName = it.sharedLibraryLinkFile.name |
| 93 | def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.')) |
| 94 | sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.')) |
| 95 | sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension |
| 96 | def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName) |
| 97 | |
| 98 | it.sharedLibraryLinkFile = newLinkFile |
| 99 | it.sharedLibraryFile = newSharedFile |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | ext.createComponentZipTasks = { components, names, base, type, project, func -> |
| 105 | def stringNames = names.collect {it.toString()} |
| 106 | def configMap = [:] |
| 107 | components.each { |
| 108 | if (it in NativeLibrarySpec && stringNames.contains(it.name)) { |
| 109 | it.binaries.each { |
| 110 | if (!it.buildable) return |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 111 | def target = nativeUtils.getPublishClassifier(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 112 | if (configMap.containsKey(target)) { |
| 113 | configMap.get(target).add(it) |
| 114 | } else { |
| 115 | configMap.put(target, []) |
| 116 | configMap.get(target).add(it) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | def taskList = [] |
| 122 | def outputsFolder = file("$project.buildDir/outputs") |
| 123 | configMap.each { key, value -> |
| 124 | def task = project.tasks.create(base + "-${key}", type) { |
| 125 | description = 'Creates component archive for platform ' + key |
| 126 | destinationDirectory = outputsFolder |
| 127 | classifier = key |
| 128 | archiveBaseName = '_M_' + base |
| 129 | duplicatesStrategy = 'exclude' |
| 130 | |
| 131 | from(licenseFile) { |
| 132 | into '/' |
| 133 | } |
| 134 | |
| 135 | func(it, value) |
| 136 | } |
| 137 | taskList.add(task) |
| 138 | |
| 139 | project.build.dependsOn task |
| 140 | |
| 141 | project.artifacts { |
| 142 | task |
| 143 | } |
| 144 | addTaskToCopyAllOutputs(task) |
| 145 | } |
| 146 | return taskList |
| 147 | } |
| 148 | |
| 149 | ext.includeStandardZipFormat = { task, value -> |
| 150 | value.each { binary -> |
| 151 | if (binary.buildable) { |
| 152 | if (binary instanceof SharedLibraryBinarySpec) { |
| 153 | task.dependsOn binary.tasks.link |
| 154 | task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) { |
| 155 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 156 | } |
| 157 | def sharedPath = binary.sharedLibraryFile.absolutePath |
| 158 | sharedPath = sharedPath.substring(0, sharedPath.length() - 4) |
| 159 | |
| 160 | task.from(new File(sharedPath + '.pdb')) { |
| 161 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 162 | } |
| 163 | task.from(binary.sharedLibraryFile) { |
| 164 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 165 | } |
| 166 | task.from(binary.sharedLibraryLinkFile) { |
| 167 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 168 | } |
| 169 | } else if (binary instanceof StaticLibraryBinarySpec) { |
| 170 | task.dependsOn binary.tasks.createStaticLib |
| 171 | task.from(binary.staticLibraryFile) { |
| 172 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 173 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 174 | def pdbDir = binary.staticLibraryFile.parentFile |
| 175 | task.from(pdbDir) { |
| 176 | include '*.pdb' |
| 177 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 178 | } |
| 179 | task.from(new File(pdbDir, "SourceLink.json")) { |
| 180 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 181 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |