Skip to content

Commit

Permalink
Add build script wrapper around CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanBryan51 committed Jan 19, 2024
1 parent e670269 commit 6476b8c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Fortran
*.mod
*.o
*.o
build
80 changes: 80 additions & 0 deletions build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

show_help() {
cat << EOF
Usage: ./$(basename "${0}") [OPTIONS]
Build script wrapper around CMake.
Options:
--clean Delete build directory before invoking CMake.
--mpi Compile MPI executable.
-d, --debug Compile in debug mode.
-v, --verbose Enable verbose output when building the project.
-h, --help Show this screen.
EOF
}

# 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)
clean=1
;;
--mpi)
mpi=1
;;
-d|--debug)
debug=1
;;
-v|--verbose)
verbose=1
;;
-h|--help)
show_help
exit
;;
?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
esac
shift
done

if hostname -f | grep gadi.nci.org.au > /dev/null; then
module purge
module add intel-compiler/2019.5.281
module add netcdf/4.6.3
# This is required so that the netcdf-fortran library is discoverable by
# pkg-config:
module prepend-path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/Intel/pkgconfig/"
if [[ -n $mpi ]]; then
module add intel-mpi/2019.5.281
fi
fi

if [[ -n $clean ]]; then
rm -r build
fi

cmake_args=()

if [[ -n $debug ]]; then
cmake_args+=(-DCMAKE_BUILD_TYPE=Debug)
else
cmake_args+=(-DCMAKE_BUILD_TYPE=Release)
fi

if [[ -n $mpi ]]; then
cmake_args+=(-DCABLE_MPI="ON")
cmake_args+=(-DCMAKE_Fortran_COMPILER="mpif90")
fi

cmake_build_args=()
if [[ -n $verbose ]]; then
cmake_build_args+=(-v)
fi

cmake -S . -B build "${cmake_args[@]}"
cmake --build build -j 4 "${cmake_build_args[@]}"

0 comments on commit 6476b8c

Please sign in to comment.