2023-12-08 00:13:39 +08:00
|
|
|
#
|
2024-01-06 01:09:31 +08:00
|
|
|
# This script easy to build win32, linux, winuwp(winrt), ios, tvos, osx, android depends on $myRoot/1k/build.ps1
|
2023-12-08 00:13:39 +08:00
|
|
|
# usage: pwsh build.ps1 -p <targetPlatform> -a <arch>
|
|
|
|
# options
|
2024-01-06 01:09:31 +08:00
|
|
|
# -p: build target platform: win32,winuwp(winrt),linux,android,osx,ios,tvos,wasm
|
2023-12-08 00:13:39 +08:00
|
|
|
# for android: will search ndk in sdk_root which is specified by env:ANDROID_HOME first,
|
|
|
|
# if not found, by default will install ndk-r16b or can be specified by option: -cc 'ndk-r23c'
|
|
|
|
# -a: build arch: x86,x64,armv7,arm64; for android can be list by ';', i.e: 'arm64;x64'
|
|
|
|
# -cc: toolchain: for win32 you can specific -cc clang to use llvm-clang, please install llvm-clang from https://github.com/llvm/llvm-project/releases
|
|
|
|
# -xc: additional cmake options: i.e. -xc '-Dbuild','-DCMAKE_BUILD_TYPE=Release'
|
|
|
|
# -xb: additional cross build options: i.e. -xb '--config','Release'
|
2024-03-04 22:26:37 +08:00
|
|
|
# -c(configOnly): no build, only generate native project files (vs .sln, xcodeproj)
|
2023-12-08 00:13:39 +08:00
|
|
|
# -d: specify project dir to compile, i.e. -d /path/your/project/
|
2024-03-04 22:26:37 +08:00
|
|
|
# -f: force generate native project files. Useful if no changes are detected, such as with resource updates.
|
2023-12-08 00:13:39 +08:00
|
|
|
# examples:
|
|
|
|
# - win32:
|
|
|
|
# - pwsh build.ps1 -p win32
|
|
|
|
# - pwsh build.ps1 -p win32 -cc clang
|
|
|
|
# - winuwp: pwsh build.ps1 -p winuwp
|
|
|
|
# - linux: pwsh build.ps1 -p linux
|
|
|
|
# - android:
|
|
|
|
# - pwsh build.ps1 -p android -a arm64
|
|
|
|
# - pwsh build.ps1 -p android -a 'arm64;x64'
|
|
|
|
# - osx:
|
|
|
|
# - pwsh build.ps1 -p osx -a x64
|
|
|
|
# - pwsh build.ps1 -p osx -a arm64
|
|
|
|
# - ios: pwsh build.ps1 -p ios -a x64
|
|
|
|
# - tvos: pwsh build.ps1 -p tvos -a x64
|
|
|
|
# - wasm: pwsh build.ps1 -p wasm
|
|
|
|
# build.ps1 without any arguments:
|
|
|
|
# - pwsh build.ps1
|
|
|
|
# on windows: target platform is win32, arch=x64
|
|
|
|
# on linux: target platform is linux, arch=x64
|
|
|
|
# on macos: target platform is osx, arch=x64
|
|
|
|
#
|
|
|
|
param(
|
|
|
|
[switch]$configOnly,
|
2024-01-18 21:09:36 +08:00
|
|
|
[switch]$forceConfig,
|
2024-02-17 00:29:07 +08:00
|
|
|
[switch]$setupOnly
|
2023-12-08 00:13:39 +08:00
|
|
|
)
|
|
|
|
|
2024-02-17 00:29:07 +08:00
|
|
|
$unhandled_args = @()
|
|
|
|
|
2024-04-13 22:11:22 +08:00
|
|
|
$1k_switch_options = @{ 'dll' = $true; 'u' = $true; 'dm' = $true }
|
|
|
|
|
2024-04-13 22:20:13 +08:00
|
|
|
$options = @{p = $null; d = $null; xc = @(); xb = @(); }
|
2023-12-08 00:13:39 +08:00
|
|
|
|
|
|
|
$optName = $null
|
|
|
|
foreach ($arg in $args) {
|
|
|
|
if (!$optName) {
|
|
|
|
if ($arg.StartsWith('-')) {
|
|
|
|
$optName = $arg.SubString(1).TrimEnd(':')
|
|
|
|
}
|
2024-04-13 22:20:13 +08:00
|
|
|
if($1k_switch_options.Contains("$optName")) {
|
2024-04-13 22:11:22 +08:00
|
|
|
$unhandled_args += $arg
|
|
|
|
$optName = $null
|
|
|
|
continue
|
|
|
|
}
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($options.Contains($optName)) {
|
|
|
|
$options[$optName] = $arg
|
2024-04-13 22:11:22 +08:00
|
|
|
}
|
|
|
|
else {
|
2024-02-17 00:29:07 +08:00
|
|
|
$unhandled_args += "-$optName"
|
|
|
|
$unhandled_args += $arg
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
$optName = $null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function translate_array_opt($opt) {
|
|
|
|
if ($opt -and $opt.GetType().BaseType -ne [array]) {
|
|
|
|
$opt = "$opt".Split(',')
|
|
|
|
}
|
|
|
|
return $opt
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($options.xb.Count -ne 0) {
|
|
|
|
[array]$options.xb = (translate_array_opt $options.xb)
|
|
|
|
}
|
|
|
|
if ($options.xc.Count -ne 0) {
|
|
|
|
[array]$options.xc = (translate_array_opt $options.xc)
|
|
|
|
}
|
|
|
|
|
|
|
|
$myRoot = $PSScriptRoot
|
|
|
|
$workDir = $(Get-Location).Path
|
|
|
|
|
|
|
|
# axroot
|
2023-12-20 20:50:18 +08:00
|
|
|
$AX_ROOT = $null
|
|
|
|
if (Test-Path "$myRoot/core/axmolver.h.in" -PathType Leaf) {
|
2023-12-08 00:13:39 +08:00
|
|
|
$AX_ROOT = $myRoot
|
|
|
|
$env:AX_ROOT = $AX_ROOT
|
2024-04-13 22:11:22 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-12-20 20:50:18 +08:00
|
|
|
throw "The axmol engine incompleted"
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
|
2023-12-20 20:50:18 +08:00
|
|
|
# 1k/build.ps1
|
2024-04-13 22:11:22 +08:00
|
|
|
if (Test-Path "$myRoot/1k/build.ps1" -PathType Leaf) {
|
2023-12-20 20:50:18 +08:00
|
|
|
$b1k_root = $myRoot
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw "The 1k/build.ps1 not found"
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
|
2024-04-13 22:11:22 +08:00
|
|
|
$source_proj_dir = if ($options.d) { $options.d } else { $workDir }
|
2024-03-23 00:51:46 +08:00
|
|
|
$Global:is_axmol_engine = ($source_proj_dir -eq $AX_ROOT)
|
|
|
|
$Global:is_axmol_app = (Test-Path (Join-Path $source_proj_dir '.axproj.json') -PathType Leaf)
|
2023-12-08 00:13:39 +08:00
|
|
|
$is_android = $options.p -eq 'android'
|
|
|
|
|
|
|
|
# start construct full cmd line
|
|
|
|
$b1k_script = (Resolve-Path -Path "$b1k_root/1k/build.ps1").Path
|
|
|
|
$b1k_args = @()
|
|
|
|
|
2023-12-11 23:28:21 +08:00
|
|
|
$cm_target_index = $options.xb.IndexOf('--target')
|
2024-04-13 22:11:22 +08:00
|
|
|
if ($cm_target_index -ne -1) {
|
2023-12-11 23:28:21 +08:00
|
|
|
$cmake_target = $options.xb[$cm_target_index + 1]
|
|
|
|
}
|
|
|
|
|
2024-03-23 00:51:46 +08:00
|
|
|
if ($is_axmol_engine -and $is_android) {
|
2023-12-11 23:28:21 +08:00
|
|
|
if (!$cmake_target) {
|
2024-03-24 05:53:21 +08:00
|
|
|
$source_proj_dir = Join-Path $myRoot 'tests/cpp-tests'
|
2024-04-13 22:11:22 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-12-11 23:28:21 +08:00
|
|
|
$builtin_targets = @{
|
2024-04-13 22:11:22 +08:00
|
|
|
'cpp-tests' = 'tests/cpp-tests'
|
2023-12-11 23:28:21 +08:00
|
|
|
'fairygui-tests' = 'tests/fairygui-tests'
|
2024-04-13 22:11:22 +08:00
|
|
|
'live2d-tests' = 'tests/live2d-tests'
|
2023-12-11 23:28:21 +08:00
|
|
|
}
|
|
|
|
if (!$builtin_targets.Contains($cmake_target)) {
|
|
|
|
throw "specified target '$cmake_target' not present in engine"
|
|
|
|
}
|
|
|
|
$source_proj_dir = Join-Path $myRoot $builtin_targets[$cmake_target]
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-07 23:32:28 +08:00
|
|
|
$search_paths = @($source_proj_dir)
|
2023-12-08 00:13:39 +08:00
|
|
|
function search_proj_file($file_path, $type) {
|
|
|
|
foreach ($search_path in $search_paths) {
|
|
|
|
$full_path = Join-Path $search_path $file_path
|
|
|
|
if (Test-Path $full_path -PathType $type) {
|
|
|
|
# $ret_path = if ($type -eq 'Container') { $full_path } else { $search_path }
|
|
|
|
return $search_path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $null
|
|
|
|
}
|
|
|
|
|
|
|
|
$proj_dir = search_proj_file 'CMakeLists.txt' 'Leaf'
|
2024-04-13 22:11:22 +08:00
|
|
|
if (!$proj_dir) { throw "The directory $source_proj_dir doesn't contains CMakeLists.txt!" }
|
2023-12-08 00:13:39 +08:00
|
|
|
$proj_name = (Get-Item $proj_dir).BaseName
|
|
|
|
|
|
|
|
$use_gradle = $is_android -and (Test-Path $(Join-Path $proj_dir 'proj.android/gradlew') -PathType Leaf)
|
|
|
|
if ($use_gradle) {
|
|
|
|
$b1k_args += '-xt', 'proj.android/gradlew'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$use_gradle) {
|
2023-12-11 23:28:21 +08:00
|
|
|
if (!$cmake_target) {
|
2023-12-08 00:13:39 +08:00
|
|
|
# non android, specific cmake target
|
|
|
|
$cmake_targets = @(
|
2024-02-21 22:35:57 +08:00
|
|
|
# project
|
|
|
|
$proj_name,
|
|
|
|
# engine
|
|
|
|
'cpp-tests'
|
2023-12-08 00:13:39 +08:00
|
|
|
)
|
2024-03-23 00:51:46 +08:00
|
|
|
$cmake_target = $cmake_targets[$is_axmol_engine]
|
2023-12-08 00:13:39 +08:00
|
|
|
$options.xb += '--target', $cmake_target
|
|
|
|
}
|
|
|
|
|
2024-04-13 22:11:22 +08:00
|
|
|
if ($is_android -and !"$($options.xc)".Contains('-DANDROID_STL')) {
|
2024-03-23 02:06:40 +08:00
|
|
|
$options.xc += '-DANDROID_STL=c++_shared'
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
2024-04-13 22:11:22 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
# android gradle
|
2023-12-08 00:13:39 +08:00
|
|
|
# engine ci
|
2024-03-23 00:51:46 +08:00
|
|
|
if ($is_axmol_engine) {
|
2024-01-17 03:50:13 +08:00
|
|
|
$options.xc += "-PKEY_STORE_FILE=$AX_ROOT/tools/ci/axmol-ci.jks", '-PKEY_STORE_PASSWORD=axmol-ci', '-PKEY_ALIAS=axmol-ci', '-PKEY_PASSWORD=axmol-ci'
|
2023-12-08 00:13:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($proj_dir) {
|
|
|
|
$b1k_args += '-d', "$proj_dir"
|
|
|
|
}
|
|
|
|
$prefix = Join-Path $b1k_root 'tools/external'
|
|
|
|
$b1k_args += '-prefix', "$prefix"
|
|
|
|
|
|
|
|
# remove arg we don't want forward to
|
|
|
|
$options.Remove('d')
|
|
|
|
$b1k_args = [System.Collections.ArrayList]$b1k_args
|
|
|
|
foreach ($option in $options.GetEnumerator()) {
|
|
|
|
if ($option.Value) {
|
|
|
|
$null = $b1k_args.Add("-$($option.Key)")
|
|
|
|
$null = $b1k_args.Add($option.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$forward_args = @{}
|
|
|
|
if ($configOnly) {
|
|
|
|
$forward_args['configOnly'] = $true
|
|
|
|
}
|
|
|
|
if ($forceConfig) {
|
|
|
|
$forward_args['forceConfig'] = $true
|
|
|
|
}
|
2024-01-18 21:09:36 +08:00
|
|
|
if ($setupOnly) {
|
|
|
|
$forward_args['setupOnly'] = $true
|
|
|
|
}
|
2023-12-08 00:13:39 +08:00
|
|
|
|
2024-02-17 00:29:07 +08:00
|
|
|
. $b1k_script @b1k_args @forward_args @unhandled_args
|
2023-12-08 00:13:39 +08:00
|
|
|
|
|
|
|
if (!$configOnly) {
|
|
|
|
$b1k.pause('Build done')
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$b1k.pause('Generate done')
|
|
|
|
}
|
|
|
|
|