-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·152 lines (126 loc) · 4.64 KB
/
build.sh
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
146
147
148
149
150
151
152
#!/bin/bash
## Copyright 2022-present Contributors to the colorman project.
## SPDX-License-Identifier: BSD-3-Clause
## https://github.com/mikaelsundell/colorman
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
machine_arch=$(uname -m)
macos_version=$(sw_vers -productVersion)
major_version=$(echo "$macos_version" | cut -d '.' -f 1)
# signing
sign_code=OFF
code_sign_identity=""
development_team_id=""
# check signing
parse_args() {
while [[ "$#" -gt 0 ]]; do
case $1 in
--target=*)
major_version="${1#*=}" ;;
--sign)
sign_code=ON ;;
*)
build_type="$1" # save it in build_type if it's not a recognized flag
;;
esac
shift
done
}
parse_args "$@"
# target
if [ -z "$major_version" ]; then
macos_version=$(sw_vers -productVersion)
major_version=$(echo "$macos_version" | cut -d '.' -f 1)
fi
export MACOSX_DEPLOYMENT_TARGET=$major_version
export CMAKE_OSX_DEPLOYMENT_TARGET=$major_version
# signing
if [ "$sign_code" == "ON" ]; then
default_code_sign_identity=${CODE_SIGN_IDENTITY:-}
default_development_team_id=${DEVELOPMENT_TEAM_ID:-}
read -p "Enter Code Sign Identity [$default_code_sign_identity]: " input_code_sign_identity
code_sign_identity=${input_code_sign_identity:-$default_code_sign_identity}
if [[ ! "$input_code_sign_identity" == *"Developer ID"* ]]; then
echo "Code Sign identity must contain 'Developer ID' to be a valid developer certificate."
exit 1
fi
read -p "Enter Development Team ID [$default_development_team_id]: " input_development_team_id
development_team_id=${input_development_team_id:-$default_development_team_id}
fi
# exit on error
set -e
# clear
clear
# build type
if [ "$build_type" != "debug" ] && [ "$build_type" != "release" ] && [ "$build_type" != "all" ]; then
echo "invalid build type: $build_type (use 'debug', 'release', or 'all')"
exit 1
fi
echo "Building Colorman for $build_type"
echo "---------------------------------"
# check if cmake is in the path
if ! command -v cmake &> /dev/null; then
echo "cmake not found in the PATH, will try to set to /Applications/CMake.app/Contents/bin"
export PATH=$PATH:/Applications/CMake.app/Contents/bin
if ! command -v cmake &> /dev/null; then
echo "cmake could not be found, please make sure it's installed"
exit 1
fi
fi
# check if cmake version is compatible
if ! [[ $(cmake --version | grep -o '[0-9]\+\(\.[0-9]\+\)*' | head -n1) < "3.28.0" ]]; then
echo "cmake version is not compatible with Qt, must be before 3.28.0 for multi configuration"
exit 1;
fi
# build colorman
build_colorman() {
local build_type="$1"
local cmake_sign_options=""
# cmake
export PATH=$PATH:/Applications/CMake.app/Contents/bin &&
# script dir
cd "$script_dir"
# clean dir
build_dir="$script_dir/build.$build_type"
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
# build dir
mkdir -p "build.$build_type"
cd "build.$build_type"
# prefix dir
prefix="$script_dir/../3rdparty/build/macosx/$machine_arch.$build_type"
if ! [ -d "$prefix" ]; then
echo "could not find 3rdparty for build in: $prefix"
exit 1;
fi
# xcode build
xcode_type=$(echo "$build_type" | awk '{ print toupper(substr($0, 1, 1)) tolower(substr($0, 2)) }')
# build
if [ "$sign_code" == "ON" ]; then
cmake .. -DCMAKE_MODULE_PATH="$script_dir/modules" -DCMAKE_PREFIX_PATH="$prefix" -DSIGN_CODE=ON -DCODE_SIGN_IDENTITY="$code_sign_identity" -DDEVELOPMENT_TEAM_ID="$development_team_id" -G Xcode
else
cmake .. -DCMAKE_MODULE_PATH="$script_dir/modules" -DCMAKE_PREFIX_PATH="$prefix" -G Xcode
fi
cmake --build . --config $xcode_type --parallel
dmg_file="$script_dir/Colorman_macOS${major_version}_${machine_arch}_${build_type}.dmg"
if [ -f "$dmg_file" ]; then
rm -f "$dmg_file"
fi
# deployqt
$script_dir/scripts/macdeploy.sh -b "sources/colorman/$xcode_type/Colorman.app" -m "$prefix/bin/macdeployqt"
if [ "$sign_code" == "ON" ]; then
codesign --force --deep --sign "$code_sign_identity" --timestamp --options runtime "sources/colorman/$xcode_type/Colorman.app"
fi
# deploydmg
$script_dir/scripts/macdmg.sh -b "sources/colorman/$xcode_type/Colorman.app" -d "$dmg_file"
if [ "$sign_code" == "ON" ]; then
codesign --force --deep --sign "$code_sign_identity" --timestamp --options runtime --verbose "$dmg_file"
fi
}
# build types
if [ "$build_type" == "all" ]; then
build_colorman "debug"
build_colorman "release"
else
build_colorman "$build_type"
fi