Skip to content

Commit

Permalink
Merge pull request #86 from COSIMA/fox_as_external_dep
Browse files Browse the repository at this point in the history
Treat FoX as an external dependency
  • Loading branch information
micaeljtoliveira authored Nov 28, 2023
2 parents aa16188 + d76d8ac commit 808a6e5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build_type: [Debug, Release]

container:
image: ghcr.io/cosima/access-om3-ci-images/${{matrix.compiler}}:0.4.1
image: ghcr.io/cosima/access-om3-ci-images/${{matrix.compiler}}:main

steps:
- name: Checkout
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
[submodule "share/CESM_share"]
path = share/CESM_share
url = https://github.com/ESCOMP/CESM_share.git
[submodule "CDEPS/fox"]
path = CDEPS/fox
url = https://github.com/ESMCI/fox/
[submodule "WW3/WW3"]
path = WW3/WW3
url = https://github.com/ESCOMP/WW3
17 changes: 6 additions & 11 deletions CDEPS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_fortran_library(OM3_cdeps_common mod/common STATIC)
target_include_directories(OM3_cdeps_common PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_common
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX PIO::PIO_Fortran
)
target_sources(OM3_cdeps_common PRIVATE
CDEPS/streams/dshr_methods_mod.F90
Expand All @@ -23,7 +23,7 @@ add_fortran_library(OM3_cdeps_datm mod/datm STATIC)
target_include_directories(OM3_cdeps_datm PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_datm
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom OM3_cdeps_common PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX OM3_cdeps_common PIO::PIO_Fortran
)
target_sources(OM3_cdeps_datm PRIVATE
CDEPS/datm/datm_datamode_cfsr_mod.F90
Expand All @@ -42,7 +42,7 @@ add_fortran_library(OM3_cdeps_docn mod/docn STATIC)
target_include_directories(OM3_cdeps_docn PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_docn
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom OM3_cdeps_common PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX OM3_cdeps_common PIO::PIO_Fortran
)
target_sources(OM3_cdeps_docn PRIVATE
CDEPS/docn/docn_datamode_aquaplanet_mod.F90
Expand All @@ -59,7 +59,7 @@ add_fortran_library(OM3_cdeps_dice mod/dice STATIC)
target_include_directories(OM3_cdeps_dice PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_dice
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom OM3_cdeps_common PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX OM3_cdeps_common PIO::PIO_Fortran
)
target_sources(OM3_cdeps_dice PRIVATE
CDEPS/dice/dice_datamode_ssmi_mod.F90
Expand All @@ -72,7 +72,7 @@ add_fortran_library(OM3_cdeps_dwav mod/dwav STATIC)
target_include_directories(OM3_cdeps_dwav PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_dwav
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom OM3_cdeps_common PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX OM3_cdeps_common PIO::PIO_Fortran
)
target_sources(OM3_cdeps_dwav PRIVATE
CDEPS/dwav/wav_comp_nuopc.F90
Expand All @@ -83,13 +83,8 @@ add_fortran_library(OM3_cdeps_drof mod/drof STATIC)
target_include_directories(OM3_cdeps_drof PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>)
target_link_libraries(OM3_cdeps_drof
PUBLIC esmf
PRIVATE OM3_share OM3_cmeps FoX_dom OM3_cdeps_common PIO::PIO_Fortran
PRIVATE OM3_share OM3_cmeps FoX::FoX OM3_cdeps_common PIO::PIO_Fortran
)
target_sources(OM3_cdeps_drof PRIVATE
CDEPS/drof/rof_comp_nuopc.F90
)

### Subdirectories

## Build FoX
add_subdirectory(fox)
1 change: 0 additions & 1 deletion CDEPS/fox
Submodule fox deleted from 4ff17b
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ find_package(MPI REQUIRED)
if(OM3_OPENMP)
find_package(OpenMP REQUIRED)
endif()
find_package(FoX 4.1.2 REQUIRED)
find_package(NetCDF 4.7.3 REQUIRED Fortran)
find_package(ESMF 8.3.0 MODULE REQUIRED)
find_package(fms COMPONENTS R8 REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ OPENMPI_VERSION=4.1.4

module purge
module load cmake/3.24.2
module use /g/data/ik11/spack/0.20.1/modules/access-om3/0.2.0/linux-rocky8-x86_64 # requires membership of "ik11" group
module load esmf/8.4.2 fms/git.2021.03.01=2021.03.01 parallelio/2.5.10
module use /g/data/ik11/spack/0.20.1/modules/access-om3/0.x.0/linux-rocky8-cascadelake # requires membership of "ik11" group
module load esmf/8.4.2 fms/git.2021.03.01=2021.03.01 parallelio/2.5.10 fortranxml/4.1.2
module load intel-compiler/${COMPILER_VERSION} openmpi/${OPENMPI_VERSION}

cd ${SCRIPT_DIR}
Expand Down
56 changes: 56 additions & 0 deletions cmake/FindFoX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# We will use pkgconfig to find the library
find_package(PkgConfig REQUIRED)

## Prepare arguments to pass to pkg_search_module

# QUIET
set(_quiet_arg)
if (FoX_FIND_QUIETLY)
list(APPEND _quiet_arg QUIET)
endif ()

# REQUIRED
set(_required_arg)
if (FoX_FIND_REQUIRED)
list(APPEND _required_arg REQUIRED)
endif ()

# Construct the moduleSpec to search for
if (DEFINED FoX_FIND_VERSION_RANGE)
# Can only parse the minimum requirement
list(APPEND PKG_MODULE_SPECS "fox>=${FoX_FIND_VERSION_MIN}")
elseif ({FoX_FIND_VERSION_EXACT)
# Requesting exact version
list(APPEND PKG_MODULE_SPECS "fox=${FoX_FIND_VERSION}")
elseif (DEFINED FoX_FIND_VERSION)
# Otherwise treat the request as minimum requirement
list(APPEND PKG_MODULE_SPECS "fox>=${FoX_FIND_VERSION}")
else ()
# Fallthrough if no version is required
list(APPEND PKG_MODULE_SPECS "fox")
endif ()

## Call pkg-config
if (CMAKE_VERSION VERSION_LESS 3.28)
# https://gitlab.kitware.com/cmake/cmake/-/issues/25228
set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1)
endif ()
if (CMAKE_VERSION VERSION_LESS 3.22)
# Back-porting
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6345
set(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} 1)
endif ()
pkg_search_module(FoX
${_required_arg} ${_quiet_arg}
IMPORTED_TARGET
${PKG_MODULE_SPECS})

## Create alias if package was found by pkg-config
if (FoX_FOUND)
add_library(FoX::FoX ALIAS PkgConfig::FoX)
endif ()

# Sanitize local variables
set(PKG_MODULE_SPECS)
set(_quiet_arg)
set(_required_arg)

0 comments on commit 808a6e5

Please sign in to comment.