From 59678855f6f207f634fcbaa82c05392f0935b425 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 21 Feb 2024 16:43:41 -0700 Subject: [PATCH] Install main bins with .exe links similar to WRF cmake --- CMakeLists.txt | 19 +++++++ cmake/wrf_case_setup.cmake | 124 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 cmake/wrf_case_setup.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d4d28e9..bd6ce9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,8 @@ include( CMakePackageConfigHelpers ) # include( confcheck ) # include( gitinfo ) include( wrf_get_version ) +include( wrf_case_setup ) + # Grab version info wrf_get_version( ${PROJECT_SOURCE_DIR}/README ) @@ -156,6 +158,23 @@ add_subdirectory( util ) ## Install and export ## ################################################################################ +wrf_setup_targets( + TARGETS + $ + $ + $ + DEST_PATH ${CMAKE_INSTALL_PREFIX}/bin + ) + + +wrf_setup_files( + FILES + ${PROJECT_SOURCE_DIR}/link_grib.csh + DEST_PATH + ${CMAKE_INSTALL_PREFIX}/bin + USE_SYMLINKS + ) + # Install to namespace install( diff --git a/cmake/wrf_case_setup.cmake b/cmake/wrf_case_setup.cmake new file mode 100644 index 0000000..4e65dc0 --- /dev/null +++ b/cmake/wrf_case_setup.cmake @@ -0,0 +1,124 @@ +# WRF Macro for adding target symlinks/copies to be run after internal install() code +macro( wrf_setup_targets ) + + set( options USE_SYMLINKS ) + set( oneValueArgs DEST_PATH ) + set( multiValueArgs TARGETS ) + + cmake_parse_arguments( + WRF_SETUP + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + set( WRF_SETUP_CMD copy_if_different ) + if ( ${WRF_SETUP_USE_SYMLINKS} ) + set( WRF_SETUP_CMD create_symlink ) + endif() + + + foreach ( WRF_SETUP_TARGET ${WRF_SETUP_TARGETS} ) + + # Generate install code for each target + # https://stackoverflow.com/a/56528615 + #!TODO Do we *need* the rm for symlinks beforehand? + # get_filename_component( WRF_SETUP_FILE_ONLY $ NAME + + # If we ever wanted to link or copy things other than binaries we could change this + set( WRF_SETUP_INSTALL_LOCATION ${CMAKE_INSTALL_PREFIX}/bin ) + + install( + CODE " + message( STATUS \"Setting up $ via ${WRF_SETUP_CMD}\" ) + execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_INSTALL_LOCATION}/$ ${WRF_SETUP_DEST_PATH}/$ ) + " + COMPONENT setup + ) + + # Add .exe link as well + install( + CODE " + message( STATUS \"Creating symlink for $.exe\" ) + execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${WRF_SETUP_DEST_PATH}/$ ${WRF_SETUP_DEST_PATH}/$.exe ) + " + COMPONENT setup + ) + + endforeach() + +endmacro() + +# WRF Macro for adding file symlinks/copies to be run after internal install() code +macro( wrf_setup_files ) + + set( options USE_SYMLINKS ) + set( oneValueArgs DEST_PATH ) + set( multiValueArgs FILES ) + + cmake_parse_arguments( + WRF_SETUP + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + set( WRF_SETUP_CMD copy_if_different ) + if ( ${WRF_SETUP_USE_SYMLINKS} ) + set( WRF_SETUP_CMD create_symlink ) + endif() + + foreach ( WRF_SETUP_FILE ${WRF_SETUP_FILES} ) + + # Generate install code for each file, this could be done in a simpler manner + # with regular commands but to preserve order of operations it will be done via install( CODE ... ) + # https://stackoverflow.com/a/56528615 + get_filename_component( WRF_SETUP_FULL_FILE ${WRF_SETUP_FILE} ABSOLUTE ) + get_filename_component( WRF_SETUP_FILE_ONLY ${WRF_SETUP_FILE} NAME ) + # Left here for debug purposes, may want to turn this into a trace-level debug msg + # message( "Generating install commands for ${WRF_SETUP_FILE_ONLY} into ${WRF_SETUP_DEST_PATH}" ) + install( + CODE " + message( STATUS \"Setting up ${WRF_SETUP_FILE_ONLY} via ${WRF_SETUP_CMD}\" ) + execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_FULL_FILE} ${WRF_SETUP_DEST_PATH}/${WRF_SETUP_FILE_ONLY} ) + " + COMPONENT setup + ) + + endforeach() + +endmacro() + +# WRF Macro for adding file symlink to be run after internal install() code +macro( wrf_setup_file_new_name ) + + set( options USE_SYMLINKS ) + set( oneValueArgs FILE NEW_NAME ) + set( multiValueArgs ) + + cmake_parse_arguments( + WRF_SETUP + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + + set( WRF_SETUP_CMD copy_if_different ) + if ( ${WRF_SETUP_USE_SYMLINKS} ) + set( WRF_SETUP_CMD create_symlink ) + endif() + + # Generate install code for each file, this could be done in a simpler manner + # with regular commands but to preserve order of operations it will be done via install( CODE ... ) + # https://stackoverflow.com/a/56528615 + get_filename_component( WRF_SETUP_FULL_FILE ${WRF_SETUP_FILE} ABSOLUTE ) + get_filename_component( WRF_SETUP_FILE_ONLY ${WRF_SETUP_FILE} NAME ) + get_filename_component( WRF_SETUP_NEW_NAME_FULL_FILE ${WRF_SETUP_NEW_NAME} ABSOLUTE ) + get_filename_component( WRF_SETUP_NEW_NAME_FILE_ONLY ${WRF_SETUP_NEW_NAME} NAME ) + # Left here for debug purposes, may want to turn this into a trace-level debug msg + # message( "Generating install commands for ${WRF_SETUP_FILE_ONLY} to ${WRF_SETUP_NEW_NAME_FILE_ONLY}" ) + install( + CODE " + message( STATUS \"Setting up ${WRF_SETUP_FILE_ONLY} (rename ${WRF_SETUP_NEW_NAME_FILE_ONLY}) via ${WRF_SETUP_CMD}\" ) + execute_process( COMMAND ${CMAKE_COMMAND} -E ${WRF_SETUP_CMD} ${WRF_SETUP_FULL_FILE} ${WRF_SETUP_NEW_NAME_FULL_FILE} ) + " + COMPONENT setup + ) + +endmacro() + -- 2.11.4.GIT