CMake netCDF Compatibility with WPS (#2121)
[WRF.git] / cmake / wrf_case_setup.cmake
blob4e65dc0a72f6a84511f07f11d949af14b4245f1a
1 # WRF Macro for adding target symlinks/copies to be run after internal install() code
2 macro( wrf_setup_targets )
4   set( options        USE_SYMLINKS )
5   set( oneValueArgs   DEST_PATH )
6   set( multiValueArgs TARGETS  )
8   cmake_parse_arguments(
9                         WRF_SETUP
10                         "${options}"  "${oneValueArgs}"  "${multiValueArgs}"
11                         ${ARGN}
12                         )
13   set( WRF_SETUP_CMD copy_if_different )
14   if ( ${WRF_SETUP_USE_SYMLINKS} )
15     set( WRF_SETUP_CMD create_symlink )
16   endif()
19   foreach ( WRF_SETUP_TARGET ${WRF_SETUP_TARGETS} )
21     # Generate install code for each target
22     # https://stackoverflow.com/a/56528615
23     #!TODO Do we *need* the rm for symlinks beforehand?
24     # get_filename_component( WRF_SETUP_FILE_ONLY $<TARGET_FILE:${WRF_SETUP_TARGET}> NAME
26     # If we ever wanted to link or copy things other than binaries we could change this
27     set( WRF_SETUP_INSTALL_LOCATION ${CMAKE_INSTALL_PREFIX}/bin )
29     install( 
30             CODE "
31                   message( STATUS \"Setting up $<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> via ${WRF_SETUP_CMD}\" )
32                   execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_INSTALL_LOCATION}/$<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> ${WRF_SETUP_DEST_PATH}/$<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> )
33                   "
34             COMPONENT setup
35             )
36     
37     # Add .exe link as well
38     install( 
39             CODE "
40                   message( STATUS \"Creating symlink for $<TARGET_FILE_NAME:${WRF_SETUP_TARGET}>.exe\" )
41                   execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${WRF_SETUP_DEST_PATH}/$<TARGET_FILE_NAME:${WRF_SETUP_TARGET}> ${WRF_SETUP_DEST_PATH}/$<TARGET_FILE_NAME:${WRF_SETUP_TARGET}>.exe )
42                   "
43             COMPONENT setup
44             )
46   endforeach()
48 endmacro()
50 # WRF Macro for adding file symlinks/copies to be run after internal install() code
51 macro( wrf_setup_files )
53   set( options        USE_SYMLINKS )
54   set( oneValueArgs   DEST_PATH )
55   set( multiValueArgs FILES  )
57   cmake_parse_arguments(
58                         WRF_SETUP
59                         "${options}"  "${oneValueArgs}"  "${multiValueArgs}"
60                         ${ARGN}
61                         )
62   set( WRF_SETUP_CMD copy_if_different )
63   if ( ${WRF_SETUP_USE_SYMLINKS} )
64     set( WRF_SETUP_CMD create_symlink )
65   endif()
66   
67   foreach ( WRF_SETUP_FILE ${WRF_SETUP_FILES} )
68     
69     # Generate install code for each file, this could be done in a simpler manner
70     # with regular commands but to preserve order of operations it will be done via install( CODE ... )
71     # https://stackoverflow.com/a/56528615
72     get_filename_component( WRF_SETUP_FULL_FILE ${WRF_SETUP_FILE} ABSOLUTE )
73     get_filename_component( WRF_SETUP_FILE_ONLY ${WRF_SETUP_FILE} NAME     )
74     # Left here for debug purposes, may want to turn this into a trace-level debug msg
75     # message( "Generating install commands for ${WRF_SETUP_FILE_ONLY} into ${WRF_SETUP_DEST_PATH}" )
76     install( 
77             CODE "
78                   message( STATUS \"Setting up ${WRF_SETUP_FILE_ONLY} via ${WRF_SETUP_CMD}\" )
79                   execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_FULL_FILE} ${WRF_SETUP_DEST_PATH}/${WRF_SETUP_FILE_ONLY} )
80                   "
81             COMPONENT setup
82             )
84   endforeach()
86 endmacro()
88 # WRF Macro for adding file symlink to be run after internal install() code
89 macro( wrf_setup_file_new_name )
91   set( options        USE_SYMLINKS )
92   set( oneValueArgs   FILE NEW_NAME )
93   set( multiValueArgs )
95   cmake_parse_arguments(
96                         WRF_SETUP
97                         "${options}"  "${oneValueArgs}"  "${multiValueArgs}"
98                         ${ARGN}
99                         )
100   
101   set( WRF_SETUP_CMD copy_if_different )
102   if ( ${WRF_SETUP_USE_SYMLINKS} )
103     set( WRF_SETUP_CMD create_symlink )
104   endif()
105   
106   # Generate install code for each file, this could be done in a simpler manner
107   # with regular commands but to preserve order of operations it will be done via install( CODE ... )
108   # https://stackoverflow.com/a/56528615
109   get_filename_component( WRF_SETUP_FULL_FILE ${WRF_SETUP_FILE} ABSOLUTE )
110   get_filename_component( WRF_SETUP_FILE_ONLY ${WRF_SETUP_FILE} NAME     )
111   get_filename_component( WRF_SETUP_NEW_NAME_FULL_FILE ${WRF_SETUP_NEW_NAME} ABSOLUTE )
112   get_filename_component( WRF_SETUP_NEW_NAME_FILE_ONLY ${WRF_SETUP_NEW_NAME} NAME     )
113   # Left here for debug purposes, may want to turn this into a trace-level debug msg
114   # message( "Generating install commands for ${WRF_SETUP_FILE_ONLY} to ${WRF_SETUP_NEW_NAME_FILE_ONLY}" )
115   install( 
116           CODE "
117                 message( STATUS \"Setting up ${WRF_SETUP_FILE_ONLY} (rename ${WRF_SETUP_NEW_NAME_FILE_ONLY}) via ${WRF_SETUP_CMD}\" )
118                 execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_FULL_FILE} ${WRF_SETUP_NEW_NAME_FULL_FILE} )
119                 "
120           COMPONENT setup
121           )
123 endmacro()