forked from microsoft/glTF-SDK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
androidbuild.ps1
145 lines (129 loc) · 3.63 KB
/
androidbuild.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<#
/**************************************************************
* *
# Copyright (c) Microsoft Corporation. All rights reserved. *
# Licensed under the MIT License. *
* *
**************************************************************/
.SYNOPSIS
Invokes CMake to build GLTFSDK for android targets.
This should be run after every git pull or clean and should be safe to run any time.
.DESCRIPTION
It first creates ninja files as native build target. Then invokes ninja to kick off
actual build process.
Assumes, CMake, ninja and Android-ndk are available.
.EXAMPLE
androidbuild.ps1 -arm64
#>
[CmdletBinding()]
param(
[switch]$Clean,
[switch]$Rebuild,
[switch]$NoUnitTests,
[switch]$arm64,
[switch]$arm32,
[switch]$x86,
[switch]$x86_64,
[switch]$NoDebug
)
$ErrorActionPreference = "stop"
if($NoDebug) {$BuildType = "Release"} else { $BuildType = "Debug"}
function GenerateNinjaFiles()
{
$AndroidABI = findABI
$BuildDirName = getBuildDirName
Write-Host "Generating Android ninja files for $AndroidABI"
New-Item -Path "$PSScriptRoot\Built\Int" -Name $BuildDirName -ItemType Directory -Force | Out-Null
Push-Location "$PSScriptRoot\Built\Int\$BuildDirName" | Out-Null
try
{
if (Test-Path Env:ANDROID_HOME)
{
$AndroidNDKRoot = "$Env:ANDROID_HOME\ndk-bundle"
}
else
{
$Appdata = [Environment]::GetFolderPath('ApplicationData')
$AndroidNDKRoot = "$Appdata\..\Local\Android\Sdk\ndk-bundle"
}
$AndroidToolChain = "$AndroidNDKRoot\build\cmake\android.toolchain.cmake"
$AndroidPlatform = "android-19"
if ($NoUnitTests)
{
$ENABLE_UNIT_TESTS = "OFF"
}
else
{
$ENABLE_UNIT_TESTS = "ON"
}
cmake ..\..\.. -DANDROID_ABI="$AndroidABI" -DANDROID_PLATFORM="$AndroidPlatform" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=intermediates -DCMAKE_BUILD_TYPE="$BuildType" -DANDROID_NDK="$AndroidNDKRoot" -DCMAKE_TOOLCHAIN_FILE="$AndroidToolChain" -DCMAKE_CXX_FLAGS=-fexceptions -DANDROID_STL=c++_static -GNinja -DANDROID_OS_PLATFORM=ANDROID -DENABLE_UNIT_TESTS="$ENABLE_UNIT_TESTS" | Write-Host
}
finally
{
Pop-Location | Out-Null
}
}
function BuildTarget()
{
$BuildDirName = getBuildDirName
Push-Location "$PSScriptRoot\Built\Int\$BuildDirName" | Out-Null
try
{
cmake --build . --target install --config "$BuildType"
}
finally
{
Pop-Location | Out-Null
}
}
function cleanAllTargets()
{
Remove-Item "$PSScriptRoot\Built" -Recurse -Force -ErrorAction Ignore | Write-Host
}
function cleanTarget()
{
# Delete both compilation and installation directories.
$BuildDirName = getBuildDirName
Remove-Item "$PSScriptRoot\Built\Int\$BuildDirName" -Recurse -Force -ErrorAction Ignore | Write-Host
Remove-Item "$PSScriptRoot\Built\Out\$BuildDirName\$BuildType" -Recurse -Force -ErrorAction Ignore | Write-Host
}
function findABI()
{
$ABI = "x86"
if($arm32)
{
$ABI = "armeabi-v7a"
}
elseif($arm64)
{
$ABI = "arm64-v8a"
}
elseif($x86_64)
{
$abi = "x86_64"
}
return $ABI
}
function getBuildDirName()
{
$AndroidABI = findABI
$BuildDirName = "android_$AndroidABI"
return $BuildDirName
}
function Main()
{
if($Clean)
{
cleanTarget
}
else
{
if($Rebuild)
{
cleanTarget
}
GenerateNinjaFiles
BuildTarget
}
}
Main