Skip to content

Commit

Permalink
build.bash improvements (#297)
Browse files Browse the repository at this point in the history
This PR addresses feedback specific to build.bash raised in PR:
#238

Fixes #296 

<!-- readthedocs-preview cable start -->
----
📚 Documentation preview 📚:
https://cable--297.org.readthedocs.build/en/297/

<!-- readthedocs-preview cable end -->
  • Loading branch information
SeanBryan51 authored Jun 17, 2024
2 parents 43e6bcc + 3a1442e commit b17cbc0
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions build.bash
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
#!/usr/bin/env bash

nproc_default=4
ncpus_default=4

script_name=$(basename "${0}")

show_help() {
cat << EOF
Usage: ./$script_name [OPTIONS]
Usage: ./${script_name} [OPTIONS]
Build script wrapper around CMake. Supplied arguments that do not match the
options below will be passed to CMake when generating the build system.
Options:
--clean Delete build directory before invoking CMake.
--mpi Compile MPI executable.
--compiler <compiler>
-c, --clean Delete build directory before invoking CMake.
-m, --mpi Compile MPI executable.
-C, --compiler <compiler>
Specify the compiler to use.
-j <jobs> Specify the number of parallel jobs in the compilation. By
default this value is set to $nproc_default.
-n, --ncpus <ncpus>
Specify the number of parallel jobs in the compilation. By
default this value is set to ${ncpus_default}.
-h, --help Show this screen.
Enabling debug mode:
The release build is default. To enable debug mode, specify the CMake option
-DCMAKE_BUILD_TYPE=Debug when invoking $script_name.
-DCMAKE_BUILD_TYPE=Debug when invoking ${script_name}.
Enabling verbose output from Makefile builds:
To enable more verbose output from Makefile builds, specify the CMake option
-DCMAKE_VERBOSE_MAKEFILE=ON when invoking $script_name.
-DCMAKE_VERBOSE_MAKEFILE=ON when invoking ${script_name}.
EOF
}

cmake_args=(-DCMAKE_BUILD_TYPE=Release)
cmake_args=(-DCMAKE_BUILD_TYPE=Release -DCABLE_MPI=OFF)

# Argument parsing adapted and stolen from http://mywiki.wooledge.org/BashFAQ/035#Complex_nonstandard_add-on_utilities
while [ $# -gt 0 ]; do
case $1 in
--clean)
rm -r build
while [ ${#} -gt 0 ]; do
case ${1} in
-c|--clean)
rm -r build bin
exit
;;
--mpi)
-m|--mpi)
mpi=1
cmake_args+=(-DCABLE_MPI="ON")
;;
--compiler)
compiler=$2
-C|--compiler)
compiler=${2}
shift
;;
-j)
CMAKE_BUILD_PARALLEL_LEVEL=$2
-n|--ncpus)
CMAKE_BUILD_PARALLEL_LEVEL=${2}
shift
;;
-h|--help)
show_help
exit
;;
?*)
cmake_args+=("$1")
cmake_args+=("${1}")
;;
esac
shift
Expand All @@ -75,16 +77,17 @@ if hostname -f | grep gadi.nci.org.au > /dev/null; then
intel)
module add intel-compiler/2019.5.281
compiler_lib_install_dir=Intel
[[ -n $mpi ]] && module add intel-mpi/2019.5.281
[[ -n ${mpi} ]] && module add intel-mpi/2019.5.281
;;
gnu)
module add gcc/13.2.0
compiler_lib_install_dir=GNU
[[ -n $mpi ]] && module add openmpi/4.1.4
[[ -n ${mpi} ]] && module add openmpi/4.1.4
;;
?*)
echo -e "\nError: compiler ${compiler} is not supported.\n"
exit 1
;;
esac

# This is required so that the netcdf-fortran library is discoverable by
Expand Down Expand Up @@ -113,7 +116,7 @@ elif hostname -f | grep -E '(mc16|mcmini)' > /dev/null; then
esac
fi

export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:=$nproc_default}"
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:=${ncpus_default}}"

cmake -S . -B build "${cmake_args[@]}" &&\
cmake --build build &&\
Expand Down

0 comments on commit b17cbc0

Please sign in to comment.