Skip to content

Commit 695f455

Browse files
authored
CMake WRFPLUS (#2089)
TYPE: enhancement KEYWORDS: cmake, wrfplus SOURCE: internal DESCRIPTION OF CHANGES: Problem: The current CMake build does not build the WRF PLUS core configuration Solution: Add the necessary source files to compile WRF PLUS. WRF binary will still be created, but a symlink to `wrfplus.exe` will also be created for backward compatibility
1 parent b6542b0 commit 695f455

File tree

4 files changed

+184
-44
lines changed

4 files changed

+184
-44
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,10 @@ if ( ${ENABLE_HYDRO} )
927927
add_subdirectory( hydro )
928928
endif()
929929

930+
if ( ${WRF_CORE} STREQUAL "PLUS" )
931+
add_subdirectory( wrftladj )
932+
endif()
933+
930934
add_subdirectory( dyn_em )
931935

932936

cmake/wrf_case_setup.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,51 @@ macro( wrf_setup_targets )
4747

4848
endmacro()
4949

50+
# WRF Macro for adding target symlinks/copies to be run after internal install() code
51+
# this allows for alternate naming
52+
macro( wrf_setup_target_new_name )
53+
54+
set( options USE_SYMLINKS )
55+
set( oneValueArgs TARGET DEST_PATH NEW_NAME )
56+
set( multiValueArgs )
57+
58+
cmake_parse_arguments(
59+
WRF_SETUP
60+
"${options}" "${oneValueArgs}" "${multiValueArgs}"
61+
${ARGN}
62+
)
63+
set( WRF_SETUP_CMD copy_if_different )
64+
if ( ${WRF_SETUP_USE_SYMLINKS} )
65+
set( WRF_SETUP_CMD create_symlink )
66+
endif()
67+
68+
# Generate install code for each target
69+
# https://stackoverflow.com/a/56528615
70+
#!TODO Do we *need* the rm for symlinks beforehand?
71+
# get_filename_component( WRF_SETUP_FILE_ONLY $<TARGET_FILE:${WRF_SETUP_TARGET}> NAME
72+
73+
# If we ever wanted to link or copy things other than binaries we could change this
74+
set( WRF_SETUP_INSTALL_LOCATION ${CMAKE_INSTALL_PREFIX}/bin )
75+
76+
install(
77+
CODE "
78+
message( STATUS \"Setting up $<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> via ${WRF_SETUP_CMD} as ${WRF_SETUP_NEW_NAME}\" )
79+
execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_INSTALL_LOCATION}/$<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> ${WRF_SETUP_DEST_PATH}/${WRF_SETUP_NEW_NAME} )
80+
"
81+
COMPONENT setup
82+
)
83+
84+
# Add .exe link as well
85+
install(
86+
CODE "
87+
message( STATUS \"Creating symlink for ${WRF_SETUP_NEW_NAME}.exe\" )
88+
execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${WRF_SETUP_DEST_PATH}/${WRF_SETUP_NEW_NAME} ${WRF_SETUP_DEST_PATH}/${WRF_SETUP_NEW_NAME}.exe )
89+
"
90+
COMPONENT setup
91+
)
92+
93+
endmacro()
94+
5095
# WRF Macro for adding file symlinks/copies to be run after internal install() code
5196
macro( wrf_setup_files )
5297

main/CMakeLists.txt

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@ add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
55
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
66

