mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-13 04:27:59 +01:00
38 lines
1.5 KiB
CMake
38 lines
1.5 KiB
CMake
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||
|
include(AssetCache)
|
||
|
|
||
|
find_program(CONVERT NAMES convert NO_CMAKE_FIND_ROOT_PATH)
|
||
|
if(CONVERT)
|
||
|
file(GLOB_RECURSE IMAGE_FILES RELATIVE ${DATADIR} ${DATADIR}/*.png ${DATADIR}/*.jpg ${DATADIR}/*.JPG ${DATADIR}/*.webp)
|
||
|
message(STATUS "ImgToWebp engaging... (using ${CONVERT})")
|
||
|
foreach(file IN LISTS IMAGE_FILES)
|
||
|
if (NOT file MATCHES "^icons/")
|
||
|
message(STATUS ${file})
|
||
|
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" filepath ${file})
|
||
|
if (RESIZE)
|
||
|
set(resizecmd -resize ${RESIZE})
|
||
|
else()
|
||
|
set(resizecmd "")
|
||
|
endif()
|
||
|
GetFromAssetCache(${CACHE} ${DATADIR}/${file} "${QUALITY}-${RESIZE}-${PARAMS}" CACHED HASH)
|
||
|
if (CACHED)
|
||
|
file(REMOVE ${DATADIR}/${file})
|
||
|
configure_file(${CACHED} ${DATADIR}/${filepath}.wbp COPYONLY)
|
||
|
unset(CACHED)
|
||
|
else()
|
||
|
separate_arguments(PARAMS)
|
||
|
set(CONVERT_CMD ${CONVERT} ${file} -quality ${QUALITY} ${PARAMS} ${resizecmd} webp:${filepath}.wbp)
|
||
|
execute_process(COMMAND ${CONVERT_CMD} WORKING_DIRECTORY ${DATADIR} RESULT_VARIABLE CONVERT_RESULT)
|
||
|
if(CONVERT_RESULT)
|
||
|
message(WARNING "ERROR: ${CONVERT_RESULT}")
|
||
|
else()
|
||
|
file(REMOVE ${DATADIR}/${file})
|
||
|
AddToAssetCache(${CACHE} ${HASH} "${QUALITY}-${RESIZE}-${PARAMS}" "${DATADIR}/${filepath}.wbp")
|
||
|
endif()
|
||
|
endif()
|
||
|
endif()
|
||
|
endforeach(file)
|
||
|
else(CONVERT)
|
||
|
message(WARNING "ImgToWebp: can't find convert!")
|
||
|
endif(CONVERT)
|