|
| 1 | +#!/usr/bin/env bash |
| 2 | +# using the above shebang to be most-portable |
| 3 | +# https://stackoverflow.com/questions/10376206/what-is-the-preferred-bash-shebang |
| 4 | + |
| 5 | +# reference: https://stackoverflow.com/questions/2870992/automatic-exit-from-bash-shell-script-on-error |
| 6 | +# reference: https://pubs.opengroup.org/onlinepubs/009695399/utilities/set.html |
| 7 | +# reference: https://www.davidpashley.com/articles/writing-robust-shell-scripts/ |
| 8 | +# (-e) - fail-fast (exit on first simple-command failure) |
| 9 | +# (-u) - fail on attempted expansion of uninitialized variables |
| 10 | +# note: &&/|| lists should not be used, cause -e only applies to the last statement in them |
| 11 | +# note: -o pipefail would be nice to add, but it is not POSIX |
| 12 | +set -eu |
| 13 | + |
| 14 | +# reference: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself |
| 15 | +# handle users running this script from any directory |
| 16 | +# get the path to the directory containing this script |
| 17 | +# note: this solution is good enough (POSIX + works on multiple interpreters like sh/bash/dash) |
| 18 | +# note: there are flaws such as not handling symlinks or newline characters at end of directory names (very rare) |
| 19 | +path_to_script_dir="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )" |
| 20 | +echo "PATH TO SCRIPT DIRECTORY = $path_to_script_dir" |
| 21 | +path_to_project_root_dir="$path_to_script_dir/../../../.." |
| 22 | +echo "PATH TO PROJECT ROOT DIRECTORY = $path_to_project_root_dir" |
| 23 | +# execute rest of script from project root directory... |
| 24 | +cd "$path_to_project_root_dir" |
| 25 | + |
| 26 | +no_pause="false" |
| 27 | + |
| 28 | +# reference: https://stackoverflow.com/questions/9994295/what-does-mean-in-a-shell-script |
| 29 | +# reference: https://unix.stackexchange.com/questions/258341/echo-a-string-with-a-variable-in-it-without-expanding-evaluating-it |
| 30 | +# reference: https://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-a-bash-script |
| 31 | +# reference: https://stackoverflow.com/questions/9727695/bash-scripting-if-arguments-is-equal-to-this-string-define-a-variable-like-thi |
| 32 | +# reference: https://stackoverflow.com/questions/2953646/how-can-i-declare-and-use-boolean-variables-in-a-shell-script |
| 33 | +echo "args passed in: $@" |
| 34 | +for arg in "$@" |
| 35 | +do |
| 36 | + if [ $arg = "--no-pause" ] ; then |
| 37 | + no_pause="true" |
| 38 | + fi |
| 39 | +done |
| 40 | + |
| 41 | +# notes: |
| 42 | +# mkdir -p creates a nested directory structure |
| 43 | +# https://linux.die.net/man/1/mkdir |
| 44 | +# && is used to string together commands such that cmd1 && cmd2 will only run cmd2 if cmd1 succeeds |
| 45 | +# https://stackoverflow.com/questions/5130847/running-multiple-commands-in-one-line-in-shell |
| 46 | + |
| 47 | +# BUILD x86... |
| 48 | +echo "BUILDING ALL CONFIGS FOR x86..." |
| 49 | +mkdir -p build/vs2017/x86 |
| 50 | + |
| 51 | +# build all the VS2017 stuff (project files, the .sln, etc.) |
| 52 | +# -H<source of CMakeLists.txt> |
| 53 | +# -B<build directory> |
| 54 | +# -G "<generator>" |
| 55 | +# -D<variable to set in cmake cache> |
| 56 | +# I set the project-name_BUILD_EXTERNAL_TESTS=ON so that all targets in tests/ are built |
| 57 | +cmake -H. -Bbuild/vs2017/x86 -G "Visual Studio 15 2017" -Dproject-name_BUILD_EXTERNAL_TESTS=ON |
| 58 | + |
| 59 | +# actually run MSBuild in the build directory to generate all 4 configurations (4 executables) |
| 60 | +echo "COMPILING DEBUG CONFIG..." |
| 61 | +cmake --build build/vs2017/x86 --config Debug |
| 62 | +echo "COMPILING MINSIZEREL CONFIG..." |
| 63 | +cmake --build build/vs2017/x86 --config MinSizeRel |
| 64 | +echo "COMPILING RELEASE CONFIG..." |
| 65 | +cmake --build build/vs2017/x86 --config Release |
| 66 | +echo "COMPILING RELWITHDEBINFO CONFIG..." |
| 67 | +cmake --build build/vs2017/x86 --config RelWithDebInfo |
| 68 | + |
| 69 | +# END of building for x86 |
| 70 | + |
| 71 | +# BUILD x64... |
| 72 | +echo "BUILDING ALL CONFIGS FOR x64..." |
| 73 | +mkdir -p build/vs2017/x64 |
| 74 | +cmake -H. -Bbuild/vs2017/x64 -G "Visual Studio 15 2017 Win64" -Dproject-name_BUILD_EXTERNAL_TESTS=ON |
| 75 | +echo "COMPILING DEBUG CONFIG..." |
| 76 | +cmake --build build/vs2017/x64 --config Debug |
| 77 | +echo "COMPILING MINSIZEREL CONFIG..." |
| 78 | +cmake --build build/vs2017/x64 --config MinSizeRel |
| 79 | +echo "COMPILING RELEASE CONFIG..." |
| 80 | +cmake --build build/vs2017/x64 --config Release |
| 81 | +echo "COMPILING RELWITHDEBINFO CONFIG..." |
| 82 | +cmake --build build/vs2017/x64 --config RelWithDebInfo |
| 83 | +# END of building for x64 |
| 84 | + |
| 85 | +# reference: https://stackoverflow.com/questions/92802/what-is-the-linux-equivalent-to-dos-pause |
| 86 | +# reference: https://unix.stackexchange.com/questions/53036/read-a-single-key-gives-an-error |
| 87 | +# reference: https://stackoverflow.com/questions/15744421/read-command-doesnt-wait-for-input |
| 88 | +# pause the script at the end (unless --no-pause option is set), until user wants to close it (analog to DOS-pause) |
| 89 | +# note: -r is the only POSIX option for read utility, whereas most solutions are bash-only |
| 90 | +# reference: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html |
| 91 | +if [ $no_pause = "false" ] ; then |
| 92 | + # prompt user |
| 93 | + printf "Press [ENTER] to continue . . . " |
| 94 | + # read raw (-r) input into a dummy variable (_) |
| 95 | + read -r _ |
| 96 | +fi |
0 commit comments