cmake: rework asset compression pipeline a bit

This commit is contained in:
Sebastian Krzyszkowiak 2019-04-29 03:11:55 +02:00
parent ddfe7cc50a
commit c480289123
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
5 changed files with 151 additions and 94 deletions

View file

@ -2,7 +2,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(AssetCache) include(AssetCache)
find_program(OPUSENC NAMES opusenc NO_CMAKE_FIND_ROOT_PATH) find_program(OPUSENC NAMES opusenc NO_CMAKE_FIND_ROOT_PATH)
if(OPUSENC) if(OPUSENC AND DATADIR)
file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac) file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac)
message(STATUS "FlacToOpus engaging... (using ${OPUSENC})") message(STATUS "FlacToOpus engaging... (using ${OPUSENC})")
foreach(file IN LISTS FLAC_FILES) foreach(file IN LISTS FLAC_FILES)
@ -23,6 +23,10 @@ if(OPUSENC)
endif() endif()
endif() endif()
endforeach(file) endforeach(file)
else(OPUSENC) else(OPUSENC AND DATADIR)
message(WARNING "FlacToOpus: can't find opusenc!") if(NOT OPUSENC)
endif(OPUSENC) message(WARNING "FlacToOpus: can't find opusenc!")
else()
message(WARNING "FlacToOpus: no DATADIR specified!")
endif()
endif(OPUSENC AND DATADIR)

View file

@ -2,9 +2,9 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(AssetCache) include(AssetCache)
find_program(OGGENC NAMES oggenc NO_CMAKE_FIND_ROOT_PATH) find_program(OGGENC NAMES oggenc NO_CMAKE_FIND_ROOT_PATH)
if(OGGENC) if(OGGENC AND DATADIR)
file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac) file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac)
message(STATUS "FlacToOgg engaging... (using ${OGGENC})") message(STATUS "FlacToVorbis engaging... (using ${OGGENC})")
foreach(file IN LISTS FLAC_FILES) foreach(file IN LISTS FLAC_FILES)
message(STATUS ${file}) message(STATUS ${file})
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" filename ${file}) string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" filename ${file})
@ -23,6 +23,10 @@ if(OGGENC)
endif() endif()
endif() endif()
endforeach(file) endforeach(file)
else(OGGENC) else(OGGENC AND DATADIR)
message(WARNING "FlacToOgg: can't find oggenc!") if(NOT OGGENC)
endif(OGGENC) message(WARNING "FlacToVorbis: can't find oggenc!")
else()
message(WARNING "FlacToVorbis: no DATADIR specified!")
endif()
endif(OGGENC AND DATADIR)

View file

