diff --git a/CMakeLists.txt b/CMakeLists.txt index 76cd4ba30e..cc1da583b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,37 +6,31 @@ project( LANGUAGES Fortran ) -option(CABLE_MPI "Build the MPI executable" OFF) - # third party libs +find_package(MPI REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(NETCDF REQUIRED IMPORTED_TARGET "netcdf-fortran") -if(CABLE_MPI) - find_package(MPI REQUIRED) -endif() +set( + CABLE_LINK_LIBRARIES + PkgConfig::NETCDF + MPI::MPI_Fortran +) set(CABLE_INTEL_Fortran_FLAGS -fp-model precise) set(CABLE_INTEL_Fortran_FLAGS_DEBUG -O0 -g -traceback -fpe0) set(CABLE_INTEL_Fortran_FLAGS_RELEASE -O2) +if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") + set( + CABLE_Fortran_FLAGS + ${CABLE_INTEL_Fortran_FLAGS} + "$<$:${CABLE_INTEL_Fortran_FLAGS_RELEASE}>" + "$<$:${CABLE_INTEL_Fortran_FLAGS_DEBUG}>" + ) +endif() -# CMake $<...> syntax is explained here: -# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#introduction -set(CABLE_EXE_NAME "$,cable-mpi,cable>") - -set( - CABLE_SRCS_SERIAL - src/offline/cable_driver.F90 -) -set( - CABLE_SRCS_MPI - src/offline/cable_mpidrv.F90 - src/offline/cable_mpicommon.F90 - src/offline/cable_mpimaster.F90 - src/offline/cable_mpiworker.F90 - src/science/pop/pop_mpi.F90 -) -set( - CABLE_SRCS_COMMON +add_library( + cable_common_objlib + OBJECT src/science/casa-cnp/bgcdriver.F90 src/science/casa-cnp/biogeochem_casa.F90 src/offline/cable_abort.F90 @@ -146,30 +140,27 @@ set( src/science/roughness/roughnessHGT_effLAI_cbl.F90 src/offline/spincasacnp.F90 ) -set( - CABLE_SRCS - "$,${CABLE_SRCS_MPI},${CABLE_SRCS_SERIAL}>" - ${CABLE_SRCS_COMMON} -) +target_compile_options(cable_common_objlib PRIVATE ${CABLE_Fortran_FLAGS}) +target_link_libraries(cable_common_objlib ${CABLE_LINK_LIBRARIES}) -add_executable(cable ${CABLE_SRCS}) - -set_target_properties(cable PROPERTIES OUTPUT_NAME ${CABLE_EXE_NAME}) - -if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") - target_compile_options( - cable - PRIVATE - ${CABLE_INTEL_Fortran_FLAGS} - "$<$:${CABLE_INTEL_Fortran_FLAGS_RELEASE}>" - "$<$:${CABLE_INTEL_Fortran_FLAGS_DEBUG}>" - ) -endif() - -target_link_libraries( +add_executable( cable - PkgConfig::NETCDF - "$<$:MPI::MPI_Fortran>" + src/offline/cable_driver.F90 + "$" +) +target_compile_options(cable PRIVATE ${CABLE_Fortran_FLAGS}) +target_link_libraries(cable ${CABLE_LINK_LIBRARIES}) + +add_executable( + cable-mpi + src/offline/cable_mpidrv.F90 + src/offline/cable_mpicommon.F90 + src/offline/cable_mpimaster.F90 + src/offline/cable_mpiworker.F90 + src/science/pop/pop_mpi.F90 + "$" ) +target_compile_options(cable-mpi PRIVATE ${CABLE_Fortran_FLAGS}) +target_link_libraries(cable-mpi ${CABLE_LINK_LIBRARIES}) -install(TARGETS cable RUNTIME) +install(TARGETS cable cable-mpi RUNTIME) diff --git a/build.bash b/build.bash index b356fded2e..af2bf7d395 100755 --- a/build.bash +++ b/build.bash @@ -8,7 +8,6 @@ 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. @@ -22,9 +21,6 @@ while [ $# -gt 0 ]; do --clean) clean=1 ;; - --mpi) - mpi=1 - ;; -d|--debug) debug=1 ;; @@ -45,15 +41,13 @@ done if hostname -f | grep gadi.nci.org.au > /dev/null; then module purge module add intel-compiler/2019.5.281 + module add intel-mpi/2019.5.281 module add netcdf/4.6.3 # This is required so that the netcdf-fortran library is discoverable by # pkg-config (Note, we manually prepend to PKG_CONFIG_PATH instead of # using `module prepend-path` so that we can invoke this script successfully # in benchcab): export PKG_CONFIG_PATH="${NETCDF_BASE}/lib/Intel/pkgconfig/:${PKG_CONFIG_PATH}" - if [[ -n $mpi ]]; then - module add intel-mpi/2019.5.281 - fi fi if [[ -n $clean ]]; then @@ -66,10 +60,8 @@ if [[ -n $debug ]]; then else cmake_args+=(-DCMAKE_BUILD_TYPE=Release) fi -if [[ -n $mpi ]]; then - cmake_args+=(-DCABLE_MPI="ON") - cmake_args+=(-DMPI_Fortran_COMPILER="mpif90") -fi + +cmake_args+=(-DMPI_Fortran_COMPILER="mpif90") cmake_build_args=() if [[ -n $verbose ]]; then