@@ -111,36 +111,37 @@ if (BUILD_GEOS_GTFV3_INTERFACE)
111111 SRCS ${srcs}
112112 SUBCOMPONENTS fvdycore
113113 DEPENDENCIES ${dependencies}
114- DEPENDENCIES ${GFDL}
115114 DEPENDENCIES geos_gtfv3_interface_py) # Make the main library depend on the Python library
116115else ()
117116 esma_add_library (${this}
118117 SRCS ${srcs}
119118 SUBCOMPONENTS fvdycore
120- DEPENDENCIES ${dependencies}
121- DEPENDENCIES ${GFDL} )
119+ DEPENDENCIES ${dependencies} )
122120endif ()
123121
124122if (FV_PRECISION STREQUAL R4)
125- set (GFDL FMS::fms_r4)
123+ target_link_libraries (${this} PUBLIC FMS::fms_r4)
124+ target_compile_definitions (${this} PRIVATE SINGLE_FV OVERLOAD_R4)
126125elseif (FV_PRECISION STREQUAL R4R8) # FV is R4 but FMS is R8
127- get_target_property (extra_incs FMS::fms_r4 INTERFACE_INCLUDE_DIRECTORIES )
128- target_include_directories (${this} PRIVATE $<BUILD_INTERFACE:${extra_incs} >)
129- set (GFDL FMS::fms_r8)
126+ # fvdycore needs r4 .mod interfaces
127+ get_target_property (inc_r4 FMS::fms_r4 INTERFACE_INCLUDE_DIRECTORIES )
128+ target_include_directories (${this} PRIVATE $<BUILD_INTERFACE:${inc_r4} >)
129+
130+ # But fvdycore should not *compile* with fms_r8 includes
131+ target_link_libraries (${this} PUBLIC $<LINK_ONLY:FMS::fms_r8>)
132+
133+ target_compile_definitions (${this} PRIVATE SINGLE_FV OVERLOAD_R4)
134+
135+ # This tells CMake that we need these targets built before we can build
136+ add_dependencies (${this} FMS::fms_r4 FMS::fms_r8)
130137elseif (FV_PRECISION STREQUAL R8)
131- set (GFDL FMS::fms_r8)
138+ target_link_libraries ( ${this} PUBLIC FMS::fms_r8)
132139 string (REPLACE " " ";" tmp ${FREAL8} )
133140 foreach (flag ${tmp} )
134141 target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag} >)
135142 endforeach ()
136143endif ()
137144
138- if (FV_PRECISION MATCHES R4)
139- target_compile_definitions (${this} PRIVATE -DSINGLE_FV -DOVERLOAD_R4)
140- elseif (FV_PRECISION MATCHES R4R8) # FV is R4 but FMS is R8
141- target_compile_definitions (${this} PRIVATE -DSINGLE_FV -DOVERLOAD_R4)
142- endif ()
143-
144145message (STATUS "Building FV as ${FV_PRECISION} " )
145146
146147#set (CMAKE_Fortran_FLAGS_RELEASE "${GEOS_Fortran_FLAGS_VECT}")
@@ -149,11 +150,7 @@ if (CRAY_POINTER)
149150 set_target_properties (${this} PROPERTIES COMPILE_FLAGS ${CRAY_POINTER} )
150151endif ()
151152
152- add_definitions (-DSPMD -DMAPL_MODE -DFVREGRID_MAPL_MODE)
153-
154- foreach (flag ${tmp} )
155- target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag} >)
156- endforeach ()
153+ target_compile_definitions (${this} PRIVATE MAPL_MODE FVREGRID_MAPL_MODE)
157154
158155ecbuild_add_executable (
159156 TARGET StandAlone_FV3_Dycore.x
@@ -196,6 +193,32 @@ ecbuild_add_executable (
196193 SOURCES interp_restarts_bin.F90
197194 LIBS ${this} OpenMP::OpenMP_Fortran)
198195
196+ # If we are doing R4R8 we also need add_dependencies for both fms_r4 and fms_r8
197+ # for all our executables that link to ${this} because of the way we set up the
198+ # main library above.
199+ if (FV_PRECISION STREQUAL R4R8)
200+ foreach (executable
201+ StandAlone_FV3_Dycore.x
202+ rs_scale.x
203+ StandAlone_AdvCore.x
204+ StandAlone_DynAdvCore.x
205+ c2c.x
206+ interp_restarts.x
207+ interp_restarts_bin.x)
208+
209+ # fvdycore needs r4 .mod interfaces
210+ get_target_property (inc_r4 FMS::fms_r4 INTERFACE_INCLUDE_DIRECTORIES )
211+ target_include_directories (${executable} PRIVATE $<BUILD_INTERFACE:${inc_r4} >)
212+
213+ # But fvdycore should not *compile* with FMS::fms_r8 includes
214+ target_link_libraries (${executable} $<LINK_ONLY:FMS::fms_r8>)
215+
216+ # This tells CMake that we need these targets built before we can build
217+ add_dependencies (${executable} FMS::fms_r4 FMS::fms_r8)
218+ endforeach ()
219+ endif ()
220+
221+
199222if (BUILD_GEOS_GTFV3_INTERFACE)
200223 ecbuild_add_executable (
201224 TARGET fv3_driver.x
@@ -207,6 +230,16 @@ if (BUILD_GEOS_GTFV3_INTERFACE)
207230 geos-gtfv3/driver/input /input_arrays.f90
208231 geos-gtfv3/driver/fv3_driver.F90
209232 LIBS ${this} )
233+ if (FV_PRECISION STREQUAL R4R8)
234+ # fvdycore needs r4 .mod interfaces
235+ get_target_property (inc_r4 FMS::fms_r4 INTERFACE_INCLUDE_DIRECTORIES )
236+ target_include_directories (fv3_driver.x PRIVATE $<BUILD_INTERFACE:${inc_r4} >)
237+
238+ # But fvdycore should not *compile* with FMS::fms_r8 includes
239+ target_link_libraries (fv3_driver.x PUBLIC $<LINK_ONLY:FMS::fms_r8>)
240+
241+ add_dependencies (fv3_driver.x FMS::fms_r4 FMS::fms_r8)
242+ endif ()
210243endif ()
211244
212245add_subdirectory (scripts)
0 commit comments