diff --git a/CMake/OTBApplicationMacros.cmake b/CMake/OTBApplicationMacros.cmake index d354b4cf72c5fce9323f4fa44ea6d2e6aa371cdb..921071575e235ad39ce34e22062313dd2766dc53 100644 --- a/CMake/OTBApplicationMacros.cmake +++ b/CMake/OTBApplicationMacros.cmake @@ -71,71 +71,37 @@ macro(otb_create_application) COMPONENT RuntimeLibraries) endif() - # Generate a quickstart script in the build dir - #if (NOT WIN32) - - # What is the path to the applications - # a MODULE target is always treated as LIBRARY - get_target_property(APPLICATION_BINARY_PATH ${APPLICATION_TARGET_NAME} LIBRARY_OUTPUT_DIRECTORY) - - if (NOT APPLICATION_BINARY_PATH) - set(APPLICATION_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR}) - endif() - - if (WIN32) - set(SCRIPT_CLI_SOURCE ${OTB_SOURCE_DIR}/CMake/otbcli_app.bat.in) - set(SCRIPT_CLI_INTERMEDIATE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbcli_${APPLICATION_NAME}.bat) - set(SCRIPT_CLI_INSTALLABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/otbcli_${APPLICATION_NAME}.bat) - else() - set(SCRIPT_CLI_SOURCE ${OTB_SOURCE_DIR}/CMake/otbcli_app.sh.in) - set(SCRIPT_CLI_INTERMEDIATE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbcli_${APPLICATION_NAME}) - set(SCRIPT_CLI_INSTALLABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/otbcli_${APPLICATION_NAME}) - endif() - - if (EXISTS ${SCRIPT_CLI_SOURCE}) - # Generate a script in the build dir, next to the cli launcher - configure_file( ${SCRIPT_CLI_SOURCE} - ${SCRIPT_CLI_INTERMEDIATE} - @ONLY ) - - # Copy it next to the application shared lib, and give executable rights - file(COPY ${SCRIPT_CLI_INTERMEDIATE} - DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - - # Install a version of this script if we are inside the OTB build - install(PROGRAMS ${SCRIPT_CLI_INSTALLABLE} - DESTINATION ${OTB_INSTALL_RUNTIME_DIR} - COMPONENT Runtime) - endif() - - if (WIN32) - set(SCRIPT_GUI_SOURCE ${OTB_SOURCE_DIR}/CMake/otbgui_app.bat.in) - set(SCRIPT_GUI_INTERMEDIATE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbgui_${APPLICATION_NAME}.bat) - set(SCRIPT_GUI_INSTALLABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/otbgui_${APPLICATION_NAME}.bat) - else() - set(SCRIPT_GUI_SOURCE ${OTB_SOURCE_DIR}/CMake/otbgui_app.sh.in) - set(SCRIPT_GUI_INTERMEDIATE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbgui_${APPLICATION_NAME}) - set(SCRIPT_GUI_INSTALLABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/otbgui_${APPLICATION_NAME}) - endif() - - if (EXISTS ${SCRIPT_GUI_SOURCE}) - # Generate a script in the build dir, next to the cli launcher - configure_file( ${SCRIPT_GUI_SOURCE} - ${SCRIPT_GUI_INTERMEDIATE} - @ONLY ) - - # Copy it next to the application shared lib, and give executable rights - file(COPY ${SCRIPT_GUI_INTERMEDIATE} - DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - - # Install a version of this script if we are inside the OTB build - install(PROGRAMS ${SCRIPT_GUI_INSTALLABLE} - DESTINATION ${OTB_INSTALL_RUNTIME_DIR} - COMPONENT Runtime) - endif() - #endif() + # What is the path to the applications + # a MODULE target is always treated as LIBRARY + get_target_property(APPLICATION_BINARY_PATH ${APPLICATION_TARGET_NAME} LIBRARY_OUTPUT_DIRECTORY) + + if (NOT APPLICATION_BINARY_PATH) + set(APPLICATION_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + set(INTERMEDIATE_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}) + set(SCRIPT_EXT "") + if (WIN32) + set(SCRIPT_EXT ".bat") + endif() + + # ----- Create and install launcher scripts ------ + foreach(type CLI GUI) + string(TOLOWER "${type}" type_lower) + set(SCRIPT_NAME otb${type_lower}_${APPLICATION_NAME}${SCRIPT_EXT}) + otb_write_app_launcher( + NAME ${APPLICATION_NAME} + OUTPUT ${INTERMEDIATE_DIR}/${SCRIPT_NAME} + TYPE ${type}) + # Copy it next to the application shared lib, and give executable rights + file(COPY ${INTERMEDIATE_DIR}/${SCRIPT_NAME} + DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + # Install a version of this script if we are inside the OTB build + install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${SCRIPT_NAME} + DESTINATION ${OTB_INSTALL_RUNTIME_DIR} + COMPONENT Runtime) + endforeach() list(APPEND OTB_APPLICATIONS_NAME_LIST ${APPLICATION_NAME}) list(REMOVE_DUPLICATES OTB_APPLICATIONS_NAME_LIST) @@ -170,3 +136,56 @@ macro(otb_test_application) -testenv ${TESTAPPLICATION_TESTENVOPTIONS}) endif() endmacro() + +macro(otb_write_app_launcher) + cmake_parse_arguments(APPLAUNCHER "" "NAME;OUTPUT;TYPE" "" ${ARGN} ) + if("${APPLAUNCHER_TYPE}" STREQUAL "CLI") + set(_launcher_type "otbcli") + elseif("${APPLAUNCHER_TYPE}" STREQUAL "GUI") + set(_launcher_type "otbgui") + else() + message(FATAL_ERROR "Unknown launcher type : ${APPLAUNCHER_TYPE}, only support CLI and GUI") + endif() + + if(WIN32) + # Launcher script in Batch format + file(WRITE "${APPLAUNCHER_OUTPUT}" +"@echo off +:: +:: Autogenerated by OTB installation process +:: DO NOT MODIFY +:: +set CURRENT_SCRIPT_DIR=%~dp0 +if exist %CURRENT_SCRIPT_DIR%${_launcher_type}.bat ( + :: Prefer using the launcher inside the script dir + set OTB_LAUNCHER=%CURRENT_SCRIPT_DIR%${_launcher_type}.bat +) else ( + :: Use the one from the PATH + set OTB_LAUNCHER=${_launcher_type}.bat +) + +:: start the application +%OTB_LAUNCHER% ${APPLAUNCHER_NAME} %* +") + else() + # Launcher script in Shell format + file(WRITE "${APPLAUNCHER_OUTPUT}" +"#!/bin/sh +# +# Autogenerated by OTB installation process +# DO NOT MODIFY +# +CURRENT_SCRIPT_DIR=$(dirname \"\$0\") +if [ -e \"\$CURRENT_SCRIPT_DIR/${_launcher_type}\" ] ; then + # Prefer using the launcher inside the script dir + OTB_LAUNCHER=$CURRENT_SCRIPT_DIR/${_launcher_type} +else + # Use the one from the PATH + OTB_LAUNCHER=${_launcher_type} +fi + +# start the application +\$OTB_LAUNCHER ${APPLAUNCHER_NAME} \"$@\" +") + endif() +endmacro() diff --git a/CMake/otbcli_app.bat.in b/CMake/otbcli_app.bat.in deleted file mode 100644 index e4af53d8e5cf0290d45049be10ee673daed9cbb0..0000000000000000000000000000000000000000 --- a/CMake/otbcli_app.bat.in +++ /dev/null @@ -1,18 +0,0 @@ -@echo off -:: -:: Autogenerated by OTB installation process -:: DO NOT MODIFY -:: - -set CURRENT_SCRIPT_DIR=%~dp0 - -if exist %CURRENT_SCRIPT_DIR%otbcli.bat ( - :: Prefer using the launcher inside the script dir - set OTB_CLI_LAUNCHER=%CURRENT_SCRIPT_DIR%otbcli.bat -) else ( - :: Use the one from the PATH - set OTB_CLI_LAUNCHER=otbcli.bat -) - -:: start the application -%OTB_CLI_LAUNCHER% @APPLICATION_NAME@ %* diff --git a/CMake/otbcli_app.sh.in b/CMake/otbcli_app.sh.in deleted file mode 100644 index c073ae192b11e4d34c412835c44bfdf4c4792a25..0000000000000000000000000000000000000000 --- a/CMake/otbcli_app.sh.in +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# -# Autogenerated by OTB installation process -# DO NOT MODIFY -# - -CURRENT_SCRIPT_DIR=$(dirname "$0") - -if [ -e "$CURRENT_SCRIPT_DIR/otbcli" ] -then - # Prefer using the launcher inside the script dir - OTB_CLI_LAUNCHER=$CURRENT_SCRIPT_DIR/otbcli -else - # Use the one from the PATH - OTB_CLI_LAUNCHER=otbcli -fi - -# start the application -$OTB_CLI_LAUNCHER @APPLICATION_NAME@ "$@" diff --git a/CMake/otbgui_app.bat.in b/CMake/otbgui_app.bat.in deleted file mode 100644 index 5752728a54804cdbd6f06d48ae0c85f97d67ec7b..0000000000000000000000000000000000000000 --- a/CMake/otbgui_app.bat.in +++ /dev/null @@ -1,18 +0,0 @@ -@echo off -:: -:: Autogenerated by OTB installation process -:: DO NOT MODIFY -:: - -set CURRENT_SCRIPT_DIR=%~dp0 - -if exist %CURRENT_SCRIPT_DIR%otbgui.bat ( - :: Prefer using the launcher inside the script dir - set OTB_GUI_LAUNCHER=%CURRENT_SCRIPT_DIR%otbgui.bat -) else ( - :: Use the one from the PATH - set OTB_GUI_LAUNCHER=otbgui.bat -) - -:: start the application -%OTB_GUI_LAUNCHER% @APPLICATION_NAME@ %* diff --git a/CMake/otbgui_app.sh.in b/CMake/otbgui_app.sh.in deleted file mode 100644 index 7243475e300ff137b94203ec698f74d192bd80fa..0000000000000000000000000000000000000000 --- a/CMake/otbgui_app.sh.in +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# -# Autogenerated by OTB installation process -# DO NOT MODIFY -# - -CURRENT_SCRIPT_DIR=$(dirname "$0") - -if [ -e "$CURRENT_SCRIPT_DIR/otbgui" ] -then - # Prefer using the launcher inside the script dir - OTB_GUI_LAUNCHER=$CURRENT_SCRIPT_DIR/otbgui -else - # Use the one from the PATH - OTB_GUI_LAUNCHER=otbgui -fi - -# start the application -$OTB_GUI_LAUNCHER @APPLICATION_NAME@ "$@"