forked from ufs-community/ufs-weather-model
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
457 lines (388 loc) · 15.4 KB
/
CMakeLists.txt
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
cmake_minimum_required(VERSION 3.19)
project(ufs
VERSION 1.0
LANGUAGES C CXX Fortran)
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0.0)
message(FATAL_ERROR "GNU Compiler >= 9 is required")
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/Modules)
###############################################################################
### App and Component Options
###############################################################################
# Valid applications and choices
list(APPEND VALID_APPS ATM ATMAERO ATMAQ ATMW ATMWM ATML ATMF LND LND-LM4 S2S S2SA S2SW S2SWA S2SWAL ATM_DS2S ATM_DS2S-PCICE HAFS HAFSW HAFS-MOM6 HAFS-MOM6W HAFS-ALL NG-GODAS CSTLA CSTLPA CSTLAW CSTLPAW CSTLF CSTLFW CSTLR CSTLRW CSTLRC CSTLRCW CSTLS CSTLPS CSTLSW CSTLPSW CSTLP CSTLW CSTL-ALL)
set(APP NONE CACHE BOOL "Application Name")
if(NOT (APP IN_LIST VALID_APPS))
message(FATAL_ERROR "${APP} is not a valid application.\nValid Applications are: ${VALID_APPS}")
endif()
set(FMS OFF CACHE BOOL "Enable FMS")
set(FV3 OFF CACHE BOOL "Enable FV3")
set(AQM OFF CACHE BOOL "Enable AQM")
set(UFS_GOCART OFF CACHE BOOL "Enable GOCART")
set(MOM6 OFF CACHE BOOL "Enable MOM6")
set(HYCOM OFF CACHE BOOL "Enable HYCOM")
set(CICE6 OFF CACHE BOOL "Enable CICE6")
set(LM4 OFF CACHE BOOL "Enable LM4")
set(WW3 OFF CACHE BOOL "Enable WW3")
set(STOCH_PHYS OFF CACHE BOOL "Enable Stochastic Physics")
set(CMEPS OFF CACHE BOOL "Enable CMEPS")
set(CDEPS OFF CACHE BOOL "Enable CDEPS")
set(NOAHMP OFF CACHE BOOL "Enable NOAHMP")
set(FIRE_BEHAVIOR OFF CACHE BOOL "Enable Fire Behavior")
set(ADCIRC OFF CACHE BOOL "Enable ADCIRC")
set(FVCOM OFF CACHE BOOL "Enable FVCOM")
set(SCHISM OFF CACHE BOOL "Enable SCHISM")
set(ROMS OFF CACHE BOOL "Enable ROMS")
set(PAHM OFF CACHE BOOL "Enable PAHM")
# Configure selected application specific components
message("")
include(cmake/configure_apps.cmake)
message("")
message("FMS .............. ${FMS}")
message("FV3 .............. ${FV3}")
message("AQM .............. ${AQM}")
message("GOCART ........... ${UFS_GOCART}")
message("MOM6 ............. ${MOM6}")
message("HYCOM ............ ${HYCOM}")
message("CICE6 ............ ${CICE6}")
message("LM4 .............. ${LM4}")
message("WW3 .............. ${WW3}")
message("STOCH_PHYS ....... ${STOCH_PHYS}")
message("CDEPS ............ ${CDEPS}")
message("CMEPS ............ ${CMEPS}")
message("NOAHMP ........... ${NOAHMP}")
message("FIRE_BEHAVIOR .... ${FIRE_BEHAVIOR}")
message("ADCIRC ........... ${ADCIRC}")
message("FVCOM ............ ${FVCOM}")
message("SCHISM ........... ${SCHISM}")
message("ROMS ............. ${ROMS}")
message("PAHM ............. ${PAHM}")
###############################################################################
### Build Options
###############################################################################
set(32BIT OFF CACHE BOOL "Enable 32BIT (single precision arithmetic in dycore and fast physics)")
set(CCPP_32BIT OFF CACHE BOOL "Enable CCPP_32BIT (single precision arithmetic in slow physics)")
set(AVX2 ON CACHE BOOL "Enable AVX2 instruction set")
set(AVX OFF CACHE BOOL "Enable AVX-I instruction set")
set(SIMDMULTIARCH OFF CACHE BOOL "Enable multi-target SIMD instruction sets")
set(DEBUG OFF CACHE BOOL "Enable DEBUG mode")
set(DISABLE_FMA OFF CACHE BOOL "Disable Fused Multiply-Add instructions (workaround needed for AMD EPYC)" FORCE)
set(INLINE_POST ON CACHE BOOL "Enable inline post")
set(MULTI_GASES OFF CACHE BOOL "Enable MULTI_GASES")
set(MOVING_NEST OFF CACHE BOOL "Enable moving nest code")
set(REGIONAL_MOM6 OFF CACHE BOOL "Enable Regional MOM6")
set(OPENMP ON CACHE BOOL "Enable OpenMP threading")
set(PARALLEL_NETCDF OFF CACHE BOOL "Enable parallel NetCDF")
set(JEDI_DRIVER OFF CACHE BOOL "Enable JEDI as top level driver")
set(CMEPS_AOFLUX OFF CACHE BOOL "Enable atmosphere-ocean flux calculation in mediator")
set(PDLIB OFF CACHE BOOL "Enable Domain Decomposition in WW3 via PDLIB")
set(CDEPS_INLINE OFF CACHE BOOL "Enable CDEPS inline capability")
set(HYDRO OFF CACHE BOOL "Enable hydrostatic set")
set(CMAKE_Platform $ENV{CMAKE_Platform})
if(CMAKE_Platform)
message("")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/configure_${CMAKE_Platform}.cmake)
message("Setting configuration for ${CMAKE_Platform}")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/configure_${CMAKE_Platform}.cmake)
else()
message("Platform '${CMAKE_Platform}' configuration file does not exist")
endif()
endif()
option(BUILD_WITH_IFI "Build NCEPpost with In-Flight Icing (IFI) library if present" OFF)
option(REQUIRE_IFI "Abort if libIFI is not found ; enables BUILD_WITH_IFI=ON" OFF)
option(INTERNAL_IFI "Compile with IFI inside the executable, instead of a library" OFF)
if(INTERNAL_IFI)
message("Building with libIFI inside executable. Do not distribute executable outside of WCOSS2.")
set(BUILD_WITH_IFI OFF)
set(REQUIRE_IFI OFF)
endif()
if(REQUIRE_IFI)
set(BUILD_WITH_IFI ON)
endif()
if(BUILD_WITH_IFI)
if(REQUIRE_IFI)
find_package(IFI CONFIG REQUIRED)
else()
find_package(IFI CONFIG)
endif()
endif()
message("")
message("32BIT ............ ${32BIT}")
message("CCPP_32BIT ....... ${CCPP_32BIT}")
message("AVX2 ............. ${AVX2}")
message("SIMDMULTIARCH .... ${SIMDMULTIARCH}")
message("DEBUG ............ ${DEBUG}")
message("INLINE_POST ...... ${INLINE_POST}")
message("MULTI_GASES ...... ${MULTI_GASES}")
message("MOVING_NEST ...... ${MOVING_NEST}")
message("REGIONAL_MOM6..... ${REGIONAL_MOM6}")
message("OPENMP ........... ${OPENMP}")
message("PARALLEL_NETCDF .. ${PARALLEL_NETCDF}")
message("JEDI_DRIVER ...... ${JEDI_DRIVER}")
message("CMEPS_AOFLUX ..... ${CMEPS_AOFLUX}")
message("CDEPS_INLINE ..... ${CDEPS_INLINE}")
message("HYDRO ........... ${HYDRO}")
message("")
###############################################################################
### Set CMAKE_BUILD_TYPE for DEBUG mode
###############################################################################
if(DEBUG)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Set type of build to Debug." FORCE)
else()
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Set type of build to Release." FORCE)
endif()
include(cmake/${CMAKE_Fortran_COMPILER_ID}.cmake)
###############################################################################
### Find Dependencies
###############################################################################
find_package(MPI REQUIRED)
if(OPENMP)
find_package(OpenMP REQUIRED)
endif()
find_package(NetCDF 4.7.4 REQUIRED C Fortran)
find_package(ESMF 8.3.0 MODULE REQUIRED)
if(FMS)
find_package(FMS 2022.04 REQUIRED COMPONENTS R4 R8)
if(APP MATCHES "^(HAFSW)$")
add_library(fms ALIAS FMS::fms_r4)
elseif (APP MATCHES "^(S2S|S2SA|S2SW|S2SWA|S2SWAL|ATM_DS2S|ATM_DS2S-PCICE|NG-GODAS|HAFS-MOM6|HAFS-MOM6W|CSTLA|CSTLPA|CSTLAW|CSTLPAW|CSTLF|CSTLFW|CSTLR|CSTLRW|CSTLRC|CSTLRCW|CSTLS|CSTLPS|CSTLSW|CSTLPSW|CSTLP|CSTLW|CSTL-ALL)$")
add_library(fms ALIAS FMS::fms_r8)
endif()
if(APP MATCHES "^(ATM|ATMAERO|ATMAQ|ATMWM|ATMW|ATML|ATMF|ATML-LM4|LND-LM4|HAFS|HAFS-ALL)$")
if(32BIT)
add_library(fms ALIAS FMS::fms_r4)
else()
add_library(fms ALIAS FMS::fms_r8)
endif()
endif()
endif()
if(CMEPS)
find_package(PIO 2.5.3 REQUIRED COMPONENTS C Fortran)
endif()
find_package(bacio 2.4.0 REQUIRED)
find_package(sp 2.3.3 REQUIRED)
find_package(w3emc 2.9.2 REQUIRED)
# Configure Python
find_package(Python 3.6 REQUIRED COMPONENTS Interpreter)
message("Found Python: ${Python_EXECUTABLE}")
###############################################################################
### stochastic_physics
###############################################################################
if(STOCH_PHYS)
add_subdirectory(stochastic_physics)
endif()
###############################################################################
### Atmosphere Components [FV3, MPAS?]
###############################################################################
if(FV3)
add_subdirectory(FV3)
endif()
if(PAHM)
add_subdirectory(PAHM-interface)
endif()
###############################################################################
### AQM
###############################################################################
if(AQM)
add_subdirectory(AQM)
endif()
###############################################################################
### GOCART
###############################################################################
if(UFS_GOCART)
add_subdirectory(GOCART)
endif()
###############################################################################
### Wave components [WW3]
###############################################################################
if(WW3)
if(APP MATCHES "^(ATMWM)$" )
set(SWITCH "multi_esmf" CACHE STRING "ESMF cap")
set(UFS_CAP "MULTI_ESMF" CACHE STRING "Build with MULTI_ESMF cap")
list(APPEND _ufs_defs_private FRONT_WW3=WMESMFMD)
else()
if(PDLIB)
set(SWITCH "meshcap_pdlib" CACHE STRING "NUOPC mesh cap")
else()
set(SWITCH "meshcap" CACHE STRING "NUOPC mesh cap")
endif()
set(UFS_CAP "NUOPC_MESH" CACHE STRING "Build with NUOPC_MESH cap")
list(APPEND _ufs_defs_private FRONT_WW3=wav_comp_nuopc)
endif()
add_subdirectory(WW3)
endif()
###############################################################################
### Marine Components [MOM6, HYCOM, CICE6, ADCIRC, SCHISM, ROMS]
###############################################################################
if(MOM6)
add_subdirectory(MOM6-interface)
endif()
if(HYCOM)
add_subdirectory(HYCOM-interface)
endif()
if(CICE6)
add_subdirectory(CICE-interface)
endif()
if(ADCIRC)
add_subdirectory(ADCIRC-interface)
endif()
if(FVCOM)
add_subdirectory(FVCOM-interface)
endif()
if(SCHISM)
add_subdirectory(SCHISM-interface)
endif()
if(ROMS)
add_subdirectory(ROMS-interface)
endif()
###############################################################################
### Mediator Components [CMEPS]
###############################################################################
if(CMEPS)
add_subdirectory(CMEPS-interface)
endif()
###############################################################################
### Data Components [CDEPS]
###############################################################################
if(CDEPS)
add_subdirectory(CDEPS-interface)
endif()
###############################################################################
### Land Components [NOAHMP and LM4]
###############################################################################
if (LM4)
add_subdirectory(LM4-driver)
endif()
if(NOAHMP)
add_subdirectory(NOAHMP-interface)
endif()
###############################################################################
### Fire Components [FIRE_BEHAVIOR]
###############################################################################
if(FIRE_BEHAVIOR)
set(NUOPC "ON" CACHE STRING "Build fire_behavior with NUOPC cap" FORCE)
add_subdirectory(fire_behavior)
endif()
###############################################################################
### UFS Library
###############################################################################
add_library(ufs driver/UFSDriver.F90)
set_target_properties(ufs PROPERTIES Fortran_MODULE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(ufs INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>
$<INSTALL_INTERFACE:mod>)
if(JEDI_DRIVER)
list(APPEND _ufs_defs_private JEDI_DRIVER=ON)
endif()
if(AQM)
add_dependencies(ufs aqm)
list(APPEND _ufs_defs_private FRONT_AQM=aqm)
list(APPEND _ufs_libs_public aqm)
endif()
if(UFS_GOCART)
add_dependencies(ufs UFS_Aerosols)
list(APPEND _ufs_defs_private FRONT_GOCART=Aerosol_Cap)
list(APPEND _ufs_libs_public UFS_Aerosols)
endif()
if(WW3)
target_link_libraries(ufs PUBLIC WW3::WW3)
endif()
list(APPEND _ufs_libs_public esmf)
if(STOCH_PHYS)
list(APPEND _ufs_libs_public stochastic_physics)
endif()
if(FV3)
add_dependencies(ufs fv3atm)
list(APPEND _ufs_defs_private FRONT_FV3=fv3atm_cap_mod)
list(APPEND _ufs_libs_public fv3atm)
endif()
if(MOM6)
add_dependencies(ufs mom6)
list(APPEND _ufs_defs_private FRONT_MOM6=mom_cap_mod)
list(APPEND _ufs_libs_public mom6)
endif()
if(HYCOM)
list(APPEND _ufs_defs_private FRONT_HYCOM=HYCOM_Mod)
add_dependencies(ufs hycom)
target_link_libraries(ufs PUBLIC hycom)
endif()
if(CICE6)
add_dependencies(ufs cice)
list(APPEND _ufs_defs_private FRONT_CICE6=ice_comp_nuopc)
list(APPEND _ufs_libs_public cice)
endif()
if (LM4)
add_dependencies(ufs lm4)
list(APPEND _ufs_defs_private FRONT_LM4=lm4_cap_mod)
list(APPEND _ufs_libs_public lm4)
endif()
if(CMEPS)
add_dependencies(ufs cmeps)
list(APPEND _ufs_defs_private CMEPS FRONT_CMEPS=MED)
list(APPEND _ufs_libs_public cmeps)
endif()
if(CDEPS)
add_dependencies(ufs cdeps::cdeps)
list(APPEND _ufs_defs_private FRONT_CDEPS_DATM=cdeps_datm_comp)
list(APPEND _ufs_defs_private FRONT_CDEPS_DOCN=cdeps_docn_comp)
list(APPEND _ufs_defs_private FRONT_CDEPS_DICE=cdeps_dice_comp)
target_link_libraries(ufs PUBLIC cdeps::cdeps)
endif()
if(NOAHMP)
add_dependencies(ufs noahmp)
list(APPEND _ufs_defs_private FRONT_NOAHMP=lnd_comp_nuopc)
list(APPEND _ufs_libs_public noahmp)
endif()
if(FIRE_BEHAVIOR)
add_dependencies(ufs fire_behavior_nuopc)
list(APPEND _ufs_defs_private FRONT_FIRE_BEHAVIOR=fire_behavior_nuopc)
list(APPEND _ufs_libs_public fire_behavior_nuopc)
endif()
if(ADCIRC)
add_dependencies(ufs adcirc)
list(APPEND _ufs_defs_private FRONT_ADCIRC=adc_cap)
list(APPEND _ufs_libs_public adcirc)
endif()
if(FVCOM)
add_dependencies(ufs fvcom)
list(APPEND _ufs_defs_private FRONT_FVCOM=fvcom_cap)
list(APPEND _ufs_libs_public fvcom)
endif()
if(SCHISM)
add_dependencies(ufs schism)
list(APPEND _ufs_defs_private FRONT_SCHISM=schism_nuopc_cap)
list(APPEND _ufs_libs_public schism)
endif()
if(ROMS)
add_dependencies(ufs ROMS_static)
list(APPEND _ufs_defs_private FRONT_ROMS=cmeps_roms_mod)
list(APPEND _ufs_libs_public ROMS_static)
endif()
if(PAHM)
add_dependencies(ufs pahm)
list(APPEND _ufs_defs_private FRONT_PAHM=pahm_cap)
list(APPEND _ufs_libs_public pahm)
endif()
target_compile_definitions(ufs PRIVATE "${_ufs_defs_private}")
target_link_libraries(ufs PUBLIC "${_ufs_libs_public}")
###############################################################################
### UFS executable
###############################################################################
add_executable(ufs_model driver/UFS.F90)
add_dependencies(ufs_model ufs)
target_link_libraries(ufs_model ufs esmf w3emc::w3emc_d)
set_target_properties(ufs_model PROPERTIES LINKER_LANGUAGE Fortran)
###############################################################################
### Install
###############################################################################
install(TARGETS ufs
EXPORT ufs-config
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(EXPORT ufs-config
DESTINATION lib/cmake)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod DESTINATION ${CMAKE_INSTALL_PREFIX})
###############################################################################
### Done
###############################################################################