summaryrefslogtreecommitdiff
path: root/cmake/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/scripts')
-rw-r--r--cmake/scripts/Baseset.cmake53
-rw-r--r--cmake/scripts/CreateGRF.cmake44
2 files changed, 97 insertions, 0 deletions
diff --git a/cmake/scripts/Baseset.cmake b/cmake/scripts/Baseset.cmake
new file mode 100644
index 000000000..4329dbdf8
--- /dev/null
+++ b/cmake/scripts/Baseset.cmake
@@ -0,0 +1,53 @@
+cmake_minimum_required(VERSION 3.5)
+
+#
+# Create a single baseset meta file with the correct translations.
+#
+
+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 (ARG_READ)
+
+ if (ARG STREQUAL "--")
+ set(ARG_READ YES)
+ endif (ARG STREQUAL "--")
+
+ math(EXPR ARGC "${ARGC} + 1")
+endwhile()
+
+# Place holder format is @<ini_key>_<str_id>@
+file(STRINGS "${BASESET_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 (HAS_STR_ID LESS 0)
+ 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(LANGFILE)
+list(SORT ${PLACE_HOLDER})
+string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}")
+
+# Get the grf md5
+file(MD5 ${BASESET_EXTRAGRF_FILE} ORIG_EXTRA_GRF_MD5)
+
+configure_file(${BASESET_SOURCE_FILE} ${BASESET_BINARY_FILE})
diff --git a/cmake/scripts/CreateGRF.cmake b/cmake/scripts/CreateGRF.cmake
new file mode 100644
index 000000000..f5811daf9
--- /dev/null
+++ b/cmake/scripts/CreateGRF.cmake
@@ -0,0 +1,44 @@
+cmake_minimum_required(VERSION 3.5)
+
+#
+# Create a single GRF file based on sprites/<grfname>.nfo and sprites/*.png
+# files.
+#
+
+if (NOT NFORENUM_EXECUTABLE)
+ message(FATAL_ERROR "Script needs NFORENUM_EXECUTABLE defined")
+endif (NOT NFORENUM_EXECUTABLE)
+if (NOT GRFCODEC_EXECUTABLE)
+ message(FATAL_ERROR "Script needs GRFCODEC_EXECUTABLE defined")
+endif (NOT GRFCODEC_EXECUTABLE)
+if (NOT GRF_SOURCE_FOLDER)
+ message(FATAL_ERROR "Script needs GRF_SOURCE_FOLDER defined")
+endif (NOT GRF_SOURCE_FOLDER)
+if (NOT GRF_BINARY_FILE)
+ message(FATAL_ERROR "Script needs GRF_BINARY_FILE defined")
+endif (NOT GRF_BINARY_FILE)
+
+get_filename_component(GRF_SOURCE_FOLDER_NAME "${GRF_SOURCE_FOLDER}" NAME)
+
+file(WRITE sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "")
+file(READ ${GRF_SOURCE_FOLDER}/${GRF_SOURCE_FOLDER_NAME}.nfo NFO_LINES)
+# Replace ; with \;, and make a list out of this based on \n
+string(REPLACE ";" "\\;" NFO_LINES "${NFO_LINES}")
+string(REPLACE "\n" ";" NFO_LINES "${NFO_LINES}")
+
+foreach(NFO_LINE IN LISTS NFO_LINES)
+ # Recover the ; that was really in the text (and not a newline)
+ string(REPLACE "\\;" ";" NFO_LINE "${NFO_LINE}")
+
+ if (NFO_LINE MATCHES "^#include")
+ string(REGEX REPLACE "^#include \"(.*)\"$" "\\1" INCLUDE_FILE ${NFO_LINE})
+ file(READ ${GRF_SOURCE_FOLDER}/${INCLUDE_FILE} INCLUDE_LINES)
+ file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${INCLUDE_LINES}")
+ else (NFO_LINE MATCHES "^#include")
+ file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${NFO_LINE}\n")
+ endif (NFO_LINE MATCHES "^#include")
+endforeach(NFO_LINE)
+
+execute_process(COMMAND ${NFORENUM_EXECUTABLE} -s sprites/${GRF_SOURCE_FOLDER_NAME}.nfo)
+execute_process(COMMAND ${GRFCODEC_EXECUTABLE} -n -s -e -p1 ${GRF_SOURCE_FOLDER_NAME}.grf)
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${GRF_SOURCE_FOLDER_NAME}.grf ${GRF_BINARY_FILE})