-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun.sh
executable file
·194 lines (172 loc) · 5.39 KB
/
run.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
usage="$(basename "$0") [-h] [-d] [-n] [-c] [-v] source.cpp
-- build and run single-file allolib applications.
where:
-h show this help text
-d build debug version and run in debugger
-n build only. Don't run.
-c clean build
-v verbose build. Prints full cmake log and verbose build.
"
INITIALDIR=${PWD} # gives absolute path
# echo "Script executed from: ${INITIALDIR}"
# BASH_SOURCE has the script's path
# could be absolute, could be relative
SCRIPT_PATH=$(dirname ${BASH_SOURCE[0]})
FIRSTCHAR=${SCRIPT_PATH:0:1}
if [ ${FIRSTCHAR} == "/" ]; then
# it's asolute path
AL_LIB_PATH=${SCRIPT_PATH}
else
# SCRIPT_PATH was relative
AL_LIB_PATH=${INITIALDIR}/${SCRIPT_PATH}
fi
# Get the number of processors on OS X; Linux; or MSYS2, or take a best guess.
NPROC=$(grep --count ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu || nproc || echo 2)
# Save one core for the gui.
PROC_FLAG=$((NPROC - 1))
# resolve flags
BUILD_TYPE=Release
DO_CLEAN=0
IS_VERBOSE=0
VERBOSE_FLAG=OFF
RUN_APP=1
GENERATOR="Unix Makefiles"
CMAKE_BINARY="cmake"
if [ $# == 0 ]; then
echo "$usage"
exit 1
fi
while getopts "adncvhjx" opt; do
case "${opt}" in
a)
RUN_APP=0
;;
d)
BUILD_TYPE=Debug
POSTFIX=d # if release, there's no postfix
;;
n)
RUN_APP=0
;;
c)
DO_CLEAN=1
;;
v)
IS_VERBOSE=1
VERBOSE_MAKEFILE=-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
VERBOSE_FLAG=ON
;;
h) echo "$usage"
exit
;;
j)
if [ $(uname -s) == "Darwin" ]; then
CURRENT_OS="MACOS"
# echo "running on macOS"
# Check if ninja available
command -v ninja >/dev/null 2>&1 && { echo "Using Ninja"; export GENERATOR='Ninja'; }
fi
if [ $(uname -s) == "Linux" ]; then
CURRENT_OS="LINUX"
# Check if ninja available
command -v ninja >/dev/null 2>&1 && { echo "Using Ninja"; export GENERATOR='Ninja'; }
fi
;;
x)
GENERATOR_PLATFORM=x86
;;
\?) echo "$usage" >&2
exit 1
;;
esac
done
# consume options that were parsed
shift $(expr $OPTIND - 1 )
if [ $(uname -s) == "Darwin" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -j${PROC_FLAG}"
elif [ $(uname -s) == "Linux" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -j${PROC_FLAG}"
elif [ $(uname -s) != MINGW64* ] && [ "${GENERATOR_PLATFORM}" != "x86" ]; then
# WINDOWS_FLAGS=-DCMAKE_GENERATOR_PLATFORM=x64
echo Building for Visual Studio
if [ ! -d "C:\Program Files (x86)\Microsoft Visual Studio\2017" ] && [ ! -d "C:\Program Files (x86)\Microsoft Visual Studio\2019" ]; then
echo You must install Visual Studio 2017, 2019, or 2022 to use allolib
fi
if [ ! -f "${CMAKE_BINARY}" ]; then
CMAKE_BINARY="C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"
GENERATOR="Visual Studio 17 2022"
echo Tryng VS 2022 build.
fi
if [ ! -f "${CMAKE_BINARY}" ]; then
CMAKE_BINARY="C:/Program Files (x86)/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"
GENERATOR="Visual Studio 17 2022"
echo Tryng VS 2022 x86 build.
fi
if [ ! -f "${CMAKE_BINARY}" ]; then
CMAKE_BINARY="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"
GENERATOR="Visual Studio 16 2019"
echo Tryng VS 2019 build.
fi
if [ ! -f "${CMAKE_BINARY}" ]; then
CMAKE_BINARY="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"
GENERATOR="Visual Studio 15 2017 Win64"
echo Tryng VS 2017 build.
fi
if [ ! -f "${CMAKE_BINARY}" ]; then
echo Trying to use cmake on PATH as Visual Studio Cmake not found.
CMAKE_BINARY="cmake.exe"
fi
fi
if [ ${IS_VERBOSE} == 1 ]; then
echo "BUILD TYPE: ${BUILD_TYPE}"
fi
APP_FILE_INPUT="$1" # first argument (assumming we consumed all the options above)
APP_PATH=$(dirname ${APP_FILE_INPUT})
APP_FILE=$(basename ${APP_FILE_INPUT})
APP_NAME=${APP_FILE%.*} # remove extension (once, assuming .cpp)
TARGET_NAME=$(basename ${APP_FILE_INPUT} | sed 's/\.[^.]*$//')
# echo "app path: ${APP_PATH}"
# echo "app file: ${APP_FILE}"
# echo "app name: ${APP_NAME}"
(
cd ${APP_PATH}
if [ ${DO_CLEAN} == 1 ]; then
if [ ${IS_VERBOSE} == 1 ]; then
echo "cleaning build"
fi
rm -r build
rm -r build${BUILD_DIR_SUFFIX}
fi
mkdir -p build${BUILD_DIR_SUFFIX}
cd build${BUILD_DIR_SUFFIX}
mkdir -p ${APP_NAME}
cd ${APP_NAME}
mkdir -p ${BUILD_TYPE}
cd ${BUILD_TYPE}
# set -x enters debug mode and prints the command
set -x
"${CMAKE_BINARY}" -G "${GENERATOR}" -Wno-deprecated -DRTAUDIO_API_JACK=OFF -DRTMIDI_API_JACK=OFF -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DAL_APP_FILE=../../../${APP_FILE} -DAL_VERBOSE_OUTPUT=${VERBOSE_FLAG} ${VERBOSE_MAKEFILE} "${INITIALDIR}" > cmake_log.txt
set +x
if [ ${RUN_APP} == 1 ]; then
TARGET_NAME=${TARGET_NAME}_run
fi
if [ ${BUILD_TYPE} == "Debug" ]; then
TARGET_NAME=${TARGET_NAME}_debug
fi
# set -x enters debug mode and prints the command
set -x
"${CMAKE_BINARY}" --build . --target ${TARGET_NAME} --config ${BUILD_TYPE} -- ${BUILD_FLAGS}
set +x
)
APP_BUILD_RESULT=$?
# if app failed to build, exit
if [ ${APP_BUILD_RESULT} != 0 ]; then
echo "app ${APP_NAME} failed to build"
exit 1
fi
# run app
# go to where the binary is so we have cwd there
# (app's cmake is set to put binary in 'bin')
cd "${INITIALDIR}"
cd ${APP_PATH}/bin