From 8c14c9fb7fa22cc5008e0ffcf4202f59583d637b Mon Sep 17 00:00:00 2001 From: Sean Bryan Date: Mon, 4 Mar 2024 15:58:38 +1100 Subject: [PATCH] Add --compiler flag and GNU compiler support Flags for release and debug configurations for the GNU compiler were taken from build.ksh (CABLE-POP_TRENDY branch). --- CMakeLists.txt | 12 ++++++++++++ build.bash | 25 ++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01065cbfb..427b595dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} + "$<$:${CABLE_GNU_Fortran_FLAGS_RELEASE}>" + "$<$:${CABLE_GNU_Fortran_FLAGS_DEBUG}>" + ) +endif() + add_library( cable_common_objlib OBJECT diff --git a/build.bash b/build.bash index b6b4d8c1d..703bb7acb 100755 --- a/build.bash +++ b/build.bash @@ -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 + Specify the compiler to use. -j Specify the number of parallel jobs in the compilation. By default this value is set to $nproc_default. -h, --help Show this screen. @@ -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 @@ -59,14 +65,27 @@ 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 + ;; + ?*) + 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/Intel/pkgconfig" + prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/${compiler}/pkgconfig" if [[ -n $mpi ]]; then module add intel-mpi/2019.5.281 @@ -75,7 +94,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