diff --git a/CMakeLists.txt b/CMakeLists.txt index 734fec8de9..2e764ab3c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 $ + $) +target_include_directories(streams PUBLIC $ + $) +target_include_directories(dshr PUBLIC $ + $) +target_include_directories(dshr PUBLIC $ + $) +target_include_directories(dshr PUBLIC $ + $) + +foreach(COMP datm dice dlnd docn drof dwav) + target_include_directories(${COMP} PUBLIC $ + $) + target_include_directories(${COMP} PUBLIC $ + $) + target_include_directories(${COMP} PUBLIC $ + $) + + 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) diff --git a/datm/CMakeLists.txt b/datm/CMakeLists.txt index d003dde8ae..8688b87ccf 100644 --- a/datm/CMakeLists.txt +++ b/datm/CMakeLists.txt @@ -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}) diff --git a/dice/CMakeLists.txt b/dice/CMakeLists.txt index f45a446b35..bd24a640bc 100644 --- a/dice/CMakeLists.txt +++ b/dice/CMakeLists.txt @@ -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}") diff --git a/dlnd/CMakeLists.txt b/dlnd/CMakeLists.txt index ae080d3072..92c20be7d7 100644 --- a/dlnd/CMakeLists.txt +++ b/dlnd/CMakeLists.txt @@ -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}") diff --git a/docn/CMakeLists.txt b/docn/CMakeLists.txt index 33e3ba01ce..71c011478c 100644 --- a/docn/CMakeLists.txt +++ b/docn/CMakeLists.txt @@ -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}) diff --git a/docn/docn_datamode_copyall_mod.F90 b/docn/docn_datamode_copyall_mod.F90 index a0d6be2242..95d4b76420 100644 --- a/docn/docn_datamode_copyall_mod.F90 +++ b/docn/docn_datamode_copyall_mod.F90 @@ -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) diff --git a/drof/CMakeLists.txt b/drof/CMakeLists.txt index 62a92cb83b..50bbb20f19 100644 --- a/drof/CMakeLists.txt +++ b/drof/CMakeLists.txt @@ -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}") diff --git a/dshr/CMakeLists.txt b/dshr/CMakeLists.txt index bf4f025531..05f94b9019 100644 --- a/dshr/CMakeLists.txt +++ b/dshr/CMakeLists.txt @@ -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}") @@ -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) \ No newline at end of file diff --git a/dwav/CMakeLists.txt b/dwav/CMakeLists.txt index c848741c61..97fccbd525 100644 --- a/dwav/CMakeLists.txt +++ b/dwav/CMakeLists.txt @@ -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}) @@ -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}") diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 06bb2c7d3f..cc71a4217b 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -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) diff --git a/streams/CMakeLists.txt b/streams/CMakeLists.txt index 013ee7a407..ee9a924e37 100644 --- a/streams/CMakeLists.txt +++ b/streams/CMakeLists.txt @@ -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}") @@ -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}) diff --git a/streams/dshr_methods_mod.F90 b/streams/dshr_methods_mod.F90 index bb079da4e9..3f194cbd33 100644 --- a/streams/dshr_methods_mod.F90 +++ b/streams/dshr_methods_mod.F90 @@ -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