John Park | 7eb9042 | 2018-01-27 12:04:57 -0800 | [diff] [blame] | 1 | import edu.wpi.first.nativeutils.* |
| 2 | import org.gradle.internal.os.OperatingSystem |
| 3 | |
| 4 | def windowsCompilerArgs = ['/EHsc', '/DNOMINMAX', '/Zi', '/FS', '/Zc:inline', '/MT'] |
| 5 | def windowsReleaseCompilerArgs = ['/O2'] |
| 6 | def windowsLinkerArgs = [ '/DEBUG:FULL' ] |
| 7 | def windowsReleaseLinkerArgs = [ '/OPT:REF', '/OPT:ICF' ] |
| 8 | |
| 9 | def linuxCompilerArgs = ['-std=c++11', '-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g', |
| 10 | '-Wno-unused-parameter', '-fPIC', '-rdynamic', '-Wno-error=deprecated-declarations', '-pthread'] |
| 11 | def linuxLinkerArgs = ['-rdynamic', '-pthread'] |
| 12 | def linuxReleaseCompilerArgs = ['-Og'] |
| 13 | def linuxDebugCompilerArgs = ['-O0'] |
| 14 | def linux32BitArg = '-m32' |
| 15 | |
| 16 | def macCompilerArgs = ['-std=c++11', '-Wall', '-Wextra', '-Werror', '-pedantic-errors', '-fPIC', '-g', |
| 17 | '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-Wno-unused-private-field'] |
| 18 | def macReleaseCompilerArgs = ['-O2'] |
| 19 | def macDebugCompilerArgs = ['-O0'] |
| 20 | def mac32BitArg = '-m32' |
| 21 | |
| 22 | def buildAll = project.hasProperty('buildAll') |
| 23 | |
| 24 | def windows64PlatformDetect = { |
| 25 | def arch = System.getProperty("os.arch") |
| 26 | def isWin = OperatingSystem.current().isWindows() |
| 27 | if (buildAll) { |
| 28 | return isWin |
| 29 | } else { |
| 30 | return isWin && arch == 'amd64' |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | def windows32PlatformDetect = { |
| 35 | def arch = System.getProperty("os.arch") |
| 36 | def isWin = OperatingSystem.current().isWindows() |
| 37 | if (buildAll) { |
| 38 | return isWin |
| 39 | } else { |
| 40 | return isWin && arch == 'x86' |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | def linux32IntelPlatformDetect = { |
| 45 | def arch = System.getProperty("os.arch") |
| 46 | def isLinux = OperatingSystem.current().isLinux() |
| 47 | def isIntel = (arch == 'amd64' || arch == 'i386') |
| 48 | if (buildAll) { |
| 49 | return isLinux && isIntel |
| 50 | } else { |
| 51 | return isLinux && arch == 'i386' |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | def linux64IntelPlatformDetect = { |
| 56 | def arch = System.getProperty("os.arch") |
| 57 | def isLinux = OperatingSystem.current().isLinux() |
| 58 | def isIntel = (arch == 'amd64' || arch == 'i386') |
| 59 | if (buildAll) { |
| 60 | return isLinux && isIntel |
| 61 | } else { |
| 62 | return isLinux && arch == 'amd64' |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | def linuxArmPlatformDetect = { |
| 67 | def arch = System.getProperty("os.arch") |
| 68 | def isIntel = (arch == 'amd64' || arch == 'i386') |
| 69 | return OperatingSystem.current().isLinux() && !isIntel |
| 70 | } |
| 71 | |
| 72 | def mac64PlatformDetect = { |
| 73 | def arch = System.getProperty("os.arch") |
| 74 | def isMac = OperatingSystem.current().isMacOsX() |
| 75 | if (buildAll) { |
| 76 | return isMac |
| 77 | } else { |
| 78 | return isMac && arch == 'x86_64' |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | def mac32PlatformDetect = { |
| 83 | def arch = System.getProperty("os.arch") |
| 84 | def isMac = OperatingSystem.current().isMacOsX() |
| 85 | if (buildAll) { |
| 86 | return isMac |
| 87 | } else { |
| 88 | return isMac && arch == 'x86' |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (!project.hasProperty('skipAthena')) { |
| 93 | model { |
| 94 | buildConfigs { |
| 95 | roboRio(CrossBuildConfig) { |
| 96 | architecture = 'athena' |
| 97 | operatingSystem = 'linux' |
| 98 | toolChainPrefix = 'arm-frc-linux-gnueabi-' |
| 99 | compilerArgs = linuxCompilerArgs |
| 100 | linkerArgs = linuxLinkerArgs |
| 101 | debugCompilerArgs = linuxDebugCompilerArgs |
| 102 | releaseCompilerArgs = linuxReleaseCompilerArgs |
| 103 | releaseStripBinaries = true |
| 104 | compilerFamily = 'Gcc' |
| 105 | exclude << 'gmock' |
| 106 | exclude << 'wpiutilTestingBase' |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (!project.hasProperty('onlyAthena')) { |
| 113 | model { |
| 114 | buildConfigs { |
| 115 | winX86(BuildConfig) { |
| 116 | architecture = 'x86' |
| 117 | operatingSystem = 'windows' |
| 118 | compilerArgs = windowsCompilerArgs |
| 119 | linkerArgs = windowsLinkerArgs |
| 120 | releaseCompilerArgs = windowsReleaseCompilerArgs |
| 121 | releaseLinkerArgs = windowsReleaseLinkerArgs |
| 122 | compilerFamily = 'VisualCpp' |
| 123 | detectPlatform = windows32PlatformDetect |
| 124 | } |
| 125 | winX64(BuildConfig) { |
| 126 | architecture = 'x86-64' |
| 127 | operatingSystem = 'windows' |
| 128 | compilerArgs = windowsCompilerArgs |
| 129 | linkerArgs = windowsLinkerArgs |
| 130 | releaseCompilerArgs = windowsReleaseCompilerArgs |
| 131 | releaseLinkerArgs = windowsReleaseLinkerArgs |
| 132 | compilerFamily = 'VisualCpp' |
| 133 | detectPlatform = windows64PlatformDetect |
| 134 | } |
| 135 | linuxX86(BuildConfig) { |
| 136 | architecture = 'x86' |
| 137 | operatingSystem = 'linux' |
| 138 | compilerArgs = linuxCompilerArgs |
| 139 | compilerArgs << linux32BitArg |
| 140 | linkerArgs = linuxLinkerArgs |
| 141 | linkerArgs << linux32BitArg |
| 142 | debugCompilerArgs = linuxDebugCompilerArgs |
| 143 | releaseCompilerArgs = linuxReleaseCompilerArgs |
| 144 | releaseStripBinaries = true |
| 145 | compilerFamily = 'Gcc' |
| 146 | detectPlatform = linux32IntelPlatformDetect |
| 147 | } |
| 148 | linuxX64(BuildConfig) { |
| 149 | architecture = 'x86-64' |
| 150 | operatingSystem = 'linux' |
| 151 | compilerArgs = linuxCompilerArgs |
| 152 | linkerArgs = linuxLinkerArgs |
| 153 | debugCompilerArgs = linuxDebugCompilerArgs |
| 154 | releaseCompilerArgs = linuxReleaseCompilerArgs |
| 155 | releaseStripBinaries = true |
| 156 | compilerFamily = 'Gcc' |
| 157 | detectPlatform = linux64IntelPlatformDetect |
| 158 | } |
| 159 | macX86(BuildConfig) { |
| 160 | architecture = 'x86' |
| 161 | operatingSystem = 'osx' |
| 162 | compilerArgs = macCompilerArgs |
| 163 | compilerArgs << mac32BitArg |
| 164 | linkerArgs << mac32BitArg |
| 165 | debugCompilerArgs = macDebugCompilerArgs |
| 166 | releaseCompilerArgs = macReleaseCompilerArgs |
| 167 | releaseStripBinaries = true |
| 168 | compilerFamily = 'Clang' |
| 169 | detectPlatform = mac32PlatformDetect |
| 170 | } |
| 171 | macX64(BuildConfig) { |
| 172 | architecture = 'x86-64' |
| 173 | operatingSystem = 'osx' |
| 174 | compilerArgs = macCompilerArgs |
| 175 | debugCompilerArgs = macDebugCompilerArgs |
| 176 | releaseCompilerArgs = macReleaseCompilerArgs |
| 177 | releaseStripBinaries = true |
| 178 | compilerFamily = 'Clang' |
| 179 | detectPlatform = mac64PlatformDetect |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | if (project.hasProperty('linuxCross')) { |
| 186 | model { |
| 187 | buildConfigs { |
| 188 | linuxArm(CrossBuildConfig) { |
| 189 | architecture = 'nativearm' |
| 190 | operatingSystem = 'linux' |
| 191 | toolChainPrefix = 'PLEASE_PROVIDE_A_COMPILER_NAME' |
| 192 | compilerArgs = linuxCompilerArgs |
| 193 | linkerArgs = linuxLinkerArgs |
| 194 | debugCompilerArgs = linuxDebugCompilerArgs |
| 195 | releaseCompilerArgs = linuxReleaseCompilerArgs |
| 196 | releaseStripBinaries = true |
| 197 | skipByDefault = true |
| 198 | compilerFamily = 'Gcc' |
| 199 | exclude << 'gmock' |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } else { |
| 204 | model { |
| 205 | buildConfigs { |
| 206 | linuxArm(BuildConfig) { |
| 207 | architecture = 'nativearm' |
| 208 | operatingSystem = 'linux' |
| 209 | compilerArgs = linuxCompilerArgs |
| 210 | linkerArgs = linuxLinkerArgs |
| 211 | debugCompilerArgs = linuxDebugCompilerArgs |
| 212 | releaseCompilerArgs = linuxReleaseCompilerArgs |
| 213 | releaseStripBinaries = true |
| 214 | compilerFamily = 'Gcc' |
| 215 | detectPlatform = linuxArmPlatformDetect |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |