Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / tools / CMakeLists.txt
blob7f07eb25393dcdeebbf61fe6e147453cd433fbf1
1 # WRF CMake Build
2 add_compile_options    ( "${PROJECT_COMPILE_OPTIONS}"     )
3 add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
5 #!TODO ORGANIZE THIS FOLDER
6 set( FOLDER_COMPILE_TARGET registry )
8 add_executable(
9                ${FOLDER_COMPILE_TARGET}
10               )
12 set( GEN_COMMS gen_comms.stub )
13 if ( ${USE_RSL_LITE} )
14   message( STATUS "Setting gen_comms to RSL_LITE" )
15   set( GEN_COMMS ${PROJECT_SOURCE_DIR}/external/RSL_LITE/gen_comms.c )
16 else()
17   # Account for the weird makefile nonsense of copying things around
18   set_source_files_properties( 
19                               gen_comms.stub
20                               TARGET_DIRECTORY ${FOLDER_COMPILE_TARGET}
21                               PROPERTIES
22                                 LANGUAGE C
23                               )
24 endif()
26 target_sources(
27                 ${FOLDER_COMPILE_TARGET}
28                 PRIVATE
29                   registry.c
30                   my_strtok.c
31                   reg_parse.c
32                   data.c
33                   type.c
34                   misc.c
35                   gen_defs.c
36                   gen_allocs.c
37                   gen_mod_state_descr.c
38                   gen_scalar_indices.c
39                   gen_args.c
40                   gen_config.c
41                   sym.c
42                   symtab_gen.c
43                   gen_irr_diag.c
44                   gen_model_data_ord.c
45                   gen_interp.c
46                   # gen_comms.c
47                   ${GEN_COMMS}
48                   gen_scalar_derefs.c
49                   set_dim_strs.c
50                   gen_wrf_io.c
51                   gen_streams.c
52                   )
54 # set_target_properties( 
55 #                       ${FOLDER_COMPILE_TARGET} 
56 #                         PROPERTIES
57 #                           Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${FOLDER_COMPILE_TARGET}
58 #                           Fortran_FORMAT           FREE                          
59 #                       )
61 target_include_directories( ${FOLDER_COMPILE_TARGET}
62                             PRIVATE
63                               ${CMAKE_CURRENT_SOURCE_DIR}
64                             )
66 install(
67         TARGETS ${FOLDER_COMPILE_TARGET}
68         RUNTIME DESTINATION bin/
69         ARCHIVE DESTINATION lib/
70         LIBRARY DESTINATION lib/
71         )
73 # Extra stuff for weird registry stuff
74 set( REGISTRY_FILE "NO_REGISTRY_FILE_SET" )
75 if ( ${WRF_CORE} STREQUAL "ARW" )
76   
77   if ( ${ENABLE_CHEM} )
78     set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.EM_CHEM )
80   # This check does nothing
81   # elseif ( ${WRF_DFI_RADAR} )
82   #   set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.EM )
84   else()
85     set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.EM )
87   endif()
89 elseif ( ${WRF_CORE} STREQUAL "PLUS" )
90     set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.tladj )
92 elseif ( ${WRF_CORE} STREQUAL "CONVERT" )
93   set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.CONVERT )
95 elseif ( ${WRF_CORE} STREQUAL "DA" OR ${WRF_CORE} STREQUAL "DA_4D_VAR" )
96   if ( ${WRF_CHEM} )
97     set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.wrfchemvar )
98   else()
99     set( REGISTRY_FILE ${PROJECT_SOURCE_DIR}/Registry/Registry.wrfvar )
100   endif()
102 endif()
104 set( dealloc_source )
105 foreach( n RANGE 0 11 )
106   list(
107         APPEND
108         dealloc_source
109         ${CMAKE_BINARY_DIR}/inc/deallocs_${n}.F
110         )
111 endforeach()
113 set( allocs_source )
114 foreach( n RANGE 0 31 )
115   list(
116         APPEND
117         allocs_source
118         ${CMAKE_BINARY_DIR}/inc/allocs_${n}.F
119         )
120 endforeach()
122 wrf_expand_definitions( 
123                         RESULT_VAR  REGISTRY_DEFS
124                         DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
125                         )
127 # How this is not a bigger thing or not resolved is beyond me
128 # https://gitlab.kitware.com/cmake/cmake/-/issues/18005
129 # Also the suggestion does not work
130 add_custom_command(
131                     OUTPUT
132                       ${CMAKE_BINARY_DIR}/inc/nl_config.inc
133                       ${CMAKE_BINARY_DIR}/frame/module_state_description.F
134                       ${dealloc_source}
135                       ${allocs_source}
136                     COMMENT
137                       "Generating registry code..."
138                     WORKING_DIRECTORY
139                       ${CMAKE_BINARY_DIR}
140                     # Replicate what exists in project directory for registry
141                     COMMAND
142                       ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Registry
143                     COMMAND
144                       ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/inc
145                     COMMAND
146                       ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/frame
147                     COMMAND
148                       ${CMAKE_BINARY_DIR}/tools/registry ${REGISTRY_DEFS} -DNEW_BDYS ${REGISTRY_FILE} > ${CMAKE_BINARY_DIR}/registry.log 2>&1
149                     #!TODO Just have the registry code actually check for failure or better yet rewrite the 
150                     # registry code to not be so obfuscating
151                     COMMAND 
152                       ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/inc/nl_config.inc ${CMAKE_BINARY_DIR}/inc/nl_config.inc
153                     DEPENDS
154                       ${FOLDER_COMPILE_TARGET}
155                     )
159 add_custom_target( 
160                   registry_code
161                   DEPENDS
162                     ${CMAKE_BINARY_DIR}/inc/nl_config.inc
163                     ${CMAKE_BINARY_DIR}/frame/module_state_description.F
164                     ${dealloc_source}
165                     ${allocs_source}
166                   )
168 target_sources(
169                 ${PROJECT_NAME}_Core
170                 PRIVATE
171                   ${CMAKE_BINARY_DIR}/frame/module_state_description.F
172                   ${dealloc_source}
173                   ${allocs_source}
174                 )