Skip to content

Commit

Permalink
Add --compiler flag and GNU compiler support
Browse files Browse the repository at this point in the history
Flags for release and debug configurations for the GNU compiler were
taken from build.ksh (CABLE-POP_TRENDY branch).
  • Loading branch information
SeanBryan51 committed Mar 7, 2024
1 parent 4b9b87e commit c522478
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
)
endif()

set(CABLE_GNU_Fortran_FLAGS -cpp -ffree-form -ffixed-line-length-132)
set(CABLE_GNU_Fortran_FLAGS_DEBUG -O -g -pedantic-errors -Wall -W -Wno-maybe-uninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan)
set(CABLE_GNU_Fortran_FLAGS_RELEASE -O3 -Wno-aggressive-loop-optimizations)
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(
CABLE_Fortran_FLAGS
${CABLE_GNU_Fortran_FLAGS}
"$<$<CONFIG:Release>:${CABLE_GNU_Fortran_FLAGS_RELEASE}>"
"$<$<CONFIG:Debug>:${CABLE_GNU_Fortran_FLAGS_DEBUG}>"
)
endif()

add_library(
cable_common_objlib
OBJECT
Expand Down
22 changes: 19 additions & 3 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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>
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.
-h, --help Show this screen.
Expand Down Expand Up @@ -43,6 +45,10 @@ while [ $# -gt 0 ]; do
mpi=1
cmake_args+=(-DCABLE_MPI="ON")
;;
--compiler)
compiler=$2
shift
;;
-j)
CMAKE_BUILD_PARALLEL_LEVEL=$2
shift
Expand All @@ -59,14 +65,24 @@ while [ $# -gt 0 ]; do
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 intel-compiler/2019.5.281
module add netcdf/4.6.3
case ${compiler} in
Intel)
module add intel-compiler/2019.5.281
;;
GNU)
module add gcc/13.2.0
;;
esac

# This is required so that the netcdf-fortran library is discoverable by
# pkg-config:
prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/Intel/pkgconfig"
prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/${compiler}/pkgconfig"

if [[ -n $mpi ]]; then
module add intel-mpi/2019.5.281
Expand All @@ -75,7 +91,7 @@ if hostname -f | grep gadi.nci.org.au > /dev/null; then
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/Intel"
prepend_path CMAKE_PREFIX_PATH "${OPENMPI_BASE}/include/${compiler}"
fi
fi

Expand Down

0 comments on commit c522478

Please sign in to comment.