diff options
author | Patric Stout <truebrain@openttd.org> | 2019-04-07 11:51:19 +0200 |
---|---|---|
committer | glx22 <glx22@users.noreply.github.com> | 2020-06-05 19:36:05 +0200 |
commit | 85315e2e3132dd7aff9ee96c1ba8d282350d9d5e (patch) | |
tree | 9c582e49a1d054e10e5d1b6e21e27d6c3ff747e7 /cmake/scripts/Baseset.cmake | |
parent | 203a77c1dc722df677302e84c6d5c0d4cb06d8ee (diff) | |
download | openttd-85315e2e3132dd7aff9ee96c1ba8d282350d9d5e.tar.xz |
Codechange: rework how grf and ob[msg] are generated
For grfs, it now uses CMake scripts to do its job, and both grf
files are split into their own folder to make more clear what is
going on. Additionally, it no longer builds in-source (although the
resulting grf is copied back in the source folder).
For ob[msg] it now uses CMake scripts to generate the translation
files; the result is no longer stored in-source (but in the build
folder).
Although all files are available to create the GRFs and basesets, it
won't really work till CMake is introduced (which will happen in a
few commits from here)
Diffstat (limited to 'cmake/scripts/Baseset.cmake')
-rw-r--r-- | cmake/scripts/Baseset.cmake | 53 |
1 files changed, 53 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}) |