77
# First make true executables
8-
if ( ${WRF_CORE} STREQUAL "PLUS" )
9-
add_executable(
10-
wrfplus
11-
wrf.F
12-
module_wrf_top.F
13-
)
14-
list( APPEND FOLDER_COMPILE_TARGETS wrfplus )
15-
else()
16-
# I believe this is always made if not WRF PLUS or ESMF
8+
if ( ${WRF_CORE} STREQUAL "PLUS" OR ${WRF_CASE} STREQUAL "EM_REAL" )
9+
1710
add_executable(
1811
wrf
1912
wrf.F
@@ -31,46 +24,48 @@ else()
3124
# list( APPEND FOLDER_COMPILE_TARGETS em_wrf_SST_ESMF )
3225
endif()
3326

34-
# Use case info from higher CMakeLists.txt
35-
set( MODULE_FILE ${PROJECT_SOURCE_DIR}/dyn_em/module_initialize_${WRF_CASE_MODULE}.F )
27+
if ( ${WRF_CORE} STREQUAL "ARW" )
3628

37-
if ( ${WRF_CASE} STREQUAL "EM_REAL" )
38-
add_executable(
39-
ndown
40-
ndown_em.F
41-
${MODULE_FILE}
42-
)
43-
add_executable(
44-
tc
45-
tc_em.F
46-
${MODULE_FILE}
29+
# Use case info from higher CMakeLists.txt
30+
set( MODULE_FILE ${PROJECT_SOURCE_DIR}/dyn_em/module_initialize_${WRF_CASE_MODULE}.F )
31+
32+
if ( ${WRF_CASE} STREQUAL "EM_REAL" )
33+
add_executable(
34+
ndown
35+
ndown_em.F
36+
${MODULE_FILE}
37+
)
38+
add_executable(
39+
tc
40+
tc_em.F
41+
${MODULE_FILE}
42+
)
43+
add_executable(
44+
real
45+
real_em.F
46+
${MODULE_FILE}
4747
)
48-
add_executable(
49-
real
50-
real_em.F
51-
${MODULE_FILE}
52-
)
53-
list( APPEND FOLDER_COMPILE_TARGETS ndown tc real )
48+
list( APPEND FOLDER_COMPILE_TARGETS ndown tc real )
5449

55-
elseif( NOT ${WRF_GENERAL_IDEAL_CASE} ) # Not general ideal and not real
56-
# All others are variants of ideal
57-
add_executable(
58-
ideal
59-
ideal_em.F
60-
${MODULE_FILE}
61-
)
62-
list( APPEND FOLDER_COMPILE_TARGETS ideal )
63-
else()
64-
# greater than or equal to general ideal case
65-
add_executable(
66-
ideal
67-
ideal_em.F
68-
${PROJECT_SOURCE_DIR}/dyn_em/module_initialize_ideal.F
69-
)
70-
list( APPEND FOLDER_COMPILE_TARGETS ideal )
50+
elseif( NOT ${WRF_GENERAL_IDEAL_CASE} ) # Not general ideal and not real
51+
# All others are variants of ideal
52+
add_executable(
53+
ideal
54+
ideal_em.F
55+
${MODULE_FILE}
56+
)
57+
list( APPEND FOLDER_COMPILE_TARGETS ideal )
58+
else()
59+
# greater than or equal to general ideal case
60+
add_executable(
61+
ideal
62+
ideal_em.F
63+
${PROJECT_SOURCE_DIR}/dyn_em/module_initialize_ideal.F
64+
)
65+
list( APPEND FOLDER_COMPILE_TARGETS ideal )
66+
endif()
7167
endif()
7268

73-
7469
foreach ( TARGET ${FOLDER_COMPILE_TARGETS} )
7570
set_target_properties(
7671
${TARGET}
@@ -154,3 +149,13 @@ wrf_setup_files(
154149
DEST_PATH
155150
${CMAKE_INSTALL_PREFIX}/run/
156151
)
152+
153+
if ( ${WRF_CORE} STREQUAL "PLUS" )
154+
wrf_setup_target_new_name(
155+
TARGET wrf
156+
DEST_PATH ${CMAKE_INSTALL_PREFIX}/run
157+
NEW_NAME wrfplus
158+
USE_SYMLINKS
159+
160+
)
161+
endif()

wrftladj/CMakeLists.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# WRF CMake Build
2+
3+
4+
target_sources(
5+
${PROJECT_NAME}_Core
6+
PRIVATE
7+
# Mods MP
8+
module_mp_mkessler.F
9+
module_mp_nconvp.F
10+
# Mods BL
11+
module_bl_surface_drag.F
12+
# Mods CU
13+
module_cu_du.F
14+
# Mods LL
15+
module_linked_list2.F
16+
# Mods PT
17+
mediation_pertmod_io.F
18+
# Dynem mods
19+
module_advect_em_tl.F
20+
module_advect_em_ad.F
21+
module_diffusion_em_tl.F
22+
module_diffusion_em_ad.F
23+
module_small_step_em_tl.F
24+
module_small_step_em_ad.F
25+
module_big_step_utilities_em_tl.F
26+
module_big_step_utilities_em_ad.F
27+
module_em_tl.F
28+
module_em_ad.F
29+
module_bc_em_tl.F
30+
module_bc_em_ad.F
31+
module_first_rk_step_part1_tl.F
32+
module_first_rk_step_part1_ad.F
33+
module_first_rk_step_part2_tl.F
34+
module_first_rk_step_part2_ad.F
35+
module_sfs_nba_tl.F
36+
module_sfs_nba_ad.F
37+
module_sfs_driver_tl.F
38+
module_sfs_driver_ad.F
39+
# Dynem objs
40+
solve_em_tl.F
41+
solve_em_ad.F
42+
start_em_tl.F
43+
start_em_ad.F
44+
# Phys mods
45+
module_bl_gwdo_tl.F
46+
module_bl_gwdo_ad.F
47+
module_bl_surface_drag_tl.F
48+
module_bl_surface_drag_ad.F
49+
module_cu_du_tl.F
50+
module_cu_du_ad.F
51+
module_mp_mkessler_tl.F
52+
module_mp_mkessler_ad.F
53+
module_mp_wsm6r_tl.F
54+
module_mp_wsm6r_ad.F
55+
module_mp_nconvp_tl.F
56+
module_mp_nconvp_ad.F
57+
module_physics_addtendc_tl.F
58+
module_physics_addtendc_ad.F
59+
module_physics_init_tl.F
60+
module_physics_init_ad.F
61+
module_pbl_driver_tl.F
62+
module_pbl_driver_ad.F
63+
module_cumulus_driver_tl.F
64+
module_cumulus_driver_ad.F
65+
module_microphysics_driver_tl.F
66+
module_microphysics_driver_ad.F
67+
module_microphysics_zero_out_tl.F
68+
module_microphysics_zero_out_ad.F
69+
# Share mods
70+
module_adtl_grid_utilities.F
71+
module_bc_tl.F
72+
module_bc_ad.F
73+
# Share objs
74+
jcdfi.F
75+
# Frame objs
76+
adStack.c
77+
adBuffer.F
78+
)
79+
80+
set_source_files_properties(
81+
adBuffer.F
82+
TARGET_DIRECTORY ${PROJECT_NAME}_Core
83+
PROPERTIES
84+
Fortran_FORMAT FIXED
85+
)
86+

0 commit comments

Comments
 (0)