Skip to content

Commit 9b71e56

Browse files
committed
v11: Updates needed for Ninja support
1 parent 1aae45b commit 9b71e56

File tree

1 file changed

+56
-31
lines changed

1 file changed

+56
-31
lines changed

CMakeLists.txt

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -111,42 +111,35 @@ 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
116115
else ()
117116
esma_add_library (${this}
118117
SRCS ${srcs}
119118
SUBCOMPONENTS fvdycore
120-
DEPENDENCIES ${dependencies}
121-
DEPENDENCIES ${GFDL})
119+
DEPENDENCIES ${dependencies})
122120
endif ()
123121

124122
if (FV_PRECISION STREQUAL R4)
125-
set (GFDL fms_r4)
123+
target_link_libraries (${this} PUBLIC fms_r4)
124+
target_compile_definitions (${this} PRIVATE SINGLE_FV OVERLOAD_R4)
126125
elseif (FV_PRECISION STREQUAL R4R8) # FV is R4 but FMS is R8
127-
# We need to add_dependencies for fms_r4 because CMake doesn't know we
128-
# need it for include purposes. In R4R8, we only ever link against
129-
# fms_r4, so it doesn't know we need to build it.
130-
# NOTE NOTE NOTE: This should *not* be included in GEOSgcm v12
131-
# because FMS is pre-built library in that case.
132-
add_dependencies (${this} fms_r4)
133-
get_target_property (extra_incs fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
134-
target_include_directories(${this} PRIVATE
135-
$<BUILD_INTERFACE:${extra_incs}>
136-
)
137-
set (GFDL fms_r8)
138-
elseif (FV_PRECISION STREQUAL R8)
139-
set (GFDL fms_r8)
140-
string(REPLACE " " ";" tmp ${FREAL8})
141-
foreach(flag ${tmp})
142-
target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag}>)
143-
endforeach()
144-
endif ()
126+
# fvdycore needs r4 .mod interfaces
127+
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
128+
target_include_directories(${this} PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
145129

146-
if (FV_PRECISION MATCHES R4)
147-
target_compile_definitions (${this} PRIVATE -DSINGLE_FV -DOVERLOAD_R4)
148-
elseif (FV_PRECISION MATCHES R4R8) # FV is R4 but FMS is R8
149-
target_compile_definitions (${this} PRIVATE -DSINGLE_FV -DOVERLOAD_R4)
130+
# But fvdycore should not *compile* with fms_r8 includes
131+
target_link_libraries(${this} PUBLIC $<LINK_ONLY: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_r4 fms_r8)
137+
elseif (FV_PRECISION STREQUAL R8)
138+
target_link_libraries (${this} PUBLIC fms_r8)
139+
string(REPLACE " " ";" tmp ${FREAL8})
140+
foreach(flag ${tmp})
141+
target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag}>)
142+
endforeach()
150143
endif ()
151144

152145
message(STATUS "Building FV as ${FV_PRECISION}")
@@ -157,11 +150,7 @@ if (CRAY_POINTER)
157150
set_target_properties (${this} PROPERTIES COMPILE_FLAGS ${CRAY_POINTER})
158151
endif()
159152

160-
add_definitions (-DSPMD -DMAPL_MODE -DFVREGRID_MAPL_MODE)
161-
162-
foreach(flag ${tmp})
163-
target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag}>)
164-
endforeach()
153+
target_compile_definitions (${this} PRIVATE MAPL_MODE FVREGRID_MAPL_MODE)
165154

166155
ecbuild_add_executable (
167156
TARGET StandAlone_FV3_Dycore.x
@@ -198,6 +187,32 @@ ecbuild_add_executable (
198187
SOURCES interp_restarts_bin.F90
199188
LIBS ${this} OpenMP::OpenMP_Fortran)
200189

190+
# If we are doing R4R8 we also need add_dependencies for both fms_r4 and fms_r8
191+
# for all our executables that link to ${this} because of the way we set up the
192+
# main library above.
193+
if (FV_PRECISION STREQUAL R4R8)
194+
foreach(executable
195+
StandAlone_FV3_Dycore.x
196+
rs_scale.x
197+
StandAlone_AdvCore.x
198+
StandAlone_DynAdvCore.x
199+
c2c.x
200+
interp_restarts.x
201+
interp_restarts_bin.x)
202+
203+
# fvdycore needs r4 .mod interfaces
204+
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
205+
target_include_directories(${executable} PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
206+
207+
# But fvdycore should not *compile* with fms_r8 includes
208+
target_link_libraries(${executable} $<LINK_ONLY:fms_r8>)
209+
210+
# This tells CMake that we need these targets built before we can build
211+
add_dependencies(${executable} fms_r4 fms_r8)
212+
endforeach()
213+
endif ()
214+
215+
201216
if (BUILD_GEOS_GTFV3_INTERFACE)
202217
ecbuild_add_executable (
203218
TARGET fv3_driver.x
@@ -209,6 +224,16 @@ if (BUILD_GEOS_GTFV3_INTERFACE)
209224
geos-gtfv3/driver/input/input_arrays.f90
210225
geos-gtfv3/driver/fv3_driver.F90
211226
LIBS ${this})
227+
if (FV_PRECISION STREQUAL R4R8)
228+
# fvdycore needs r4 .mod interfaces
229+
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
230+
target_include_directories(fv3_driver.x PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
231+
232+
# But fvdycore should not *compile* with fms_r8 includes
233+
target_link_libraries(fv3_driver.x PUBLIC $<LINK_ONLY:fms_r8>)
234+
235+
add_dependencies(fv3_driver.x fms_r4 fms_r8)
236+
endif ()
212237
endif ()
213238

214239
add_subdirectory(scripts)

0 commit comments

Comments
 (0)