@ -2,7 +2,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(AssetCache) include(AssetCache)
find_program(CONVERT NAMES convert NO_CMAKE_FIND_ROOT_PATH) find_program(CONVERT NAMES convert NO_CMAKE_FIND_ROOT_PATH)
if(CONVERT) if(CONVERT AND DATADIR)
file(GLOB_RECURSE IMAGE_FILES RELATIVE ${DATADIR} ${DATADIR}/*.png ${DATADIR}/*.jpg ${DATADIR}/*.JPG ${DATADIR}/*.webp) file(GLOB_RECURSE IMAGE_FILES RELATIVE ${DATADIR} ${DATADIR}/*.png ${DATADIR}/*.jpg ${DATADIR}/*.JPG ${DATADIR}/*.webp)
message(STATUS "ImgToWebp engaging... (using ${CONVERT})") message(STATUS "ImgToWebp engaging... (using ${CONVERT})")
foreach(file IN LISTS IMAGE_FILES) foreach(file IN LISTS IMAGE_FILES)
@ -37,6 +37,10 @@ if(CONVERT)
endif() endif()
endif() endif()
endforeach(file) endforeach(file)
else(CONVERT) else(CONVERT AND DATADIR)
message(WARNING "ImgToWebp: can't find convert!") if(NOT CONVERT)
endif(CONVERT) message(WARNING "ImgToWebp: can't find convert!")
else()
message(WARNING "ImgToWebp: no DATADIR specified!")
endif()
endif(CONVERT AND DATADIR)

View file

@ -323,22 +323,55 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
set(LIBSUPERDERPY_APPID "net.dosowisko.${LIBSUPERDERPY_GAMENAME}") set(LIBSUPERDERPY_APPID "net.dosowisko.${LIBSUPERDERPY_GAMENAME}")
endif(NOT DEFINED LIBSUPERDERPY_APPID) endif(NOT DEFINED LIBSUPERDERPY_APPID)
if (ANDROID)
set(ASSET_PIPELINE_DATADIR "${CMAKE_BINARY_DIR}/android/app/src/main/assets/data")
set(ASSET_PIPELINE_DEPEND "")
else (EMSCRIPTEN)
set(ASSET_PIPELINE_DATADIR "${CMAKE_INSTALL_PREFIX}/share/${LIBSUPERDERPY_GAMENAME}/data")
set(ASSET_PIPELINE_DEPEND ${LIBSUPERDERPY_GAMENAME}_install)
endif()
set(FLACTOLOSSY_DEFAULT OFF)
set(FLACTOLOSSY_FORMAT_DEFAULT "Opus")
set(IMGTOWEBP_DEFAULT OFF)
if (ANDROID OR EMSCRIPTEN) if (ANDROID OR EMSCRIPTEN)
if (ANDROID) set(FLACTOLOSSY_DEFAULT ON)
set(ASSET_PIPELINE_DATADIR "${CMAKE_BINARY_DIR}/android/app/src/main/assets/data") set(IMGTOWEBP_DEFAULT ON)
set(ASSET_PIPELINE_DEPEND "") endif()
else (EMSCRIPTEN)
set(ASSET_PIPELINE_DATADIR "${CMAKE_INSTALL_PREFIX}/share/${LIBSUPERDERPY_GAMENAME}/data")
set(ASSET_PIPELINE_DEPEND ${LIBSUPERDERPY_GAMENAME}_install)
endif()
set(FLACTOOPUS_BITRATE "192" CACHE STRING "Bitrate of resulting Opus files (kbps)") if (MAEMO5)
set(FLACTOLOSSY_DEFAULT ON)
set(FLACTOLOSSY_FORMAT_DEFAULT "Vorbis")
endif()
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_opus if (ANDROID OR EMSCRIPTEN)
DEPENDS ${ASSET_PIPELINE_DEPEND} # restrict to Android or Emscripten for now, because only those platforms have ASSET_PIPELINE_DATADIR at this moment
COMMAND ${CMAKE_COMMAND} -DDATADIR=${ASSET_PIPELINE_DATADIR} -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DBITRATE=${FLACTOOPUS_BITRATE} -P ${LIBSUPERDERPY_DIR}/cmake/FlacToOpus.cmake
USES_TERMINAL)
option(FLACTOLOSSY "Compress FLAC audio assets to lossy format" ${FLACTOLOSSY_DEFAULT})
set(FLACTOLOSSY_BITRATE "192" CACHE STRING "Bitrate of resulting Vorbis/Opus files (kbps)")
set(FLACTOLOSSY_SAMPLERATE "48000" CACHE STRING "Sample rate of resulting Vorbis files (does not apply to Opus) (Hz)")
set(FLACTOLOSSY_FORMAT ${FLACTOLOSSY_FORMAT_DEFAULT} CACHE STRING "Lossy codec to use when encoding audio files")
set_property(CACHE FLACTOLOSSY_FORMAT PROPERTY STRINGS "Opus;Vorbis")
if (FLACTOLOSSY)
if (${FLACTOLOSSY_FORMAT} STREQUAL "Vorbis")
add_definitions(-DLIBSUPERDERPY_FLACTOLOSSY_EXT="ogg")
else()
add_definitions(-DLIBSUPERDERPY_FLACTOLOSSY_EXT="opus")
endif()
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_lossy
DEPENDS ${ASSET_PIPELINE_DEPEND}
COMMAND ${CMAKE_COMMAND} -DDATADIR=${ASSET_PIPELINE_DATADIR} -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DBITRATE=${FLACTOLOSSY_BITRATE} -DSAMPLERATE=${FLACTOLOSSY_SAMPLERATE} -P ${LIBSUPERDERPY_DIR}/cmake/FlacTo${FLACTOLOSSY_FORMAT}.cmake
USES_TERMINAL)
else(FLACTOLOSSY)
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_lossy
DEPENDS ${ASSET_PIPELINE_DEPEND})
endif(FLACTOLOSSY)
option(IMGTOWEBP "Compress image assets to WebP format" ${IMGTOWEBP_DEFAULT})
option(IMGTOWEBP_LOSSLESS "Use lossless WebP compression" OFF) option(IMGTOWEBP_LOSSLESS "Use lossless WebP compression" OFF)
if(IMGTOWEBP_LOSSLESS) if(IMGTOWEBP_LOSSLESS)
set(IMGTOWEBP_QUALITY "100" CACHE STRING "Quality of resulting WebP files") set(IMGTOWEBP_QUALITY "100" CACHE STRING "Quality of resulting WebP files")
@ -348,12 +381,18 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
set(IMGTOWEBP_RESIZE "" CACHE STRING "Value passed as -resize to ImageMagick (no resizing when empty)") set(IMGTOWEBP_RESIZE "" CACHE STRING "Value passed as -resize to ImageMagick (no resizing when empty)")
set(IMGTOWEBP_PARAMS "" CACHE STRING "Additional ImageMagick parameters") set(IMGTOWEBP_PARAMS "" CACHE STRING "Additional ImageMagick parameters")
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp if(IMGTOWEBP)
DEPENDS ${ASSET_PIPELINE_DEPEND} add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
COMMAND ${CMAKE_COMMAND} -DQUALITY="${IMGTOWEBP_QUALITY}" -DRESIZE="${IMGTOWEBP_RESIZE}" -DPARAMS="${IMGTOWEBP_PARAMS}" -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DLOSSLESS="${IMGTOWEBP_LOSSLESS}" -DDATADIR=${ASSET_PIPELINE_DATADIR} -P ${LIBSUPERDERPY_DIR}/cmake/ImgToWebp.cmake DEPENDS ${ASSET_PIPELINE_DEPEND}
USES_TERMINAL) COMMAND ${CMAKE_COMMAND} -DQUALITY="${IMGTOWEBP_QUALITY}" -DRESIZE="${IMGTOWEBP_RESIZE}" -DPARAMS="${IMGTOWEBP_PARAMS}" -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DLOSSLESS="${IMGTOWEBP_LOSSLESS}" -DDATADIR=${ASSET_PIPELINE_DATADIR} -P ${LIBSUPERDERPY_DIR}/cmake/ImgToWebp.cmake
USES_TERMINAL)
add_definitions(-DLIBSUPERDERPY_IMGTOWEBP)
else(IMGTOWEBP)
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
DEPENDS ${ASSET_PIPELINE_DEPEND})
endif(IMGTOWEBP)
endif(ANDROID OR EMSCRIPTEN) endif (ANDROID OR EMSCRIPTEN)
MACRO(add_libsuperderpy_target EXECUTABLE_SRC_LIST) MACRO(add_libsuperderpy_target EXECUTABLE_SRC_LIST)
if(ANDROID) if(ANDROID)
@ -363,7 +402,7 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
set(APK_PATH ${CMAKE_BINARY_DIR}/android/bin/${LIBSUPERDERPY_GAMENAME}-debug.apk) set(APK_PATH ${CMAKE_BINARY_DIR}/android/bin/${LIBSUPERDERPY_GAMENAME}-debug.apk)
add_custom_target(${LIBSUPERDERPY_GAMENAME}_apk ALL add_custom_target(${LIBSUPERDERPY_GAMENAME}_apk ALL
DEPENDS ${EXECUTABLE} ${LIBSUPERDERPY_GAMENAME}_flac_to_opus ${LIBSUPERDERPY_GAMENAME}_img_to_webp DEPENDS ${EXECUTABLE} ${LIBSUPERDERPY_GAMENAME}_flac_to_lossy ${LIBSUPERDERPY_GAMENAME}_img_to_webp
BYPRODUCTS ${APK_PATH} BYPRODUCTS ${APK_PATH}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/android" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/android"
COMMAND ./gradlew assembleDebug COMMAND ./gradlew assembleDebug
@ -406,7 +445,7 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
endif() endif()
add_custom_target(${LIBSUPERDERPY_GAMENAME}_js add_custom_target(${LIBSUPERDERPY_GAMENAME}_js
DEPENDS ${LIBSUPERDERPY_GAMENAME}_install ${LIBSUPERDERPY_GAMENAME}_flac_to_opus ${LIBSUPERDERPY_GAMENAME}_img_to_webp ${CMAKE_BINARY_DIR}/emscripten-imports.json DEPENDS ${LIBSUPERDERPY_GAMENAME}_install ${LIBSUPERDERPY_GAMENAME}_flac_to_lossy ${LIBSUPERDERPY_GAMENAME}_img_to_webp ${CMAKE_BINARY_DIR}/emscripten-imports.json
WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/${LIBSUPERDERPY_GAMENAME}" WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/${LIBSUPERDERPY_GAMENAME}"
COMMAND "${CMAKE_C_COMPILER}" ${CFLAGS_LIST} ../bin/${LIBSUPERDERPY_GAMENAME}${CMAKE_EXECUTABLE_SUFFIX} ../lib/libsuperderpy${CMAKE_SHARED_LIBRARY_SUFFIX} ../lib/lib${LIBSUPERDERPY_GAMENAME}${CMAKE_SHARED_LIBRARY_SUFFIX} ${ALLEGRO5_LIBS} ${EMSCRIPTEN_FLAGS} -o ${LIBSUPERDERPY_GAMENAME}.html --pre-js ${LIBSUPERDERPY_DIR}/src/emscripten-pre-js.js --preload-file ../share/${LIBSUPERDERPY_GAMENAME}/data --preload-file gamestates@/ COMMAND "${CMAKE_C_COMPILER}" ${CFLAGS_LIST} ../bin/${LIBSUPERDERPY_GAMENAME}${CMAKE_EXECUTABLE_SUFFIX} ../lib/libsuperderpy${CMAKE_SHARED_LIBRARY_SUFFIX} ../lib/lib${LIBSUPERDERPY_GAMENAME}${CMAKE_SHARED_LIBRARY_SUFFIX} ${ALLEGRO5_LIBS} ${EMSCRIPTEN_FLAGS} -o ${LIBSUPERDERPY_GAMENAME}.html --pre-js ${LIBSUPERDERPY_DIR}/src/emscripten-pre-js.js --preload-file ../share/${LIBSUPERDERPY_GAMENAME}/data --preload-file gamestates@/
USES_TERMINAL USES_TERMINAL

View file

@ -404,74 +404,80 @@ SYMBOL_EXPORT const char* FindDataFilePath(struct Game* game, const char* filena
} }
#endif #endif
#if (defined __EMSCRIPTEN__) || (defined ALLEGRO_ANDROID) #ifdef LIBSUPERDERPY_FLACTOLOSSY_EXT
char* file = AddGarbage(game, strdup(filename)); {
char* sub = strstr(file, ".flac"); char* file = AddGarbage(game, strdup(filename));
if (sub) { char* sub = strstr(file, ".flac");
sub[0] = '.'; if (sub) {
sub[1] = 'o'; sub[0] = '.';
sub[2] = 'p'; sub[1] = LIBSUPERDERPY_FLACTOLOSSY_EXT[0];
sub[3] = 'u'; sub[2] = LIBSUPERDERPY_FLACTOLOSSY_EXT[1];
sub[4] = 's'; sub[3] = LIBSUPERDERPY_FLACTOLOSSY_EXT[2];
sub[5] = 0; sub[4] = LIBSUPERDERPY_FLACTOLOSSY_EXT[3];
} sub[5] = 0;
result = TestDataFilePath(game, file); }
if (result) { result = TestDataFilePath(game, file);
return AddGarbage(game, result); if (result) {
return AddGarbage(game, result);
}
} }
#endif
sub = strstr(file, ".png"); #ifdef LIBSUPERDERPY_IMGTOWEBP
if (sub) { {
sub[0] = '.'; char* file = AddGarbage(game, strdup(filename));
sub[1] = 'w'; char* sub = strstr(file, ".png");
sub[2] = 'b'; if (sub) {
sub[3] = 'p'; sub[0] = '.';
sub[4] = 0; sub[1] = 'w';
} sub[2] = 'b';
result = TestDataFilePath(game, file); sub[3] = 'p';
if (result) { sub[4] = 0;
return AddGarbage(game, result); }
} result = TestDataFilePath(game, file);
if (result) {
return AddGarbage(game, result);
}
sub = strstr(file, ".jpg"); sub = strstr(file, ".jpg");
if (sub) { if (sub) {
sub[0] = '.'; sub[0] = '.';
sub[1] = 'w'; sub[1] = 'w';
sub[2] = 'b'; sub[2] = 'b';
sub[3] = 'p'; sub[3] = 'p';
sub[4] = 0; sub[4] = 0;
} }
result = TestDataFilePath(game, file); result = TestDataFilePath(game, file);
if (result) { if (result) {
return AddGarbage(game, result); return AddGarbage(game, result);
} }
sub = strstr(file, ".JPG"); sub = strstr(file, ".JPG");
if (sub) { if (sub) {
sub[0] = '.'; sub[0] = '.';
sub[1] = 'w'; sub[1] = 'w';
sub[2] = 'b'; sub[2] = 'b';
sub[3] = 'p'; sub[3] = 'p';
sub[4] = 0; sub[4] = 0;
} }
result = TestDataFilePath(game, file); result = TestDataFilePath(game, file);
if (result) { if (result) {
return AddGarbage(game, result); return AddGarbage(game, result);
} }
sub = strstr(file, ".webp"); sub = strstr(file, ".webp");
if (sub) { if (sub) {
sub[0] = '.'; sub[0] = '.';
sub[1] = 'w'; sub[1] = 'w';
sub[2] = 'b'; sub[2] = 'b';
sub[3] = 'p'; sub[3] = 'p';
sub[4] = 0; sub[4] = 0;
}
result = TestDataFilePath(game, file);
if (result) {
return AddGarbage(game, result);
}
} }
result = TestDataFilePath(game, file);
if (result) {
return AddGarbage(game, result);
}
#endif #endif
result = TestDataFilePath(game, filename); result = TestDataFilePath(game, filename);