diff --git a/cmake/CreateGrfCommand.cmake b/cmake/CreateGrfCommand.cmake --- a/cmake/CreateGrfCommand.cmake +++ b/cmake/CreateGrfCommand.cmake @@ -28,12 +28,13 @@ function(create_grf_command) list(APPEND GRF_PNG_BINARY_FILES ${GRF_PNG_BINARY_FILE}) endforeach() - add_custom_command(OUTPUT ${GRF_BINARY_FILE} + add_custom_command(OUTPUT ${GRF_BINARY_FILE} ${GRF_BINARY_FILE}.hash COMMAND ${CMAKE_COMMAND} -DGRF_SOURCE_FOLDER=${CMAKE_CURRENT_SOURCE_DIR} -DGRF_BINARY_FILE=${GRF_BINARY_FILE} -DNFORENUM_EXECUTABLE=${NFORENUM_EXECUTABLE} -DGRFCODEC_EXECUTABLE=${GRFCODEC_EXECUTABLE} + -DGRFID_EXECUTABLE=${GRFID_EXECUTABLE} -P ${CMAKE_SOURCE_DIR}/cmake/scripts/CreateGRF.cmake MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/cmake/scripts/CreateGRF.cmake DEPENDS ${GRF_PNG_BINARY_FILES} diff --git a/cmake/FindGrfcodec.cmake b/cmake/FindGrfcodec.cmake --- a/cmake/FindGrfcodec.cmake +++ b/cmake/FindGrfcodec.cmake @@ -2,6 +2,7 @@ # find_program(GRFCODEC_EXECUTABLE grfcodec) +find_program(GRFID_EXECUTABLE grfid) find_program(NFORENUM_EXECUTABLE nforenum) include(FindPackageHandleStandardArgs) @@ -9,5 +10,6 @@ find_package_handle_standard_args(Grfcod FOUND_VAR GRFCODEC_FOUND REQUIRED_VARS GRFCODEC_EXECUTABLE + GRFID_EXECUTABLE NFORENUM_EXECUTABLE ) diff --git a/cmake/scripts/Baseset.cmake b/cmake/scripts/Baseset.cmake --- a/cmake/scripts/Baseset.cmake +++ b/cmake/scripts/Baseset.cmake @@ -58,6 +58,7 @@ list(SORT ${PLACE_HOLDER}) string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}") # Get the grf md5 -file(MD5 ${BASESET_EXTRAGRF_FILE} ORIG_EXTRA_GRF_MD5) +file(READ ${BASESET_EXTRAGRF_FILE}.hash ORIG_EXTRA_GRF_MD5) +string(STRIP ${ORIG_EXTRA_GRF_MD5} ORIG_EXTRA_GRF_MD5) configure_file(${BASESET_SOURCE_FILE} ${BASESET_BINARY_FILE}) diff --git a/cmake/scripts/CreateGRF.cmake b/cmake/scripts/CreateGRF.cmake --- a/cmake/scripts/CreateGRF.cmake +++ b/cmake/scripts/CreateGRF.cmake @@ -11,6 +11,9 @@ endif() if(NOT GRFCODEC_EXECUTABLE) message(FATAL_ERROR "Script needs GRFCODEC_EXECUTABLE defined") endif() +if(NOT GRFID_EXECUTABLE) + message(FATAL_ERROR "Script needs GRFID_EXECUTABLE defined") +endif() if(NOT GRF_SOURCE_FOLDER) message(FATAL_ERROR "Script needs GRF_SOURCE_FOLDER defined") endif() @@ -55,4 +58,15 @@ if(RESULT) message(FATAL_ERROR "GRFCodec failed") endif() +execute_process(COMMAND ${GRFID_EXECUTABLE} -m ${GRF_SOURCE_FOLDER_NAME}.grf OUTPUT_VARIABLE GRFID_HASH RESULT_VARIABLE RESULT) +if(RESULT) + if(NOT RESULT MATCHES "^[0-9]*$") + message(FATAL_ERROR "Failed to run GRFID (${RESULT}), please check GRFID_EXECUTABLE variable") + endif() + message(FATAL_ERROR "GRFID failed") +endif() + +file(WRITE ${GRF_BINARY_FILE}.hash ${GRFID_HASH}) + +# Copy build files back to the source directory. execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${GRF_SOURCE_FOLDER_NAME}.grf ${GRF_BINARY_FILE}) diff --git a/media/baseset/CMakeLists.txt b/media/baseset/CMakeLists.txt --- a/media/baseset/CMakeLists.txt +++ b/media/baseset/CMakeLists.txt @@ -49,6 +49,7 @@ foreach(BASESET_SOURCE_FILE IN LISTS BAS MAIN_DEPENDENCY ${BASESET_SOURCE_FILE} DEPENDS ${LANG_SOURCE_FILES} ${BASESET_EXTRAGRF_FILE} + ${BASESET_EXTRAGRF_FILE}.hash ${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating ${BASESET_SOURCE_FILE_NAME} baseset metadata file" diff --git a/media/baseset/openttd.grf.hash b/media/baseset/openttd.grf.hash new file mode 100644 --- /dev/null +++ b/media/baseset/openttd.grf.hash @@ -0,0 +1,1 @@ +237f3152daa7706aa30784ba72fb727a diff --git a/media/baseset/orig_extra.grf.hash b/media/baseset/orig_extra.grf.hash new file mode 100644 --- /dev/null +++ b/media/baseset/orig_extra.grf.hash @@ -0,0 +1,1 @@ +1fb8473f51d1c57c3bba4ae6cfca1cb2