diff --git a/CMake/Assets.cmake b/CMake/Assets.cmake index 38f604781..3650d46c9 100644 --- a/CMake/Assets.cmake +++ b/CMake/Assets.cmake @@ -1,3 +1,4 @@ +include(functions/copy_files) include(functions/trim_retired_files) if(NOT DEFINED DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY) @@ -235,18 +236,12 @@ else() # Copy assets to the build assets subdirectory. This serves two purposes: # - If smpq is installed, devilutionx.mpq is built from these files. # - If smpq is not installed, the game will load the assets directly from this directory. - foreach(asset_file ${devilutionx_assets}) - set(src "${CMAKE_CURRENT_SOURCE_DIR}/assets/${asset_file}") - set(dst "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/${asset_file}") - list(APPEND DEVILUTIONX_MPQ_FILES "${asset_file}") - list(APPEND DEVILUTIONX_OUTPUT_ASSETS_FILES "${dst}") - add_custom_command( - COMMENT "Copying ${asset_file}" - OUTPUT "${dst}" - DEPENDS "${src}" - COMMAND ${CMAKE_COMMAND} -E copy "${src}" "${dst}" - VERBATIM) - endforeach() + copy_files( + FILES ${devilutionx_assets} + SRC_PREFIX "assets/" + OUTPUT_DIR "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}" + OUTPUT_VARIABLE DEVILUTIONX_OUTPUT_ASSETS_FILES) + set(DEVILUTIONX_MPQ_FILES ${devilutionx_assets}) if (Gettext_FOUND) foreach(lang ${devilutionx_langs}) list(APPEND DEVILUTIONX_MPQ_FILES "${lang}.gmo") diff --git a/CMake/functions/copy_files.cmake b/CMake/functions/copy_files.cmake new file mode 100644 index 000000000..54764d8e8 --- /dev/null +++ b/CMake/functions/copy_files.cmake @@ -0,0 +1,38 @@ + +# copy_files( +# FILES +# OUTPUT_DIR +# [SRC_PREFIX ] +# [OUTPUT_VARIABLE ] +# ) +function(copy_files) + set(options) + set(oneValueArgs SRC_PREFIX OUTPUT_DIR OUTPUT_VARIABLE) + set(multiValueArgs FILES) + cmake_parse_arguments(PARSE_ARGV 0 arg + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ) + if(arg_UNPARSED_ARGUMENTS) + message(FATAL "unknown arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + if(OUTPUT_DIR IN_LIST arg_KEYWORDS_MISSING_VALUES) + message(FATAL "OUTPUT_DIR is required") + endif() + + foreach(path ${arg_FILES}) + set(src "${CMAKE_CURRENT_SOURCE_DIR}/${arg_SRC_PREFIX}${path}") + set(dst "${arg_OUTPUT_DIR}/${path}") + list(APPEND _out_paths "${dst}") + add_custom_command( + COMMENT "Copying ${arg_SRC_PREFIX}${path}" + OUTPUT "${dst}" + DEPENDS "${src}" + COMMAND ${CMAKE_COMMAND} -E copy "${src}" "${dst}" + VERBATIM + ) + endforeach() + if(arg_OUTPUT_VARIABLE) + set(${arg_OUTPUT_VARIABLE} ${_out_paths} PARENT_SCOPE) + endif() + +endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e490a0ac2..9bf66f131 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,5 @@ include(GoogleTest) +include(functions/copy_files) add_library(libdevilutionx_so SHARED) set_target_properties(libdevilutionx_so PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -148,6 +149,38 @@ if(DEVILUTIONX_SCREENSHOT_FORMAT STREQUAL DEVILUTIONX_SCREENSHOT_FORMAT_PNG AND libdevilutionx_surface_to_png libdevilutionx_text_render ) + copy_files( + FILES + basic-colors.png + basic.png + horizontal_overflow.png + horizontal_overflow-colors.png + kerning_fit_spacing-colors.png + kerning_fit_spacing.png + kerning_fit_spacing__align_center-colors.png + kerning_fit_spacing__align_center.png + kerning_fit_spacing__align_center__newlines.png + kerning_fit_spacing__align_center__newlines_in_fmt-colors.png + kerning_fit_spacing__align_center__newlines_in_value-colors.png + kerning_fit_spacing__align_right-colors.png + kerning_fit_spacing__align_right.png + vertical_overflow.png + vertical_overflow-colors.png + SRC_PREFIX fixtures/text_render_integration_test/ + OUTPUT_DIR "${DEVILUTIONX_TEST_FIXTURES_OUTPUT_DIRECTORY}/text_render_integration_test" + OUTPUT_VARIABLE _text_render_integration_test_fixtures + ) + add_custom_target(text_render_integration_test_resources + DEPENDS + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/fonts/12-00.clx" + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/fonts/goldui.trn" + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/fonts/golduis.trn" + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/fonts/grayuis.trn" + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/fonts/grayui.trn" + "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/ui_art/diablo.pal" + ${_text_render_integration_test_fixtures} + ) + add_dependencies(text_render_integration_test text_render_integration_test_resources) endif() target_link_dependencies(utf8_test PRIVATE libdevilutionx_utf8) diff --git a/test/Fixtures.cmake b/test/Fixtures.cmake index a03f699e4..a0a88e0e1 100644 --- a/test/Fixtures.cmake +++ b/test/Fixtures.cmake @@ -1,3 +1,5 @@ +include(functions/copy_files) + if(NOT DEFINED DEVILUTIONX_TEST_FIXTURES_OUTPUT_DIRECTORY) set(DEVILUTIONX_TEST_FIXTURES_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fixtures") endif() @@ -81,21 +83,6 @@ set(devilutionx_fixtures memory_map/player.txt memory_map/portal.txt memory_map/quest.txt - text_render_integration_test/basic-colors.png - text_render_integration_test/basic.png - text_render_integration_test/horizontal_overflow.png - text_render_integration_test/horizontal_overflow-colors.png - text_render_integration_test/kerning_fit_spacing-colors.png - text_render_integration_test/kerning_fit_spacing.png - text_render_integration_test/kerning_fit_spacing__align_center-colors.png - text_render_integration_test/kerning_fit_spacing__align_center.png - text_render_integration_test/kerning_fit_spacing__align_center__newlines.png - text_render_integration_test/kerning_fit_spacing__align_center__newlines_in_fmt-colors.png - text_render_integration_test/kerning_fit_spacing__align_center__newlines_in_value-colors.png - text_render_integration_test/kerning_fit_spacing__align_right-colors.png - text_render_integration_test/kerning_fit_spacing__align_right.png - text_render_integration_test/vertical_overflow.png - text_render_integration_test/vertical_overflow-colors.png timedemo/WarriorLevel1to2/demo_0.dmo timedemo/WarriorLevel1to2/demo_0_reference_spawn_0.sv timedemo/WarriorLevel1to2/spawn_0.sv @@ -109,17 +96,12 @@ set(devilutionx_fixtures txtdata/utf8_bom.tsv ) -foreach(fixture ${devilutionx_fixtures}) - set(src "${CMAKE_CURRENT_SOURCE_DIR}/fixtures/${fixture}") - set(dst "${DEVILUTIONX_TEST_FIXTURES_OUTPUT_DIRECTORY}/${fixture}") - list(APPEND DEVILUTIONX_OUTPUT_TEST_FIXTURES_FILES "${dst}") - add_custom_command( - COMMENT "Copying ${fixture}" - OUTPUT "${dst}" - DEPENDS "${src}" - COMMAND ${CMAKE_COMMAND} -E copy "${src}" "${dst}" - VERBATIM) -endforeach() +copy_files( + FILES ${devilutionx_fixtures} + SRC_PREFIX fixtures/ + OUTPUT_DIR "${DEVILUTIONX_TEST_FIXTURES_OUTPUT_DIRECTORY}" + OUTPUT_VARIABLE DEVILUTIONX_OUTPUT_TEST_FIXTURES_FILES +) add_custom_target(devilutionx_copied_fixtures DEPENDS ${DEVILUTIONX_OUTPUT_TEST_FIXTURES_FILES}) add_dependencies(test_main devilutionx_copied_fixtures)