Skip to content

Commit

Permalink
Merge pull request ESCOMP#40 from hafs-community/feature/hafs_cdeps_pr
Browse files Browse the repository at this point in the history
Updating CDEPS CMake build system to compile with HAFS
  • Loading branch information
uturuncoglu authored Jan 20, 2021
2 parents 0b3a68e + 5da53f4 commit 3b1ec5a
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 72 deletions.
59 changes: 52 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

message("CMAKE_MODULE_PATH is ${CMAKE_MODULE_PATH}")

find_package(ESMF REQUIRED)
if (DEFINED PIO)
set(PIO_PATH ${PIO})
if (TARGET esmf)
message("Target esmf is already found. Skip find_package ...")
else()
set(PIO_PATH $ENV{PIO})
find_package(ESMF REQUIRED)
endif()

if (DEFINED ENV{PIO_ROOT})
message("PIO_ROOT is $ENV{PIO_ROOT}")
else()
if (DEFINED PIO)
set(PIO_PATH ${PIO})
else()
set(PIO_PATH $ENV{PIO})
endif()
find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH})
endif()
find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH})

if (NOT DEFINED MPILIB OR NOT ${MPILIB} STREQUAL "mpi-serial")
find_package(MPI REQUIRED)
Expand All @@ -53,5 +62,41 @@ foreach(COMP datm dice dlnd docn drof dwav)
add_subdirectory("${COMP}")
endforeach(COMP)

install(TARGETS streams dshr
LIBRARY DESTINATION lib)
target_include_directories(streams PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/share>
$<INSTALL_INTERFACE:mod>)
target_include_directories(streams PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>
$<INSTALL_INTERFACE:mod>)
target_include_directories(dshr PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/share>
$<INSTALL_INTERFACE:mod>)
target_include_directories(dshr PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fox/include>
$<INSTALL_INTERFACE:mod>)
target_include_directories(dshr PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/streams>
$<INSTALL_INTERFACE:mod>)

foreach(COMP datm dice dlnd docn drof dwav)
target_include_directories(${COMP} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/share>
$<INSTALL_INTERFACE:mod>)
target_include_directories(${COMP} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/streams>
$<INSTALL_INTERFACE:mod>)
target_include_directories(${COMP} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/dshr>
$<INSTALL_INTERFACE:mod>)

install(TARGETS ${COMP}
EXPORT ${COMP}
LIBRARY DESTINATION lib
COMPONENT Library)
install(EXPORT ${COMP}
DESTINATION lib/cmake)
endforeach(COMP)

foreach(DEPS streams dshr cdeps_share FoX_dom FoX_wxml FoX_sax FoX_common FoX_utils FoX_fsys)
if(NOT BLD_STANDALONE AND ${DEPS} STREQUAL "cdeps_share")
continue()
endif()
install(TARGETS ${DEPS}
EXPORT ${DEPS}
LIBRARY DESTINATION lib
COMPONENT Library)
install(EXPORT ${DEPS}
DESTINATION lib/cmake)
endforeach(COMP)
36 changes: 24 additions & 12 deletions datm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
project(datm Fortran)
set(SRCFILES atm_comp_nuopc.F90
datm_datamode_clmncep_mod.F90
datm_datamode_cplhist_mod.F90
datm_datamode_core2_mod.F90
datm_datamode_jra_mod.F90
datm_datamode_era5_mod.F90)

add_library(datm atm_comp_nuopc.F90
datm_datamode_clmncep_mod.F90
datm_datamode_cplhist_mod.F90
datm_datamode_core2_mod.F90
datm_datamode_jra_mod.F90
datm_datamode_era5_mod.F90)

foreach(FILE ${SRCFILES})
if(EXISTS "${CASEROOT}/SourceMods/src.datm/${FILE}")
list(REMOVE_ITEM SRCFILES ${FILE})
list(APPEND SRCFILES "${CASEROOT}/SourceMods/src.datm/${FILE}")
message("Using ${FILE} from ${CASEROOT}/SourceMods/src.datm")
endif()
endforeach()

message("DATM srcfiles are ${SRCFILES}")

add_library(datm ${SRCFILES})

