-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.bash
More file actions
executable file
·170 lines (142 loc) · 4.66 KB
/
build.bash
File metadata and controls
executable file
·170 lines (142 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# Exit immediately on error
set -e
ncpus_default=4
script_name=$(basename "${0}")
show_help() {
cat << EOF
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:
-c, --clean Delete build directory before invoking CMake.
-m, --mpi Compile MPI executable.
-C, --compiler <compiler>
Specify the compiler to use.
-n, --ncpus <ncpus>
Specify the number of parallel jobs in the compilation. By
default this value is set to ${ncpus_default}.
-l, --library <coupled-app>
Build just CABLE science library (libscable_science.a), for a
specified coupled application. Options for the coupled
application are ESM1.6.
-t, --tests Enable CABLE unit tests.
-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}.
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}.
EOF
}
# DEFAULTS
# Configure
cmake_args=(-DCMAKE_BUILD_TYPE=Release -DCABLE_MPI=OFF -DCABLE_LIBRARY=OFF)
# Build
build_args=()
# Install
do_install=1
# Tests
do_tests=0
# Argument parsing adapted and stolen from http://mywiki.wooledge.org/BashFAQ/035#Complex_nonstandard_add-on_utilities
while [ ${#} -gt 0 ]; do
case ${1} in
-c|--clean)
rm -rf build bin
exit
;;
-m|--mpi)
mpi=1
cmake_args+=(-DCABLE_MPI="ON")
;;
-l|--library)
cmake_args+=(-DCABLE_LIBRARY="ON")
cmake_args+=(-DCABLE_LIBRARY_TARGET="${2}")
do_install=0 # Disable installation when only building the science library
shift
;;
-C|--compiler)
compiler=${2}
shift
;;
-n|--ncpus)
CMAKE_BUILD_PARALLEL_LEVEL=${2}
shift
;;
-t|--tests)
cmake_args+=(-DCABLE_TESTS="ON")
do_tests=1
;;
-h|--help)
show_help
exit
;;
?*)
cmake_args+=("${1}")
;;
esac
shift
done
if hostname -f | grep gadi.nci.org.au > /dev/null; then
: "${compiler:=intel}"
. /etc/bashrc
module purge
module add cmake/3.24.2
module add netcdf/4.6.3
case ${compiler} in
intel)
if [ $do_tests -eq 1 ]; then
# This is required to as Fortuno requires Intel Fortran
# 2024.0.0 or higher
module add intel-compiler-llvm/2024.0.2
else
module add intel-compiler/2019.5.281
fi
compiler_lib_install_dir=Intel
[[ -n ${mpi} ]] && module add intel-mpi/2019.5.281
;;
gnu)
module add gcc/14.1.0
compiler_lib_install_dir=GNU
[[ -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
# pkg-config:
prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/${compiler_lib_install_dir}/pkgconfig"
if module is-loaded openmpi; then
# This is required so that the openmpi MPI libraries are discoverable
# via CMake's `find_package` mechanism:
prepend_path CMAKE_PREFIX_PATH "${OPENMPI_BASE}/include/${compiler_lib_install_dir}"
fi
elif hostname -f | grep -E '(mc16|mcmini)' > /dev/null; then
: "${compiler:=gnu}"
case ${compiler} in
gnu)
export PKG_CONFIG_PATH=/usr/local/netcdf-fortran-4.6.1-gfortran/lib/pkgconfig:${PKG_CONFIG_PATH}
export PKG_CONFIG_PATH=${HOMEBREW_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}
cmake_args+=(-DCMAKE_Fortran_COMPILER=gfortran)
;;
?*)
echo -e "\nError: compiler ${compiler} is not supported.\n"
exit 1
;;
esac
fi
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:=${ncpus_default}}"
# Configure by default
cmake -S . -B build "${cmake_args[@]}"
# Build requested targets
cmake --build build "${build_args[@]}"
# Install if requested
if [ $do_install -eq 1 ]; then
cmake --install build --prefix .
fi
if [ $do_tests -eq 1 ]; then
ctest --test-dir build --verbose
fi