#!/usr/bin/env fish function print_help_and_exit echo "\ Usage: setup_builds.sh [OPTIONS] compiler build-type Positionals: gcc Compile with gcc clang Compile with clang debug Build debug release Build release Options: --compiler Specify the compiler --type Specify the type of build -f,--force Overwrite existing build directories -h,--help Print this help message and exit " exit $argv[1] end function assert_dir if test ! -d "$argv[1]" if test -n "$argv[2]" echo "Invalid variable "$argv[2]": '"$argv[1]"' is not a directory" else echo "'"$argv[1]"' is not a directory" end exit 1 end end # common variables set tools_path (realpath (dirname (status -f))) set spartan_path_cmd $tools_path/spartan_path.fish set repo_root (eval $spartan_path_cmd "repo-root") set build_root "$repo_root"/"build" mkdir -p "$build_root" # Initialize the build directory. Expected arguments: , # Note: this method assumes the variables 'repot_root' and 'build_root' have # already been properly initialized function setup_build assert_dir $repo_root assert_dir $build_root set compiler "$argv[1]" set c_compiler (which cc) set build_type "$argv[2]" if test \( -z "$build_type" \) -o \( \( "$build_type" != debug \) -a \( "$build_type" != release \) \) print_help_and_exit 1 end if test "$build_type" = debug set build_type_arg Debug if test "$compiler" = gcc set compiler_arg "/usr/lib/ccache/g++" else # set compiler_arg "/usr/lib/ccache/clang++" set compiler_arg "clang++" set c_compiler (which clang) end else if test "$build_type" = release set build_type_arg Release if test "$compiler" = gcc set compiler_arg "g++" else set compiler_arg "clang++" end end if test \( -z "$compiler" \) -o \( \( "$compiler" != gcc \) -a \( "$compiler" != clang \) \) print_help_and_exit 1 end set build_dest $build_root"/"$compiler"/"$build_type echo "Set up build: "$compiler" "$build_type if test \( -z "$force" \) -a \( -d $build_dest \) echo "The build directory '"$build_dest"' already exists (use -f to overwrite)" return 1 end rm -rf "$build_dest" mkdir -p "$build_dest" cd "$build_dest" cmake -G Ninja -DCMAKE_BUILD_TYPE=$build_type_arg -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_C_COMPILER=$c_compiler -DCMAKE_CXX_COMPILER=$compiler_arg $repo_root end # The while loop below removes arguments (via shift) as it parses them. # Additional information that needs to be extracted from the arguments must be # done so before the loop is executed. set i 1 while test $i -le (count $argv) switch $argv[$i] case --compiler set i (math "$i + 1") set compiler $argv[$i] case clang set compiler clang case gcc set compiler gcc case --type set i (math "$i + 1") set build_type $argv[$i] case release set build_type release case debug set build_type debug case -f set force 1 case --force set force 1 case -h print_help_and_exit 0 case --help print_help_and_exit 0 case '*' print_help_and_exit 1 end set i (math "$i + 1") end echo "compiler in "$compiler echo "build type in "$build_type if test -n "$compiler" if test -n "$build_type" setup_build $compiler $build_type else # all builds for the specified compiler setup_build $compiler debug setup_build $compiler release end else if test -n "$build_type" # all builds for the specified build type setup_build gcc $build_type setup_build clang $build_type else # all builds setup_build gcc debug setup_build gcc release setup_build clang debug setup_build clang release end