add_dependencies(datm dshr streams)
target_include_directories (datm PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (datm PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (datm PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
target_include_directories (datm PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (datm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/dshr)
target_include_directories (datm PRIVATE ${CMAKE_SOURCE_DIR})
target_include_directories (datm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/share)
target_include_directories (datm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/streams)
target_include_directories (datm PRIVATE ${PIO_Fortran_INCLUDE_DIR})
16 changes: 10 additions & 6 deletions dice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ foreach(FILE ${SRCFILES})
message("Using ${FILE} from ${CASEROOT}/SourceMods/src.dice")
endif()
endforeach()

message("DICE srcfiles are ${SRCFILES}")

add_library(dice ${SRCFILES})

target_include_directories (dice PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (dice PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (dice PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
add_dependencies(dice dshr streams)
target_include_directories (dice PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (dice PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dshr")
target_include_directories (dice PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories (dice PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/share")
target_include_directories (dice PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/streams")
target_include_directories (dice PRIVATE "${PIO_Fortran_INCLUDE_DIR}")
15 changes: 9 additions & 6 deletions dlnd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ foreach(FILE ${SRCFILES})
endif()
endforeach()

message("DLND srcfiles are ${SRCFILES}")

add_library(dlnd ${SRCFILES})

target_include_directories (dlnd PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (dlnd PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (dlnd PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
add_dependencies(dlnd dshr streams)
target_include_directories (dlnd PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (dlnd PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dshr")
target_include_directories (dlnd PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories (dlnd PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/share")
target_include_directories (dlnd PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/streams")
target_include_directories (dlnd PRIVATE "${PIO_Fortran_INCLUDE_DIR}")
16 changes: 9 additions & 7 deletions docn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ foreach(FILE ${SRCFILES})
endif()
endforeach()

add_library(docn ${SRCFILES})
message("DOCN srcfiles are ${SRCFILES}")

add_library(docn ${SRCFILES})

target_include_directories (docn PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (docn PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (docn PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
add_dependencies(docn dshr streams)
target_include_directories (docn PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (docn PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/dshr)
target_include_directories (docn PRIVATE ${CMAKE_SOURCE_DIR})
target_include_directories (docn PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/share)
target_include_directories (docn PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/streams)
target_include_directories (docn PRIVATE ${PIO_Fortran_INCLUDE_DIR})
18 changes: 12 additions & 6 deletions docn/docn_datamode_copyall_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,22 @@ subroutine docn_datamode_copyall_init_pointers(exportState, ocn_fraction, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_t' , fldptr1=So_t , rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_s' , fldptr1=So_s , rc=rc)
call dshr_state_getfldptr(exportState, 'So_s' , fldptr1=So_s , allowNullReturn=.true., rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_u' , fldptr1=So_u , rc=rc)
call dshr_state_getfldptr(exportState, 'So_u' , fldptr1=So_u , allowNullReturn=.true., rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_v' , fldptr1=So_v , rc=rc)
call dshr_state_getfldptr(exportState, 'So_v' , fldptr1=So_v , allowNullReturn=.true., rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

So_u(:) = 0.0_r8
So_v(:) = 0.0_r8
So_s(:) = ocnsalt
if (associated(So_u)) then
So_u(:) = 0.0_r8
end if
if (associated(So_v)) then
So_v(:) = 0.0_r8
end if
if (associated(So_s)) then
So_s(:) = ocnsalt
end if
So_t(:) = TkFrz

! Set export state ocean fraction (So_omask)
Expand Down
15 changes: 9 additions & 6 deletions drof/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ foreach(FILE ${SRCFILES})
endif()
endforeach()

message("DROF srcfiles are ${SRCFILES}")

add_library(drof ${SRCFILES})

target_include_directories (drof PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (drof PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (drof PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
add_dependencies(drof dshr streams)
target_include_directories (drof PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (drof PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dshr")
target_include_directories (drof PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories (drof PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/share")
target_include_directories (drof PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/streams")
target_include_directories (drof PRIVATE "${PIO_Fortran_INCLUDE_DIR}")
18 changes: 8 additions & 10 deletions dshr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
project(dshr Fortran)

set(SRCFILES dshr_dfield_mod.F90
dshr_fldlist_mod.F90
dshr_mod.F90)
set(MODFILES ${SRCFILES})

foreach(FILE ${SRCFILES})
list(TRANSFORM MODFILES REPLACE ".F90" ".mod")
if(EXISTS "${CASEROOT}/SourceMods/src.cdeps/${FILE}")
list(REMOVE_ITEM SRCFILES ${FILE})
list(APPEND SRCFILES "${CASEROOT}/SourceMods/src.cdeps/${FILE}")
Expand All @@ -18,12 +18,10 @@ if(BLD_STANDALONE)
endif()
add_dependencies(dshr streams)

target_include_directories (dshr PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (dshr PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (dshr PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (dshr PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
target_include_directories (dshr PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (dshr PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/streams)
target_include_directories (dshr PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/share)
target_include_directories (dshr PRIVATE "${PIO_Fortran_INCLUDE_DIR}")

install(TARGETS dshr
LIBRARY DESTINATION lib)
foreach(MOD ${MODFILES})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${MOD}" DESTINATION include)
endforeach()
LIBRARY DESTINATION lib)
17 changes: 10 additions & 7 deletions dwav/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
project(dwav Fortran)
set(SRCFILES wav_comp_nuopc.F90)

foreach(FILE ${SRCFILES})
if(EXISTS "${CASEROOT}/SourceMods/src.dwav/${FILE}")
list(REMOVE_ITEM SRCFILES ${FILE})
Expand All @@ -8,12 +9,14 @@ foreach(FILE ${SRCFILES})
endif()
endforeach()

add_library(dwav ${SRCFILES})
message("DWAV srcfiles are ${SRCFILES}")

add_library(dwav ${SRCFILES})

target_include_directories (dwav PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/dshr")
target_include_directories (dwav PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/share")
target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/streams")
target_include_directories (dwav PUBLIC "${PIO_Fortran_INCLUDE_DIR}")
add_dependencies(dwav dshr streams)
target_include_directories (dwav PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (dwav PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dshr")
target_include_directories (dwav PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories (dwav PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/share")
target_include_directories (dwav PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/streams")
target_include_directories (dwav PRIVATE "${PIO_Fortran_INCLUDE_DIR}")
4 changes: 3 additions & 1 deletion share/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ add_library(cdeps_share ${GenF90_SRCS}
shr_precip_mod.F90
shr_string_mod.F90)

target_include_directories (cdeps_share PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${ESMF_F90COMPILEPATHS} ${PIO_Fortran_INCLUDE_DIRS})
target_include_directories (cdeps_share PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${ESMF_F90COMPILEPATHS} ${PIO_Fortran_INCLUDE_DIRS})

install(TARGETS cdeps_share
LIBRARY DESTINATION lib)

#===== genf90 =====
if (DEFINED GENF90_PATH)
Expand Down
15 changes: 11 additions & 4 deletions streams/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ set(SRCFILES dshr_methods_mod.F90
dshr_strdata_mod.F90
dshr_stream_mod.F90
dshr_tinterp_mod.F90)

set(MODFILES ${SRCFILES})

foreach(FILE ${SRCFILES})
list(TRANSFORM MODFILES REPLACE ".F90" ".mod")
if(EXISTS "${CASEROOT}/SourceMods/src.cdeps/${FILE}")
Expand All @@ -11,16 +13,21 @@ foreach(FILE ${SRCFILES})
message("Using ${FILE} from ${CASEROOT}/SourceMods/src.cdeps")
endif()
endforeach()

message("Stream srcfiles are ${SRCFILES}")

add_library(streams ${SRCFILES})

add_dependencies(streams FoX_dom)
if(BLD_STANDALONE)
add_dependencies(streams cdeps_share)
endif()
target_include_directories (streams PUBLIC ${CMAKE_BINARY_DIR}/fox/include)
target_include_directories (streams PUBLIC ${ESMF_F90COMPILEPATHS})
target_include_directories (streams PUBLIC ${PIO_Fortran_INCLUDE_DIR})
target_include_directories (streams PUBLIC ${CMAKE_BINARY_DIR}/share)

target_include_directories (streams PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/fox/include)
target_include_directories (streams PRIVATE ${ESMF_F90COMPILEPATHS})
target_include_directories (streams PRIVATE ${PIO_Fortran_INCLUDE_DIR})
target_include_directories (streams PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/share)

install(TARGETS streams
LIBRARY DESTINATION lib)
foreach(MOD ${MODFILES})
Expand Down
4 changes: 4 additions & 0 deletions streams/dshr_methods_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,16 @@ subroutine memcheck(string, level, mastertask)

! local variables
integer :: ierr
#ifdef CESMCOUPLED
integer, external :: GPTLprint_memusage
#endif
!-----------------------------------------------------------------------

#ifdef CESMCOUPLED
if ((mastertask .and. memdebug_level > level) .or. memdebug_level > level+1) then
ierr = GPTLprint_memusage(string)
endif
#endif

end subroutine memcheck

Expand Down

0 comments on commit 3b1ec5a

Please sign in to comment.