Added logging, refactored versioning; STB is now included

- Added logging
- Rewrote versioning code
- Refactored dependency management
  - STB (stb_image.h) is now included
  - All other dependencies now use find_package
- Cross-compilation from Linux to Windows is now possible
This commit is contained in:
2022-10-31 21:12:48 +03:00
parent da10f7c5cd
commit a110c9de03
21 changed files with 3217 additions and 198 deletions

View File

@ -1,12 +1,15 @@
#!/bin/bash
usage=\
"Usage: build.sh [OPTIONS...] [TOOL-ARGUMENT...]
"Usage: build.sh [OPTIONS...]
Build and run the game.
Options:
--debug make a debug build (default)
--release make a release build
--build-id=ID set the build ID. Default is dev.
--cmake-gen=ARGS pass additional arguments to pass to cmake when
generating build files. ARGS is the ;-separated list.
--dont-generate don't generate build instructions; use existing
configuration if building
--dont-build don't build; run existing binaries or generate build
@ -25,6 +28,10 @@ Environment variables:
CMAKE cmake executable
VALGRIND valgrind executable
private.sh variables:
private_cmake_gen_args array of additional arguments to pass to cmake when
generating build files
See also: tools/cppcheck/use-cppcheck.sh --help
tools/clang-format/use-clang-format.sh --help
tools/setup.sh --help"
@ -38,6 +45,7 @@ source "$rsrc/bashlib.sh"
build_type=Debug
do_generate=true
cmake_gen_args=()
do_build=true
run_type=Normal
@ -47,53 +55,63 @@ debug_vulkan=''
memcheck_args=()
for arg in "$@"; do
if [ $is_cmake_arg ]; then
cmake_args+=("$arg")
else
case "$arg" in
-h | --help )
echo "$usage"
exit
;;
--debug )
build_type=Debug
;;
--release )
build_type=Release
;;
--debug-vulkan )
debug_vulkan=true
;;
-R | --run )
do_run=true
;;
--memcheck )
do_run=true
run_type=memcheck
;;
--memcheck=* )
do_run=true
run_type=memcheck
readarray -t -d ';' new_memcheck_args <<<"${arg#*=};"
unset new_memcheck_args[-1]
memcheck_args+=("${new_memcheck_args[@]}")
unset new_memcheck_args
;;
--dont-generate )
do_generate=''
;;
--dont-build )
do_build=''
;;
* )
fail "Unknown option '$arg'"
;;
esac
fi
case "$arg" in
-h | --help )
echo "$usage"
exit
;;
--debug )
build_type=Debug
;;
--release )
build_type=Release
;;
--build-id )
fail "Option --build-id=ID requires a parameter"
;;
--build-id=* )
build_id="${arg#*=}"
;;
--cmake-gen )
fail "Option --cmake-gen=ARGS requires a parameter"
;;
--cmake-gen=* )
readarray -t -d ';' new_cmake_gen_args <<<"${arg#*=};"
unset new_cmake_gen_args[-1]
cmake_gen_args+=("${new_cmake_gen_args[@]}")
unset new_cmake_gen_args
;;
--debug-vulkan )
debug_vulkan=true
;;
-R | --run )
do_run=true
;;
--memcheck )
do_run=true
run_type=memcheck
;;
--memcheck=* )
do_run=true
run_type=memcheck
readarray -t -d ';' new_memcheck_args <<<"${arg#*=};"
unset new_memcheck_args[-1]
memcheck_args+=("${new_memcheck_args[@]}")
unset new_memcheck_args
;;
--dont-generate )
do_generate=''
;;
--dont-build )
do_build=''
;;
* )
fail "Unknown option '$arg'"
;;
esac
done
if [ -z "$do_build" -a -z "$do_generate" -a ${#cmake_args[@]} != 0 ]; then
if [ -z "$do_build" -a -z "$do_generate" -a ${#cmake_gen_args[@]} != 0 ]; then
fail "CMake arguments are set, but no build is requested. Aborting"
fi
@ -107,12 +125,23 @@ fi
find_cmd CMAKE cmake
if [ $do_generate ]; then
cmake_gen_managed_args=(
-DCMAKE_BUILD_TYPE=$build_type
-DVULKAN_ERROR_CHECKING=`[ $debug_vulkan ] && echo ON || echo OFF`
-UBUILD_ID
)
[ -n "${build_id+x}" ] && cmake_gen_managed_args+=(
-DBUILD_ID="$build_id"
)
echo_and_run "$CMAKE" \
-B "$build_dir" \
-S "$source_dir" \
-DCMAKE_BUILD_TYPE=$build_type \
-DVULKAN_ERROR_CHECKING=`[ $debug_vulkan ] && echo ON || echo OFF` \
"${cmake_args[@]}" \
"${cmake_gen_managed_args[@]}" \
"${private_cmake_gen_args[@]}" \
"${cmake_gen_args[@]}" \
|| fail "Could not generate build files"
fi

View File

@ -55,9 +55,7 @@ $unstaged_changes"
fi
git diff -U0 --no-color --relative HEAD \
'*.cpp' \
'*.h' \
'*.inl' \
{desktop,main}/{'*.cpp','*.h','*.inl'} \
| command "$CLANG_FORMAT_DIFF" -p1 -style="$style" -i --verbose
exit_code="$?"
git add "$root_dir"

View File

@ -13,3 +13,6 @@ missingInclude:*
# Shut up. Just shut up.
unmatchedSuppression:*
# Do not check third-party libraries
*:*lib*

View File

@ -74,7 +74,6 @@ function check_cmd() {
unset found
}
check_cmd pkg-config
check_cmd cmake
check_cmd python3
check_cmd glslc
@ -91,8 +90,8 @@ fi
# Try generating build files
if FAIL_SILENTLY=true find_cmd found_cmake cmake; then
if CMAKE="$found_cmake" "$tools_dir/build.sh" --dont-build; then
if FAIL_SILENTLY=true find_cmd CMAKE cmake; then
if CMAKE="$CMAKE" "$tools_dir/build.sh" --dont-build; then
echo 'CMake did not encounter any problems'
else
echo 'Could not generate build files; libraries are probably missing'
@ -113,8 +112,8 @@ fail "Could not find the following required commands or libraries:
You can resolve these errors in the following ways:
1. Install required software packages. See README for specific instructions.
2. Edit PATH, PKG_CONFIG_PATH or CMAKE_MODULE_PATH environment variables in
tools/private.sh to include your installation directories.
2. Edit PATH or CMAKE_MODULE_PATH environment variables in tools/private.sh
to include your installation directories.
"