From c035d97286707f6f5de10789e1dd8a7ca3e5f8e5 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 30 Sep 2014 01:43:43 -0700 Subject: [PATCH] Make libPNG/zlib optional dependencies --- CMakeLists.txt | 10 +++++++--- src/gba/gba-serialize.c | 32 +++++++++++++++++++++----------- src/gba/gba-thread.c | 2 ++ src/gba/gba-thread.h | 2 ++ src/util/png-io.c | 4 ++++ src/util/png-io.h | 4 ++++ 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff71d11a5..e65be553c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra -std=gnu99") set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger") set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger") set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support") +set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support") set(BUILD_SDL ON CACHE BOOL "Build SDL frontend") set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool") file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c) @@ -107,9 +108,12 @@ if(USE_FFMPEG) list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVUTIL_LIBRARIES}) endif() -find_package(PNG REQUIRED) -find_package(ZLIB REQUIRED) -list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) +if(USE_PNG) + find_package(PNG REQUIRED) + find_package(ZLIB REQUIRED) + add_definitions(-DUSE_PNG) + list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) +endif() add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC}) target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB}) diff --git a/src/gba/gba-serialize.c b/src/gba/gba-serialize.c index c9c81899a..903ed5459 100644 --- a/src/gba/gba-serialize.c +++ b/src/gba/gba-serialize.c @@ -7,12 +7,15 @@ #include "gba-video.h" #include "util/memory.h" -#include "util/png-io.h" #include "util/vfs.h" #include + +#ifdef USE_PNG +#include "util/png-io.h" #include #include +#endif const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000; @@ -113,6 +116,7 @@ static struct VFile* _getStateVf(struct GBA* gba, struct VDir* dir, int slot, bo return vf; } +#ifdef USE_PNG static bool _savePNGState(struct GBA* gba, struct VFile* vf) { unsigned stride; void* pixels = 0; @@ -168,6 +172,7 @@ static bool _loadPNGState(struct GBA* gba, struct VFile* vf) { GBASyncPostFrame(gba->sync); return true; } +#endif bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot) { struct VFile* vf = _getStateVf(gba, dir, slot, true); @@ -198,23 +203,28 @@ bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, bool screenshot) { } GBASerialize(gba, state); vf->unmap(vf, state, sizeof(struct GBASerializedState)); - } else { + return true; + } + #ifdef USE_PNG + else { return _savePNGState(gba, vf); } - return true; + #endif + return false; } bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf) { - if (!isPNG(vf)) { - struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); - if (!state) { - return false; - } - GBADeserialize(gba, state); - vf->unmap(vf, state, sizeof(struct GBASerializedState)); - } else { + #ifdef USE_PNG + if (isPNG(vf)) { return _loadPNGState(gba, vf); } + #endif + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); + if (!state) { + return false; + } + GBADeserialize(gba, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); return true; } diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index d1ca8c9ba..243b3eb57 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -520,6 +520,7 @@ struct GBAThread* GBAThreadGetContext(void) { } #endif +#ifdef USE_PNG void GBAThreadTakeScreenshot(struct GBAThread* threadContext) { unsigned stride; void* pixels = 0; @@ -531,6 +532,7 @@ void GBAThreadTakeScreenshot(struct GBAThread* threadContext) { PNGWriteClose(png, info); vf->close(vf); } +#endif void GBASyncPostFrame(struct GBASync* sync) { if (!sync) { diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 8f09fc940..b6de84fbd 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -112,7 +112,9 @@ void GBAThreadTogglePause(struct GBAThread* threadContext); void GBAThreadPauseFromThread(struct GBAThread* threadContext); struct GBAThread* GBAThreadGetContext(void); +#ifdef USE_PNG void GBAThreadTakeScreenshot(struct GBAThread* threadContext); +#endif void GBASyncPostFrame(struct GBASync* sync); bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip); diff --git a/src/util/png-io.c b/src/util/png-io.c index 5d90daabb..93a9530fe 100644 --- a/src/util/png-io.c +++ b/src/util/png-io.c @@ -1,5 +1,7 @@ #include "util/png-io.h" +#ifdef USE_PNG + #include "vfs.h" static void _pngWrite(png_structp png, png_bytep buffer, png_size_t size) { @@ -177,3 +179,5 @@ bool PNGReadFooter(png_structp png, png_infop end) { void PNGReadClose(png_structp png, png_infop info, png_infop end) { png_destroy_read_struct(&png, &info, &end); } + +#endif diff --git a/src/util/png-io.h b/src/util/png-io.h index 257368090..81aca92d7 100644 --- a/src/util/png-io.h +++ b/src/util/png-io.h @@ -3,6 +3,8 @@ #include "common.h" +#ifdef USE_PNG + #include struct VFile; @@ -29,3 +31,5 @@ bool PNGReadFooter(png_structp png, png_infop end); void PNGReadClose(png_structp png, png_infop info, png_infop end); #endif + +#endif