Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.bash improvements #297

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading