Skip to content

Commit

Permalink
Configure paths in desktop shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Apr 13, 2018
1 parent b434344 commit 714d755
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,11 @@ if(GENERATE_doc_html)
DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()

# Configure and install desktop shortcut.
if(UNIX)
include(DesktopShortcutHelpers)
configure_and_install_desktop_shortcut(${CMAKE_SOURCE_DIR}/cmake/templates/robotDevastation.desktop.in)
endif()

# Uninstall target.
include(AddUninstallTarget)
64 changes: 64 additions & 0 deletions cmake/DesktopShortcutHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
if(COMMAND configure_and_install_desktop_shortcut)
return()
endif()

function(configure_and_install_desktop_shortcut)
set(_arg ${ARGV0})

if("${_arg}" STREQUAL "")
message(SEND_ERROR "Missing argument to configure_desktop_shortcut().")
return()
endif()

# Retrieve and sanitize file name of provided template.
get_filename_component(_template_name ${_arg} NAME)
string(REGEX REPLACE "\\.in$" "" _filename ${_template_name})
string(REGEX MATCH ".+\\.desktop$" _valid_filename ${_filename})

if(NOT _valid_filename)
message(SEND_ERROR "Invalid desktop file: \"${_filename}\".")
return()
endif()

# Configure desktop shortcut (build tree).
set(DESKTOP_SHORTCUT_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
configure_file(${_arg} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_filename})

# Configure desktop shortcut (install tree).
set(DESKTOP_SHORTCUT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
configure_file(${_arg} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_filename}.install)

# Set execute permissions on shortcut (build tree).
file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_filename}
DESTINATION ${CMAKE_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)

# Find xdg-user-dir program.
find_program(XdgUserDir_EXECUTABLE xdg-user-dir)
set(_desktop_install_path)

# Retrieve desktop location via xdg-user-dir or env variable.
if(XdgUserDir_EXECUTABLE)
execute_process(COMMAND ${XdgUserDir_EXECUTABLE} DESKTOP
OUTPUT_VARIABLE _output
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(_desktop_install_path "${_output}")
else()
message(STATUS "xdg-user-dir not found, using $HOME environment variable.")
set(_desktop_install_path "$ENV{HOME}")
endif()

# Install desktop shortcut.
if(_desktop_install_path)
message(STATUS "Installation path of desktop shortcut: ${_desktop_install_path}.")

install(PROGRAMS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_filename}.install
DESTINATION "${_desktop_install_path}"
RENAME ${_filename})
else()
message(STATUS "Not installing desktop shortcut.")
endif()
endfunction()
9 changes: 9 additions & 0 deletions cmake/templates/robotDevastation.desktop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Name=robotDevastation
Type=Application
MimeType=application/vnd.ms-htmlhelp;
Exec=gnome-terminal --maximize -e ${DESKTOP_SHORTCUT_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/robotDevastation
NoDisplay=true
StartupNotify=true
Icon=${DESKTOP_SHORTCUT_INSTALL_PREFIX}/${RD_CONTEXTS_INSTALL_DIR}/images/rd-icon-64x64.png
Path=
9 changes: 0 additions & 9 deletions scripts/gnome/robotDevastation.desktop

This file was deleted.

0 comments on commit 714d755

Please sign in to comment.