diff options
author | glx22 <glx@openttd.org> | 2021-03-09 18:00:37 +0100 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-03-09 22:42:25 +0100 |
commit | 35a228f78f5b64f57e93ce8d108cec98d805b469 (patch) | |
tree | 694535c3673a923a3c2481f81b53fb9b134a1028 /cmake | |
parent | b5770acd50215744b5f9649b1ba4386be4b452c5 (diff) | |
download | openttd-35a228f78f5b64f57e93ce8d108cec98d805b469.tar.xz |
Add: [CMake] Install menu and media files
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/InstallAndPackage.cmake | 14 | ||||
-rw-r--r-- | cmake/scripts/Desktop.cmake | 60 |
2 files changed, 72 insertions, 2 deletions
diff --git a/cmake/InstallAndPackage.cmake b/cmake/InstallAndPackage.cmake index 5fd17cb03..0b1dc1493 100644 --- a/cmake/InstallAndPackage.cmake +++ b/cmake/InstallAndPackage.cmake @@ -58,8 +58,18 @@ if(OPTION_INSTALL_FHS) COMPONENT manual) endif() -# TODO -- Media files -# TODO -- Menu files +if(UNIX AND NOT APPLE) + install(DIRECTORY + ${CMAKE_BINARY_DIR}/media/icons + ${CMAKE_BINARY_DIR}/media/pixmaps + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} + COMPONENT media) + + install(FILES + ${CMAKE_BINARY_DIR}/media/${BINARY_NAME}.desktop + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications + COMPONENT menu) +endif() if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(ARCHITECTURE "amd64") diff --git a/cmake/scripts/Desktop.cmake b/cmake/scripts/Desktop.cmake new file mode 100644 index 000000000..7cec0b9af --- /dev/null +++ b/cmake/scripts/Desktop.cmake @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.5) + +# +# Create a desktop file with the correct translations. +# + +if(NOT DESKTOP_SOURCE_FILE) + message(FATAL_ERROR "Script needs DESKTOP_SOURCE_FILE defined") +endif() +if(NOT DESKTOP_BINARY_FILE) + message(FATAL_ERROR "Script needs DESKTOP_BINARY_FILE defined") +endif() +if(NOT BINARY_NAME) + message(FATAL_ERROR "Script needs BINARY_NAME defined") +endif() + +set(ARGC 1) +set(ARG_READ NO) + +# Read all the arguments given to CMake; we are looking for -- and everything +# that follows. Those are our language files. +while(ARGC LESS CMAKE_ARGC) + set(ARG ${CMAKE_ARGV${ARGC}}) + + if(ARG_READ) + list(APPEND LANG_SOURCE_FILES "${ARG}") + endif() + + if(ARG STREQUAL "--") + set(ARG_READ YES) + endif() + + math(EXPR ARGC "${ARGC} + 1") +endwhile() + +# Place holder format is @<ini_key>_<str_id>@ +file(STRINGS "${DESKTOP_SOURCE_FILE}" PLACE_HOLDER REGEX "^@") +string(REGEX REPLACE "@([^_]+).*@" "\\1" INI_KEY "${PLACE_HOLDER}") +string(REGEX REPLACE "@[^_]+_(.*)@" "\\1" STR_ID "${PLACE_HOLDER}") +string(REGEX REPLACE "@(.*)@" "\\1" PLACE_HOLDER "${PLACE_HOLDER}") + +# Get the translations +foreach(LANGFILE IN LISTS LANG_SOURCE_FILES) + file(STRINGS "${LANGFILE}" LANGLINES REGEX "^(##isocode|${STR_ID})" ENCODING UTF-8) + string(FIND "${LANGLINES}" "${STR_ID}" HAS_STR_ID) + if(HAS_STR_ID LESS 0) + continue() + endif() + string(REGEX REPLACE "##isocode ([^;]+).*" "\\1" ISOCODE "${LANGLINES}") + if("${ISOCODE}" STREQUAL "en_GB") + string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}=\\1" LANGLINES "${LANGLINES}") + else() + string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}[${ISOCODE}]=\\1" LANGLINES "${LANGLINES}") + endif() + list(APPEND ${PLACE_HOLDER} ${LANGLINES}) +endforeach() +list(SORT ${PLACE_HOLDER}) +string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}") + +configure_file(${DESKTOP_SOURCE_FILE} ${DESKTOP_BINARY_FILE}) |