Skip to content

Commit

Permalink
Get the PF UNIT tests working using the full ESMF library which also …
Browse files Browse the repository at this point in the history
…requires PIO and NetCDF as a result
  • Loading branch information
ekluzek committed Oct 30, 2024
1 parent 9c05576 commit 721ce0e
Show file tree
Hide file tree
Showing 29 changed files with 56 additions and 55 deletions.
55 changes: 28 additions & 27 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ cmake_minimum_required(VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY})
include(CIME_initial_setup)

project(clm45_tests Fortran C)
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../tools/mksurfdata_esmf/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../share/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../component/cmeps/cmake")

project(clm_tests Fortran C)

include(CIME_utils)

set(CLM_ROOT "..")

# This definition is needed to avoid having ESMF depend on mpi
add_definitions(-DHIDE_MPI)
#find_package(ESMF 8.2.0 REQUIRED )
find_package(NetCDF 4.7.4 REQUIRED Fortran)

# Add source directories from other share code (csm_share, etc.). This should be
# done first, so that in case of name collisions, the CLM versions take
# precedence (when there are two files with the same name, the one added later
# wins).
add_subdirectory(${CLM_ROOT}/share/src csm_share)
add_subdirectory(${CLM_ROOT}/share/unit_test_stubs/util csm_share_stubs)
add_subdirectory(${CLM_ROOT}/share/src/esmf_wrf_timemgr esmf_wrf_timemgr)

# Add files needed from CMEPS
list ( APPEND drv_sources_needed
Expand Down Expand Up @@ -53,43 +56,41 @@ foreach (sourcefile ${share_sources})
endif()
endforeach()

# Remove shr_cal_mod from share_sources.
#
# shr_cal_mod depends on ESMF (or the lightweight esmf wrf timemgr, at
# least). Since CTSM doesn't currently use shr_cal_mod, we're avoiding
# the extra overhead of including esmf_wrf_timemgr sources in this
# build.
#
# TODO: like above, this should be moved into a general-purpose function
# in Sourcelist_utils. Then this block of code could be replaced with a
# single call, like: remove_source_file(${share_sources}
# "shr_cal_mod.F90")
foreach (sourcefile ${share_sources})
string(REGEX MATCH "shr_cal_mod.F90" match_found ${sourcefile})
if(match_found)
list(REMOVE_ITEM share_sources ${sourcefile})
endif()
endforeach()
if (DEFINED PIO)
set(PIO_PATH ${PIO})
else()
set(PIO_PATH $ENV{PIO})
endif()

# Build libraries containing stuff needed for the unit tests.
# Eventually, these add_library calls should probably be distributed into the correct location, rather than being in this top-level CMakeLists.txt file.
add_library(csm_share ${share_sources} ${drv_sources_needed})
declare_generated_dependencies(csm_share "${share_genf90_sources}")
add_library(esmf_wrf_timemgr ${esmf_wrf_timemgr_sources})
add_library(clm ${clm_sources})
declare_generated_dependencies(clm "${clm_genf90_sources}")
add_dependencies(esmf_wrf_timemgr csm_share)
add_dependencies(clm csm_share esmf_wrf_timemgr)
add_dependencies(clm csm_share esmf)

# We need to look for header files here, in order to pick up shr_assert.h
include_directories(${CLM_ROOT}/share/include)

# And we need to look for header files here, for some include files needed by
# the esmf_wrf_timemgr code
include_directories(${CLM_ROOT}/share/src/esmf_wrf_timemgr)

# PIO2
add_compile_definitions(PIO2)

add_library(pioc STATIC IMPORTED)
add_library(piof STATIC IMPORTED)
set_property(TARGET pioc PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpioc.so)
set_property(TARGET piof PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpiof.so)

# Tell cmake to look for libraries & mod files here, because this is where we built libraries
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories (${ESMF_F90COMPILEPATHS})
include_directories ($ENV{PIO}/include)
include_directories (${NETCDF}/include)

message( "CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}" )
link_directories(${CMAKE_CURRENT_BINARY_DIR})
link_libraries( pioc piof netcdf )

# Add the test directories
# Note: it's possible that these could be added by each source directory that
Expand Down
2 changes: 1 addition & 1 deletion src/biogeochem/test/CNPhenology_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(CNPhenology
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeochem/test/CNVegComputeSeed_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(CNVegComputeSeed
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeochem/test/DustEmis_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set (pfunit_sources

add_pfunit_ctest(DustEmis
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeochem/test/Latbaset_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(CropTypeLatbaset
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/Balance_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(balance
TEST_SOURCES "test_Balance.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/Daylength_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set (pfunit_sources

add_pfunit_ctest(Daylength
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/HillslopeHydrology_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(HillslopeHydrologyUtils
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/Irrigation_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(irrigation
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/Photosynthesis_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(Photosynthesis
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/SnowHydrology_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set (pfunit_sources

add_pfunit_ctest(SnowHydrology
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/TotalWaterAndHeat_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(total_water_and_heat
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(water_tracer_container
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/WaterTracerUtils_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set (pfunit_sources

add_pfunit_ctest(water_tracer_utils
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/WaterType_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(water_type
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/biogeophys/test/Wateratm2lnd_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(water_atm2lnd
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/dyn_subgrid/test/dynConsBiogeophys_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set(pfunit_sources

add_pfunit_ctest(dynConsBiogeophys
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/dyn_subgrid/test/dynInitColumns_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(dynInitColumns
TEST_SOURCES "test_init_columns.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/dyn_subgrid/test/dynTimeInfo_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(dynTimeInfo
TEST_SOURCES "test_dynTimeInfo.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/dyn_subgrid/test/dynVar_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ set (extra_sources
add_pfunit_ctest(dynVar
TEST_SOURCES "${pfunit_sources}"
OTHER_SOURCES "${extra_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/main/test/accumul_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set(pfunit_sources

add_pfunit_ctest(accumul
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/main/test/atm2lnd_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set(pfunit_sources

add_pfunit_ctest(atm2lnd
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/main/test/initVertical_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(initVertical
TEST_SOURCES "test_initVertical.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/self_tests/test/assertions_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(assertions
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/soilbiogeochem/test/tillage_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(tillage
TEST_SOURCES "test_tillage.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/utils/test/annual_flux_dribbler_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(annual_flux_dribbler
TEST_SOURCES "test_annual_flux_dribbler.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/utils/test/array_utils_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set (pfunit_sources

add_pfunit_ctest(array_utils
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/utils/test/clm_time_manager_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_pfunit_ctest(clm_time_manager
TEST_SOURCES "test_clm_time_manager.pf"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)
2 changes: 1 addition & 1 deletion src/utils/test/numerics_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set (pfunit_sources

add_pfunit_ctest(numerics
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES clm csm_share esmf_wrf_timemgr)
LINK_LIBRARIES clm csm_share esmf)

0 comments on commit 721ce0e

Please sign in to comment.