From c38cbf330af8e9b17b4a376feeee65e8afd0e002 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Tue, 26 Dec 2023 17:34:09 -0500 Subject: [PATCH] misc: rework cmake and project layout --- .github/workflows/libserum.yml | 202 ++++++++++++++------- CMakeLists.txt | 160 +++++++++------- README.md | 63 ++++++- src/serum-decode.cpp | 30 +-- src/serum-decode.h | 41 ++--- src/serum-version.h | 2 +- src/test.cpp | 37 ++++ {src => third-party/include}/miniz/miniz.c | 0 {src => third-party/include}/miniz/miniz.h | 0 9 files changed, 361 insertions(+), 174 deletions(-) create mode 100644 src/test.cpp rename {src => third-party/include}/miniz/miniz.c (100%) rename {src => third-party/include}/miniz/miniz.h (100%) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 7020fea..bfc9875 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -1,7 +1,6 @@ name: libserum on: push: - pull_request: defaults: @@ -15,7 +14,7 @@ jobs: outputs: tag: ${{ steps.version.outputs.tag }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - id: version @@ -28,7 +27,7 @@ jobs: echo "tag=${TAG}" >> $GITHUB_OUTPUT build: - name: Build libserum-${{ matrix.platform }} + name: Build libserum-${{ matrix.platform }}-${{ matrix.arch }} runs-on: ${{ matrix.os }} needs: [ version ] strategy: @@ -36,90 +35,152 @@ jobs: matrix: include: - os: windows-latest - platform: win-x64 - platform-name: x64 + platform: win + arch: x64 - os: windows-latest - platform: win-x86 - platform-name: Win32 - - os: macos-latest - platform: macOS-x64 - - os: macos-latest - platform: macOS-arm64 + platform: win + arch: x86 - os: macos-latest - platform: ios-arm64 + platform: macos + arch: arm64 - os: macos-latest - platform: tvos-arm64 + platform: macos + arch: x64 - os: ubuntu-latest - platform: linux-x64 + platform: linux + arch: x64 - os: ubuntu-latest - platform: android-arm64-v8a + platform: linux + arch: aarch64 + - os: ubuntu-latest + platform: android + arch: arm64-v8a + - os: macos-latest + platform: ios + arch: arm64 + - os: macos-latest + platform: tvos + arch: arm64 steps: - - uses: actions/checkout@v3 - - name: Build libserum-${{ matrix.platform }} + - uses: actions/checkout@v4 + - if: (!(matrix.platform == 'linux' && matrix.arch == 'aarch64')) + name: Build libserum-${{ matrix.platform }}-${{ matrix.arch }} run: | - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - if [[ "${{ matrix.platform-name }}" == "Win32" ]]; then - cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build -DUSE_WIN32=ON - else - cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build - fi - cmake --build build --config Release - elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then - if [[ "${{ matrix.platform }}" == "macOS-arm64" ]]; then - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_OSXARM=ON - elif [[ "${{ matrix.platform }}" == "macOS-x64" ]]; then - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_OSXINTEL=ON - elif [[ "${{ matrix.platform }}" == "ios-arm64" ]]; then - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_IOS=ON - elif [[ "${{ matrix.platform }}" == "tvos-arm64" ]]; then - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_TVOS=ON - fi - cmake --build build/Release - elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - if [[ "${{ matrix.platform }}" == "android-arm64-v8a" ]]; then - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_ANDROID=ON - else - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release - fi - cmake --build build/Release + if [[ "${{ matrix.platform }}" == "win" ]]; then + if [[ "${{ matrix.arch }}" == "x86" ]]; then + cmake -G "Visual Studio 17 2022" -A Win32 -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -B build + else + cmake -G "Visual Studio 17 2022" -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -B build + fi + cmake --build build --config Release + else + if [[ "$(uname)" == "Darwin" ]]; then + NUM_PROCS=$(sysctl -n hw.ncpu) + else + NUM_PROCS=$(nproc) + fi + cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -B build + cmake --build build -- -j${NUM_PROCS} fi - - run: | + - if: (matrix.platform == 'linux' && matrix.arch == 'aarch64') + name: Build libserum-${{ matrix.platform }}-${{ matrix.arch }} (arm runner) + uses: pguyot/arm-runner-action@v2 + with: + base_image: raspios_lite_arm64:latest + image_additional_mb: 4096 + cpu: cortex-a53 + cpu_info: cpuinfo/raspberrypi_zero2_w_arm64 + bind_mount_repository: true + commands: | + apt-get update -y --allow-releaseinfo-change + apt-get install --no-install-recommends -y pkg-config cmake + NUM_PROCS=$(nproc) + cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -B build + cmake --build build -- -j${NUM_PROCS} + - name: Prepare artifacts + id: artifacts + run: | mkdir tmp - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - cp build/Release/serum* tmp + if [[ "${{ matrix.platform }}" == "win" ]]; then + ARTIFACT_PATH="tmp" + if [[ "${{ matrix.arch }}" == "x86" ]]; then + cp build/Release/serum.lib tmp + cp build/Release/serum.dll tmp + else + cp build/Release/serum64.lib tmp + cp build/Release/serum64.dll tmp + fi + cp build/Release/serum_static.lib tmp + cp build/Release/serum_test_s.exe tmp + cp build/Release/serum_test.exe tmp else - cp build/Release/libserum* tmp + ARTIFACT_PATH="libserum-${{ needs.version.outputs.tag }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz" + if [[ "${{ matrix.platform }}" == "macos" ]]; then + cp build/libserum.a tmp + cp build/libserum.*.dylib tmp + cp build/serum_test_s tmp + cp build/serum_test tmp + elif [[ "${{ matrix.platform }}" == "linux" ]]; then + cp build/libserum.a tmp + cp build/libserum.so.* tmp + cp build/serum_test_s tmp + cp build/serum_test tmp + elif [[ "${{ matrix.platform }}" == "ios" || "${{ matrix.platform }}" == "tvos" ]]; then + cp build/libserum.a tmp + cp build/libserum.*.dylib tmp + elif [[ "${{ matrix.platform }}" == "android" ]]; then + cp build/libserum.a tmp + cp build/libserum.so tmp + fi + cd tmp + tar -czvf ../${ARTIFACT_PATH} * fi - - uses: actions/upload-artifact@v3 + echo "artifact_path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT + - name: Upload artifacts + uses: actions/upload-artifact@v3 with: - name: libserum-${{ needs.version.outputs.tag }}-${{ matrix.platform }} - path: tmp + name: libserum-${{ needs.version.outputs.tag }}-${{ matrix.platform }}-${{ matrix.arch }} + path: ${{ steps.artifacts.outputs.artifact_path }} post-build: runs-on: macos-latest needs: [ version, build ] - name: Build libserum-macOS + name: Build libserum-macos steps: - uses: actions/download-artifact@v3 - - run: | - mkdir libserum-${{ needs.version.outputs.tag }}-macOS - lipo -create -output libserum-${{ needs.version.outputs.tag }}-macOS/libserum.dylib \ - libserum-${{ needs.version.outputs.tag }}-macOS-x64/libserum.dylib \ - libserum-${{ needs.version.outputs.tag }}-macOS-arm64/libserum.dylib - - uses: actions/upload-artifact@v3 + - name: Unpack artifacts + run: | + cd libserum-${{ needs.version.outputs.tag }}-macos-x64 + tar -xzvf libserum-${{ needs.version.outputs.tag }}-macos-x64.tar.gz + cd .. + cd libserum-${{ needs.version.outputs.tag }}-macos-arm64 + tar -xzvf libserum-${{ needs.version.outputs.tag }}-macos-arm64.tar.gz + - name: Combine macos architectures + run: | + mkdir tmp + lipo -create -output tmp/libserum-${{ needs.version.outputs.tag }}.dylib \ + libserum-${{ needs.version.outputs.tag }}-macos-arm64/libserum.${{ needs.version.outputs.tag }}.dylib \ + libserum-${{ needs.version.outputs.tag }}-macos-x64/libserum.${{ needs.version.outputs.tag }}.dylib + lipo -create -output tmp/serum_test \ + libserum-${{ needs.version.outputs.tag }}-macos-arm64/serum_test \ + libserum-${{ needs.version.outputs.tag }}-macos-x64/serum_test + lipo -create -output tmp/serum_test_s \ + libserum-${{ needs.version.outputs.tag }}-macos-arm64/serum_test_s \ + libserum-${{ needs.version.outputs.tag }}-macos-x64/serum_test_s + - name: Prepare artifacts + run: | + cd tmp + tar -czvf ../libserum-${{ needs.version.outputs.tag }}-macos.tar.gz * + - name: Upload artifacts + uses: actions/upload-artifact@v3 with: - name: libserum-${{ needs.version.outputs.tag }}-macOS - path: libserum-${{ needs.version.outputs.tag }}-macOS + name: libserum-${{ needs.version.outputs.tag }}-macos + path: libserum-${{ needs.version.outputs.tag }}-macos.tar.gz - name: Package if: startsWith(github.ref, 'refs/tags/') run: | zip -r libserum-${{ needs.version.outputs.tag }}-win-x64.zip libserum-${{ needs.version.outputs.tag }}-win-x64 - zip -r libserum-${{ needs.version.outputs.tag }}-win-x86.zip libserum-${{ needs.version.outputs.tag }}-win-x86 - zip -r libserum-${{ needs.version.outputs.tag }}-ios-arm64.zip libserum-${{ needs.version.outputs.tag }}-ios-arm64 - zip -r libserum-${{ needs.version.outputs.tag }}-tvos-arm64.zip libserum-${{ needs.version.outputs.tag }}-tvos-arm64 - zip -r libserum-${{ needs.version.outputs.tag }}-linux-x64.zip libserum-${{ needs.version.outputs.tag }}-linux-x64 - zip -r libserum-${{ needs.version.outputs.tag }}-android-arm64-v8a.zip libserum-${{ needs.version.outputs.tag }}-android-arm64-v8a - zip -r libserum-${{ needs.version.outputs.tag }}-macOS.zip libserum-${{ needs.version.outputs.tag }}-macOS + zip -r libserum-${{ needs.version.outputs.tag }}-win-x86.zip libserum-${{ needs.version.outputs.tag }}-win-x86 - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') @@ -128,8 +189,11 @@ jobs: files: | libserum-${{ needs.version.outputs.tag }}-win-x64.zip libserum-${{ needs.version.outputs.tag }}-win-x86.zip - libserum-${{ needs.version.outputs.tag }}-ios-arm64.zip - libserum-${{ needs.version.outputs.tag }}-tvos-arm64.zip - libserum-${{ needs.version.outputs.tag }}-linux-x64.zip - libserum-${{ needs.version.outputs.tag }}-android-arm64-v8a.zip - libserum-${{ needs.version.outputs.tag }}-macOS.zip + libserum-${{ needs.version.outputs.tag }}-macos-arm64/libserum-${{ needs.version.outputs.tag }}-macos-arm64.tar.gz + libserum-${{ needs.version.outputs.tag }}-macos-x64/libserum-${{ needs.version.outputs.tag }}-macos-x64.tar.gz + libserum-${{ needs.version.outputs.tag }}-macos.tar.gz + libserum-${{ needs.version.outputs.tag }}-linux-x64/libserum-${{ needs.version.outputs.tag }}-linux-x64.tar.gz + libserum-${{ needs.version.outputs.tag }}-linux-aarch64/libserum-${{ needs.version.outputs.tag }}-linux-aarch64.tar.gz + libserum-${{ needs.version.outputs.tag }}-ios-arm64/libserum-${{ needs.version.outputs.tag }}-ios-arm64.tar.gz + libserum-${{ needs.version.outputs.tag }}-tvos-arm64/libserum-${{ needs.version.outputs.tag }}-tvos-arm64.tar.gz + libserum-${{ needs.version.outputs.tag }}-android-arm64-v8a/libserum-${{ needs.version.outputs.tag }}-android-arm64-v8a.tar.gz \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9caeac0..b55be73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,22 @@ -cmake_minimum_required(VERSION 3.18) +cmake_minimum_required(VERSION 3.25) -option(USE_OSXARM "macOS arm64" OFF) -option(USE_OSXINTEL "macOS x86_64" OFF) -option(USE_IOS "ios" OFF) -option(USE_TVOS "tvos" OFF) -option(USE_ANDROID "android" OFF) -option(USE_WIN32 "Win32" OFF) +set(PLATFORM "win" CACHE STRING "Platform") +set(ARCH "x64" CACHE STRING "Arch") -if(USE_IOS) +option(BUILD_SHARED "Option to build shared library" ON) +option(BUILD_STATIC "Option to build static library" ON) + +message(STATUS "PLATFORM: ${PLATFORM}") +message(STATUS "ARCH: ${ARCH}") + +message(STATUS "BUILD_SHARED: ${BUILD_SHARED}") +message(STATUS "BUILD_STATIC: ${BUILD_STATIC}") + +if(PLATFORM STREQUAL "ios") set(CMAKE_SYSTEM_NAME iOS) -elseif(USE_TVOS) +elseif(PLATFORM STREQUAL "tvos") set(CMAKE_SYSTEM_NAME tvOS) -elseif(USE_ANDROID) +elseif(PLATFORM STREQUAL "android") set(CMAKE_SYSTEM_NAME Android) set(CMAKE_SYSTEM_VERSION 30) set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) @@ -26,71 +31,102 @@ string(REGEX MATCH "SERUM_VERSION_PATCH[ ]+([0-9]+)" _tmp ${version}) set(VERSION_PATCH "${CMAKE_MATCH_1}") project(serum VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" - DESCRIPTION "Cross-platform library for decoding Serum files, a colorization format for pinball ROMs.") + DESCRIPTION "Cross-platform library for decoding Serum files, a colorization format for pinball ROMs.") -set(LIB_NAME "serum") -if(USE_OSXARM) +if(PLATFORM STREQUAL "win") + if(ARCH STREQUAL "x86") + add_compile_definitions(WIN32) + endif() +elseif(PLATFORM STREQUAL "macos") + set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0) + if (ARCH STREQUAL "arm64") + set(CMAKE_OSX_ARCHITECTURES arm64) + elseif(ARCH STREQUAL "x64") + set(CMAKE_OSX_ARCHITECTURES x86_64) + endif() + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + set(CMAKE_INSTALL_RPATH "@executable_path") +elseif(PLATFORM STREQUAL "ios" OR PLATFORM STREQUAL "tvos") + set(CMAKE_OSX_DEPLOYMENT_TARGET 16.0) set(CMAKE_OSX_ARCHITECTURES arm64) -elseif(USE_OSXINTEL) - set(CMAKE_OSX_ARCHITECTURES x86_64) -elseif(USE_IOS OR USE_TVOS) - set(CMAKE_OSX_DEPLOYMENT_TARGET 16.0) - set(CMAKE_OSX_ARCHITECTURES arm64) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(CMAKE_C_FLAGS -fembed-bitcode) - set(CMAKE_CXX_FLAGS -fembed-bitcode) -elseif(USE_WIN32) - add_compile_definitions(WIN32) -elseif(USE_ANDROID) -else() - set(LIB_NAME "serum64") +elseif(PLATFORM STREQUAL "linux" OR PLATFORM STREQUAL "android") + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + set(CMAKE_INSTALL_RPATH "$ORIGIN") endif() set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_STANDARD 99) -set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_C_VISIBILITY_PRESET hidden) -set(LIBRARY_SOURCES - src/miniz/miniz.h - src/miniz/miniz.c +set(SERUM_SOURCES src/serum-decode.h src/serum-decode.cpp + third-party/include/miniz/miniz.h + third-party/include/miniz/miniz.c ) -set(INCLUDE_DIRS +set(SERUM_INCLUDE_DIRS src + third-party/include ) -include_directories(AFTER src) - -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - if(NOT USE_IOS AND NOT USE_TVOS) - add_library(serum_shared SHARED ${LIBRARY_SOURCES}) - set_target_properties(serum_shared PROPERTIES - OUTPUT_NAME ${LIB_NAME} - VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} - LINK_FLAGS_RELEASE -s - ) - target_include_directories(serum_shared PUBLIC ${INCLUDE_DIRS}) - install(TARGETS serum_shared - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - ) - endif() - - - if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - add_library(serum_static STATIC ${LIBRARY_SOURCES}) - set_target_properties(serum_static PROPERTIES OUTPUT_NAME "serum") - target_include_directories(serum_static PUBLIC ${INCLUDE_DIRS}) - install(TARGETS serum_static - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - ) - install(FILES src/serum-decode.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) - endif() - -else() - include_directories(AFTER src) - add_library(Serum ${LIBRARY_SOURCES}) +if(BUILD_SHARED) + add_library(serum_shared SHARED ${SERUM_SOURCES}) + + target_include_directories(serum_shared PUBLIC ${SERUM_INCLUDE_DIRS}) + + if(PLATFORM STREQUAL "win" AND ARCH STREQUAL "x64") + set(SERUM_OUTPUT_NAME "serum64") + else() + set(SERUM_OUTPUT_NAME "serum") + endif() + + set_target_properties(serum_shared PROPERTIES + OUTPUT_NAME ${SERUM_OUTPUT_NAME} + VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} + ) + + install(TARGETS serum_shared + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib + ) + install(FILES src/serum-decode.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) + + if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux") + add_executable(serum_test + src/test.cpp + ) + + target_link_libraries(serum_test PUBLIC serum_shared) + endif() +endif() + +if(BUILD_STATIC) + add_library(serum_static STATIC ${SERUM_SOURCES}) + + target_include_directories(serum_static PUBLIC ${SERUM_INCLUDE_DIRS}) + + if(PLATFORM STREQUAL "win") + set_target_properties(serum_static PROPERTIES + OUTPUT_NAME "serum_static" + ) + else() + set_target_properties(serum_static PROPERTIES + OUTPUT_NAME "serum" + ) + endif() + + install(TARGETS serum_static + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib + ) + install(FILES src/serum-decode.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) + + if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux") + add_executable(serum_test_s + src/test.cpp + ) + + target_link_libraries(serum_test_s PUBLIC serum_static) + endif() endif() diff --git a/README.md b/README.md index 8412258..9e3568f 100644 --- a/README.md +++ b/README.md @@ -35,19 +35,72 @@ Any code, device or whatever linked to libserum or using the file format it defi If you find issues within libserum or have ideas for enhancements, we encourage you to contribute to libserum by creating PRs (GitHub Pull Requests) instead of maintaining your own copy. Due to complicated dependency management on different platforms, these libraries are included as source code copy: -* [miniz-cpp](https://github.com/tfussell/miniz-cpp) by Thomas Fussel +* [miniz](https://github.com/richgel999/miniz) ## Compiling -#### Linux or macOS +#### Windows (x64) +Use Visual Studio. + +or + ```shell -cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -cmake --build build/Release +cmake -G "Visual Studio 17 2022" -DPLATFORM=win -DARCH=x64 -B build +cmake --build build --config Release ``` -#### Windows +#### Windows (x86) Use Visual Studio. +or + +```shell +cmake -G "Visual Studio 17 2022" -A Win32 -DPLATFORM=win -DARCH=x86 -B build +cmake --build build --config Release +``` + +#### Linux (x64) +```shell +cmake -DPLATFORM=linux -DARCH=x64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### Linux (aarch64) +```shell +cmake -DPLATFORM=linux -DARCH=aarch64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### MacOS (arm64) +```shell +cmake -DPLATFORM=macos -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### MacOS (x64) +```shell +cmake -DPLATFORM=macos -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### iOS (arm64) +```shell +cmake -DPLATFORM=ios -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### tvOS (arm64) +```shell +cmake -DPLATFORM=tvos -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + +#### Android (arm64-v8a) +```shell +cmake -DPLATFORM=android -DARCH=arm64-v8a -DCMAKE_BUILD_TYPE=Release -B build +cmake --build build +``` + #### For C# code If you want to include Serum colorization in your C# project, declare things this way: diff --git a/src/serum-decode.cpp b/src/serum-decode.cpp index 726d08b..27826d7 100644 --- a/src/serum-decode.cpp +++ b/src/serum-decode.cpp @@ -241,12 +241,12 @@ void Serum_free(void) cromloaded = false; } -SERUM_API(const char*) Serum_GetVersion() +SERUM_API const char* Serum_GetVersion() { return SERUM_VERSION; } -SERUM_API(const char*) Serum_GetMinorVersion() +SERUM_API const char* Serum_GetMinorVersion() { return SERUM_MINOR_VERSION; } @@ -345,7 +345,7 @@ void Reset_ColorRotations(void) for (int ti = 1; ti < MAX_COLOR_ROTATIONS; ti++) colorshiftinittime[ti] = colorshiftinittime[0]; } -SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers) +SERUM_API bool Serum_LoadFile(const char* const filename, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers) { char pathbuf[pathbuflen]; @@ -528,7 +528,7 @@ SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* phe return true; } -SERUM_API(bool) Serum_Load(const char* const altcolorpath, const char* const romname, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers) +SERUM_API bool Serum_Load(const char* const altcolorpath, const char* const romname, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers) { char pathbuf[pathbuflen]; if (strcpy_s(pathbuf, pathbuflen, altcolorpath) || @@ -545,7 +545,7 @@ SERUM_API(bool) Serum_Load(const char* const altcolorpath, const char* const rom return Serum_LoadFile(pathbuf, pwidth, pheight, pnocolors, pntriggers); } -SERUM_API(void) Serum_Dispose(void) +SERUM_API void Serum_Dispose(void) { Serum_free(); } @@ -761,17 +761,17 @@ void Copy_Frame_Palette(int nofr, UINT8* dpal) memcpy(dpal, &cpal[nofr * 64 * 3], 64 * 3); } -SERUM_API(void) Serum_SetIgnoreUnknownFramesTimeout(UINT16 milliseconds) +SERUM_API void Serum_SetIgnoreUnknownFramesTimeout(UINT16 milliseconds) { ignoreUnknownFramesTimeout = milliseconds; } -SERUM_API(void) Serum_SetMaximumUnknownFramesToSkip(UINT8 maximum) +SERUM_API void Serum_SetMaximumUnknownFramesToSkip(UINT8 maximum) { maxFramesToSkip = maximum; } -SERUM_API(void) Serum_SetStandardPalette(const UINT8* palette, const int bitDepth) +SERUM_API void Serum_SetStandardPalette(const UINT8* palette, const int bitDepth) { int palette_length = (1 << bitDepth)*3; assert(palette_length < PALETTE_SIZE); @@ -782,7 +782,7 @@ SERUM_API(void) Serum_SetStandardPalette(const UINT8* palette, const int bitDept } } -SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID) +SERUM_API bool Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID) { if (triggerID) { @@ -883,14 +883,14 @@ SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, return false; // no new frame, return false, client has to update rotations! } -SERUM_API(bool) Serum_Colorize(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32 *triggerID) +SERUM_API bool Serum_Colorize(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32 *triggerID) { UINT32 hashcode; int32_t frameID; return Serum_ColorizeWithMetadata(frame, width, height, palette, rotations, triggerID, &hashcode, &frameID); } -SERUM_API(bool) Serum_ApplyRotations(UINT8* palette, UINT8* rotations) +SERUM_API bool Serum_ApplyRotations(UINT8* palette, UINT8* rotations) { bool isrotation = false; UINT32 now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); @@ -918,7 +918,7 @@ SERUM_API(bool) Serum_ApplyRotations(UINT8* palette, UINT8* rotations) return isrotation; } -SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID) +SERUM_API bool Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID) { bool new_frame = Serum_ColorizeWithMetadata(frame, width, height, palette, rotations, triggerID, hashcode, frameID); if (!new_frame) { @@ -927,7 +927,7 @@ SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int wid return new_frame; } -SERUM_API(bool) Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT32 *triggerID) +SERUM_API bool Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT32 *triggerID) { if (frame) { @@ -949,12 +949,12 @@ SERUM_API(bool) Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int heig return false; } -SERUM_API(void) Serum_DisableColorization() +SERUM_API void Serum_DisableColorization() { enabled = false; } -SERUM_API(void) Serum_EnableColorization() +SERUM_API void Serum_EnableColorization() { enabled = true; } diff --git a/src/serum-decode.h b/src/serum-decode.h index 29a57d4..2b33193 100644 --- a/src/serum-decode.h +++ b/src/serum-decode.h @@ -1,10 +1,9 @@ -#ifndef SERUM_DECODE_H -#define SERUM_DECODE_H +#pragma once -#if defined _WIN32 -#define SERUM_API(RetType) extern "C" __declspec(dllexport) RetType +#ifdef _MSC_VER +#define SERUM_API extern "C" __declspec(dllexport) #else -#define SERUM_API(RetType) extern "C" RetType __attribute__((visibility("default"))) +#define SERUM_API extern "C" __attribute__((visibility("default"))) #endif #define MIN(a,b) ((a) < (b) ? (a) : (b)) @@ -25,20 +24,18 @@ const int ROTATION_SIZE = 3 * MAX_COLOR_ROTATIONS; // size of a color rotation b const int MAX_SPRITE_TO_DETECT = 16; // max number of sprites detected in a frame const int MAX_BACKGROUND_IMAGES = 255; // max number of background images -SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers); -SERUM_API(bool) Serum_Load(const char* const altcolorpath, const char* const romname, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers); -SERUM_API(void) Serum_SetIgnoreUnknownFramesTimeout(UINT16 milliseconds); -SERUM_API(void) Serum_SetMaximumUnknownFramesToSkip(UINT8 maximum); -SERUM_API(void) Serum_SetStandardPalette(const UINT8* palette, const int bitDepth); -SERUM_API(void) Serum_Dispose(void); -SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID); -SERUM_API(bool) Serum_Colorize(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID); -SERUM_API(bool) Serum_ApplyRotations(UINT8* palette, UINT8* rotations); -SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID); -SERUM_API(bool) Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT32* triggerID); -SERUM_API(void) Serum_DisableColorization(void); -SERUM_API(void) Serum_EnableColorization(void); -SERUM_API(const char*) Serum_GetVersion(void); -SERUM_API(const char*) Serum_GetMinorVersion(void); - -#endif +SERUM_API bool Serum_LoadFile(const char* const filename, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers); +SERUM_API bool Serum_Load(const char* const altcolorpath, const char* const romname, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers); +SERUM_API void Serum_SetIgnoreUnknownFramesTimeout(UINT16 milliseconds); +SERUM_API void Serum_SetMaximumUnknownFramesToSkip(UINT8 maximum); +SERUM_API void Serum_SetStandardPalette(const UINT8* palette, const int bitDepth); +SERUM_API void Serum_Dispose(void); +SERUM_API bool Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID); +SERUM_API bool Serum_Colorize(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID); +SERUM_API bool Serum_ApplyRotations(UINT8* palette, UINT8* rotations); +SERUM_API bool Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID); +SERUM_API bool Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT32* triggerID); +SERUM_API void Serum_DisableColorization(void); +SERUM_API void Serum_EnableColorization(void); +SERUM_API const char* Serum_GetVersion(void); +SERUM_API const char* Serum_GetMinorVersion(void); \ No newline at end of file diff --git a/src/serum-version.h b/src/serum-version.h index c772cf7..08ceae7 100644 --- a/src/serum-version.h +++ b/src/serum-version.h @@ -2,7 +2,7 @@ #define SERUM_VERSION_MAJOR 1 // X Digits #define SERUM_VERSION_MINOR 6 // Max 2 Digits -#define SERUM_VERSION_PATCH 1 // Max 2 Digits +#define SERUM_VERSION_PATCH 2 // Max 2 Digits #define _SERUM_STR(x) #x #define SERUM_STR(x) _SERUM_STR(x) diff --git a/src/test.cpp b/src/test.cpp new file mode 100644 index 0000000..0401c71 --- /dev/null +++ b/src/test.cpp @@ -0,0 +1,37 @@ +#include "serum-decode.h" + +#include + +int main(int argc, const char* argv[]) +{ + int width; + int height; + + unsigned int numColors; + unsigned int numTriggers; + + if (argc < 3) { + std::cout << "Usage: " << argv[0] << " [path] [rom]" << std::endl; + + return 1; + } + + const char* path = argv[1]; + const char* rom = argv[2]; + + if (!Serum_Load(path, rom, &width, &height, &numColors, &numTriggers)) { + std::cout << "Failed to load Serum: path=" << path << ", rom=" << rom << std::endl; + + Serum_Dispose(); + + return 1; + } + + std::cout << "Serum successfully loaded: path=" << path << ", rom=" << rom + << ", width=" << width << ", height=" << height + << ", numColors=" << numColors << ", numTriggers=" << numTriggers << std::endl; + + Serum_Dispose(); + + return 0; +} \ No newline at end of file diff --git a/src/miniz/miniz.c b/third-party/include/miniz/miniz.c similarity index 100% rename from src/miniz/miniz.c rename to third-party/include/miniz/miniz.c diff --git a/src/miniz/miniz.h b/third-party/include/miniz/miniz.h similarity index 100% rename from src/miniz/miniz.h rename to third-party/include/miniz/miniz.h