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/CreateGRF.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/CreateGRF.cmake')
-rw-r--r-- | cmake/scripts/CreateGRF.cmake | 44 |
1 files changed, 44 insertions, 0 deletions
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}) |