diff --git a/build.bash b/build.bash index b4dd10f8d..75e3b3198 100755 --- a/build.bash +++ b/build.bash @@ -1,56 +1,58 @@ #!/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 + -c, --clean Delete build directory before invoking CMake. + -m, --mpi Compile MPI executable. + -C, --compiler Specify the compiler to use. - -j Specify the number of parallel jobs in the compilation. By - default this value is set to $nproc_default. + -n, --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) @@ -58,7 +60,7 @@ while [ $# -gt 0 ]; do exit ;; ?*) - cmake_args+=("$1") + cmake_args+=("${1}") ;; esac shift @@ -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 @@ -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 &&\