-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
239 lines (198 loc) · 8.29 KB
/
CMakeLists.txt
File metadata and controls
239 lines (198 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
esma_set_this ()
option(BUILD_GEOS_GTFV3_INTERFACE "Build GEOS-gtFV3 interface" OFF)
set (srcs
sw.f90 jw.f90 testcases_3_4_5_6_stand_alone.f90
GetWeightsC2C.F90
GetWeights.F90
CubeHalo.F90
Cube2LatLon.F90 LatLon2Cube.F90 AppGridCreate.F90 FV_StateMod.F90
AdvCore_GridCompMod.F90
DynCore_GridCompMod.F90 CreateInterpWeights_GridCompMod.F90
StandAlone_DynAdvCore_GridCompMod.F90
CubeToLatLonRegridder.F90
LatLonToCubeRegridder.F90
CubeToCubeRegridder.F90
CubeToLatLon.F90
CubeGridPrototype.F90
GEOS_FV3_Utilities.F90
fv_regrid_c2c.F90
fv_regrid_c2c_bin.F90
fv_regridding_utils.F90
rs_scaleMod.F90
)
if (BUILD_GEOS_GTFV3_INTERFACE)
list (APPEND srcs
geos-gtfv3/geos_gtfv3_interface.f90
geos-gtfv3/geos_gtfv3_interface.c)
endif ()
if (BUILD_GEOS_GTFV3_INTERFACE)
message(STATUS "Building GEOS-gtFV3 interface")
add_definitions(-DRUN_GTFV3)
# The Python library creation requires mpiexec/mpirun to run on a
# compute node. Probably a weird SLURM thing?
find_package(MPI REQUIRED)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
# Set up some variables in case names change
set(GEOS_GTFV3_INTERFACE_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/libgeos_gtfv3_interface_py.so)
set(GEOS_GTFV3_INTERFACE_HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/geos_gtfv3_interface_py.h)
set(GEOS_GTFV3_INTERFACE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/geos-gtfv3/geos_gtfv3_interface.py)
# This command creates the shared object library from Python
add_custom_command(
OUTPUT ${GEOS_GTFV3_INTERFACE_LIBRARY}
# Note below is essentially:
# mpirun -np 1 python file
# but we use the CMake options as much as we can for flexibility
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 1 ${Python3_EXECUTABLE} ${GEOS_GTFV3_INTERFACE_SRCS}
BYPRODUCTS ${GEOS_GTFV3_INTERFACE_HEADER_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
MAIN_DEPENDENCY ${GEOS_GTFV3_INTERFACE_SRCS}
COMMENT "Building gtfv3 interface library with Python"
VERBATIM
)
# This creates a target we can use for dependencies and post build
add_custom_target(generate_python_interface_library DEPENDS ${GEOS_GTFV3_INTERFACE_LIBRARY})
# Because of the weird hacking of INTERFACE libraries below, we cannot
# use the "usual" CMake calls to install() the .so. I think it's because
# INTERFACE libraries don't actually produce any artifacts as far as
# CMake is concerned. So we add a POST_BUILD custom command to "install"
# the library into install/lib
add_custom_command(TARGET generate_python_interface_library
POST_BUILD
# We first need to make a lib dir if it doesn't exist. If not, then
# the next command can copy the script into a *file* called lib because
# of a race condition (if install/lib/ isn't mkdir'd first)
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_PREFIX}/lib
# Now we copy the file (if different...though not sure if this is useful)
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${GEOS_GTFV3_INTERFACE_LIBRARY}" ${CMAKE_INSTALL_PREFIX}/lib
)
# We use INTERFACE libraries to create a sort of "fake" target library we can use
# to make libFVdycoreCubed_GridComp.a depend on. It seems to work!
add_library(geos_gtfv3_interface_py INTERFACE)
# The target_include_directories bits were essentially stolen from the esma_add_library
# code...
target_include_directories(geos_gtfv3_interface_py INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> # stubs
# modules and copied *.h, *.inc
$<BUILD_INTERFACE:${esma_include}/${this}>
$<INSTALL_INTERFACE:include/${this}>
)
target_link_libraries(geos_gtfv3_interface_py INTERFACE ${GEOS_GTFV3_INTERFACE_LIBRARY})
# This makes sure the library is built first
add_dependencies(geos_gtfv3_interface_py generate_python_interface_library)
# This bit is to resolve an issue and Google told me to do this. I'm not
# sure that the LIBRARY DESTINATION bit actually does anything since
# this is using INTERFACE
install(TARGETS geos_gtfv3_interface_py
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
endif ()
set(dependencies MAPL GFTL_SHARED::gftl-shared GMAO_hermes GEOS_Shared esmf OpenMP::OpenMP_Fortran)
if (BUILD_GEOS_GTFV3_INTERFACE)
esma_add_library (${this}
SRCS ${srcs}
SUBCOMPONENTS fvdycore
DEPENDENCIES ${dependencies}
DEPENDENCIES geos_gtfv3_interface_py) # Make the main library depend on the Python library
else ()
esma_add_library (${this}
SRCS ${srcs}
SUBCOMPONENTS fvdycore
DEPENDENCIES ${dependencies})
endif ()
if (FV_PRECISION STREQUAL R4)
target_link_libraries (${this} PUBLIC fms_r4)
target_compile_definitions (${this} PRIVATE SINGLE_FV OVERLOAD_R4)
elseif (FV_PRECISION STREQUAL R4R8) # FV is R4 but FMS is R8
# fvdycore needs r4 .mod interfaces
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${this} PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
# But fvdycore should not *compile* with fms_r8 includes
target_link_libraries(${this} PUBLIC $<LINK_ONLY:fms_r8>)
target_compile_definitions (${this} PRIVATE SINGLE_FV OVERLOAD_R4)
# This tells CMake that we need these targets built before we can build
add_dependencies(${this} fms_r4 fms_r8)
elseif (FV_PRECISION STREQUAL R8)
target_link_libraries (${this} PUBLIC fms_r8)
string(REPLACE " " ";" tmp ${FREAL8})
foreach(flag ${tmp})
target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${flag}>)
endforeach()
endif ()
message(STATUS "Building FV as ${FV_PRECISION}")
#set (CMAKE_Fortran_FLAGS_RELEASE "${GEOS_Fortran_FLAGS_VECT}")
if (CRAY_POINTER)
set_target_properties (${this} PROPERTIES COMPILE_FLAGS ${CRAY_POINTER})
endif()
target_compile_definitions (${this} PRIVATE MAPL_MODE FVREGRID_MAPL_MODE)
ecbuild_add_executable (
TARGET StandAlone_FV3_Dycore.x
SOURCES StandAlone_FV3_Dycore.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET rs_scale.x
SOURCES rs_scale.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET StandAlone_AdvCore.x
SOURCES StandAlone_AdvCore.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET StandAlone_DynAdvCore.x
SOURCES StandAlone_DynAdvCore.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET c2c.x
SOURCES c2c.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET interp_restarts.x
SOURCES interp_restarts.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
ecbuild_add_executable (
TARGET interp_restarts_bin.x
SOURCES interp_restarts_bin.F90
LIBS ${this} OpenMP::OpenMP_Fortran)
# If we are doing R4R8 we also need add_dependencies for both fms_r4 and fms_r8
# for all our executables that link to ${this} because of the way we set up the
# main library above.
if (FV_PRECISION STREQUAL R4R8)
foreach(executable
StandAlone_FV3_Dycore.x
rs_scale.x
StandAlone_AdvCore.x
StandAlone_DynAdvCore.x
c2c.x
interp_restarts.x
interp_restarts_bin.x)
# fvdycore needs r4 .mod interfaces
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${executable} PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
# But fvdycore should not *compile* with fms_r8 includes
target_link_libraries(${executable} $<LINK_ONLY:fms_r8>)
# This tells CMake that we need these targets built before we can build
add_dependencies(${executable} fms_r4 fms_r8)
endforeach()
endif ()
if (BUILD_GEOS_GTFV3_INTERFACE)
ecbuild_add_executable (
TARGET fv3_driver.x
SOURCES
geos-gtfv3/driver/FV_State_Utilities.F90
geos-gtfv3/driver/input/domain_dim.f90
geos-gtfv3/driver/input/grid_bounds.f90
geos-gtfv3/driver/input/input_scalars.f90
geos-gtfv3/driver/input/input_arrays.f90
geos-gtfv3/driver/fv3_driver.F90
LIBS ${this})
if (FV_PRECISION STREQUAL R4R8)
# fvdycore needs r4 .mod interfaces
get_target_property(inc_r4 fms_r4 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(fv3_driver.x PRIVATE $<BUILD_INTERFACE:${inc_r4}>)
# But fvdycore should not *compile* with fms_r8 includes
target_link_libraries(fv3_driver.x PUBLIC $<LINK_ONLY:fms_r8>)
add_dependencies(fv3_driver.x fms_r4 fms_r8)
endif ()
endif ()
add_subdirectory(scripts)