Update version info for release v4.6.1 (#2122)
[WRF.git] / main / CMakeLists.txt
blobb0ec69d7f008591c9d10db6370c9bdb3aedb2402
1 # WRF CMake Build
2 set( FOLDER_COMPILE_TARGETS )
4 add_compile_options    ( "${PROJECT_COMPILE_OPTIONS}"     )
5 add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
7 # 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
17   add_executable( 
18                   wrf
19                   wrf.F
20                   module_wrf_top.F
21                   )
22   list( APPEND FOLDER_COMPILE_TARGETS wrf )
23 # #!TODO When does this get activated?
24 # elseif()
25 #   add_executable(
26 #                   wrf_SST_ESMF
27 #                   wrf_ESMFMod.F
28 #                   wrf_SST_ESMF.F
29 #                   module_wrf_top.F
30 #                   )
31 #   list( APPEND FOLDER_COMPILE_TARGETS em_wrf_SST_ESMF )
32 endif()
34 # Use case info from higher CMakeLists.txt
35 set( MODULE_FILE ${PROJECT_SOURCE_DIR}/dyn_em/module_initialize_${WRF_CASE_MODULE}.F )
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}
47                   )
48   add_executable( 
49                   real
50                   real_em.F
51                   ${MODULE_FILE}
52                 )
53   list( APPEND FOLDER_COMPILE_TARGETS ndown tc real )
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 )
71 endif()
74 foreach ( TARGET ${FOLDER_COMPILE_TARGETS} )
75   set_target_properties( 
76                         ${TARGET}
77                           PROPERTIES
78                             # Just dump everything in here
79                             Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/modules/${TARGET}/
80                             Fortran_FORMAT           FREE                          
81                         )
83   
84   if ( ${USE_IPO} )
85     set_target_properties(
86                         ${TARGET}
87                         PROPERTIES
88                           INTERPROCEDURAL_OPTIMIZATION TRUE
89                         )
91     if ( ${CMAKE_VERSION} VERSION_LESS 3.24 )
92       target_link_libraries( 
93                         ${TARGET}
94                         PRIVATE
95                           ${PROJECT_NAME}_Core
96                         )
98       # Static libraries with LTO/IPO sometimes don't pull all the correct symbols
99       set( LINKER_OPTION ${CMAKE_Fortran_LINKER_WRAPPER_FLAG} )
100       target_link_options(
101                           ${TARGET}
102                           PRIVATE
103                             ${LINKER_OPTION}--whole-archive $<TARGET_FILE:${PROJECT_NAME}_Core> ${LINKER_OPTION}--no-whole-archive
104                           )
105     else()
106       target_link_libraries( 
107                         ${TARGET}
108                         PRIVATE
109                           $<LINK_LIBRARY:WHOLE_ARCHIVE,${PROJECT_NAME}_Core>
110                         )
111     endif()
112   else()
113     target_link_libraries( 
114                         ${TARGET}
115                         PRIVATE
116                           ${PROJECT_NAME}_Core
117                         )
118   endif()
120   target_include_directories(
121                               ${TARGET}
122                               PRIVATE
123                                 ${PROJECT_SOURCE_DIR}/inc
124                                 ${PROJECT_BINARY_DIR}/inc
125                                 $<TARGET_PROPERTY:${PROJECT_NAME}_Core,Fortran_MODULE_DIRECTORY>
126                             )
127 endforeach()
130 install(
131         TARGETS ${FOLDER_COMPILE_TARGETS}
132         RUNTIME DESTINATION bin/
133         ARCHIVE DESTINATION lib/
134         LIBRARY DESTINATION lib/
135         )
137 # Install the "run" directory
138 install(
139         DIRECTORY   ${PROJECT_SOURCE_DIR}/run/
140         DESTINATION ${CMAKE_INSTALL_PREFIX}/run
141         PATTERN CMakeLists.txt EXCLUDE
142         PATTERN .gitignore     EXCLUDE
143         )
144 wrf_setup_targets(
145                   TARGETS         ${FOLDER_COMPILE_TARGETS}
146                   DEST_PATH       ${CMAKE_INSTALL_PREFIX}/run
147                   USE_SYMLINKS
148                   )
150 # Re-setup this particular file
151 wrf_setup_files(
152                 FILES
153                   ${PROJECT_SOURCE_DIR}/phys/noahmp/parameters/MPTABLE.TBL
154                 DEST_PATH
155                   ${CMAKE_INSTALL_PREFIX}/run/
156                 )