Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libchdr to latest upstream. #230

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
66 changes: 41 additions & 25 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,49 @@ INCFLAGS := -I$(CORE_DIR) \
-I$(MEDNAFEN_DIR)/hw_misc \
-I$(LIBRETRO_COMM_DIR)/include

LIBCHDR = deps/libchdr
LIBCHDR_LZMA = $(LIBCHDR)/deps/lzma-24.05
LIBCHDR_ZSTD = $(LIBCHDR)/deps/zstd-1.5.6/lib
LIBCHDR_INCFLAGS = \
-I$(DEPS_DIR)/lzma-19.00/include \
-I$(DEPS_DIR)/libchdr/include
-I$(LIBCHDR_LZMA)/include \
-I$(LIBCHDR_ZSTD) \
-I$(LIBCHDR)/include
LIBCHDR_SOURCES_C = \
$(DEPS_DIR)/lzma-19.00/src/Alloc.c \
$(DEPS_DIR)/lzma-19.00/src/Bra86.c \
$(DEPS_DIR)/lzma-19.00/src/BraIA64.c \
$(DEPS_DIR)/lzma-19.00/src/CpuArch.c \
$(DEPS_DIR)/lzma-19.00/src/Delta.c \
$(DEPS_DIR)/lzma-19.00/src/LzFind.c \
$(DEPS_DIR)/lzma-19.00/src/Lzma86Dec.c \
$(DEPS_DIR)/lzma-19.00/src/LzmaDec.c \
$(DEPS_DIR)/lzma-19.00/src/LzmaEnc.c \
$(DEPS_DIR)/libchdr/src/libchdr_bitstream.c \
$(DEPS_DIR)/libchdr/src/libchdr_cdrom.c \
$(DEPS_DIR)/libchdr/src/libchdr_chd.c \
$(DEPS_DIR)/libchdr/src/libchdr_flac.c \
$(DEPS_DIR)/libchdr/src/libchdr_huffman.c

ZLIB_INCFLAGS = -I$(DEPS_DIR)/zlib-1.2.11
$(LIBCHDR_LZMA)/src/Alloc.c \
$(LIBCHDR_LZMA)/src/Bra86.c \
$(LIBCHDR_LZMA)/src/BraIA64.c \
$(LIBCHDR_LZMA)/src/CpuArch.c \
$(LIBCHDR_LZMA)/src/Delta.c \
$(LIBCHDR_LZMA)/src/LzFind.c \
$(LIBCHDR_LZMA)/src/Lzma86Dec.c \
$(LIBCHDR_LZMA)/src/LzmaDec.c \
$(LIBCHDR_LZMA)/src/LzmaEnc.c \
$(LIBCHDR_LZMA)/src/Sort.c \
$(LIBCHDR)/src/libchdr_bitstream.c \
$(LIBCHDR)/src/libchdr_cdrom.c \
$(LIBCHDR)/src/libchdr_chd.c \
$(LIBCHDR)/src/libchdr_flac.c \
$(LIBCHDR)/src/libchdr_huffman.c \
$(LIBCHDR_ZSTD)/common/entropy_common.c \
$(LIBCHDR_ZSTD)/common/error_private.c \
$(LIBCHDR_ZSTD)/common/fse_decompress.c \
$(LIBCHDR_ZSTD)/common/xxhash.c \
$(LIBCHDR_ZSTD)/common/zstd_common.c \
$(LIBCHDR_ZSTD)/decompress/huf_decompress.c \
$(LIBCHDR_ZSTD)/decompress/huf_decompress_amd64.c \
$(LIBCHDR_ZSTD)/decompress/zstd_ddict.c \
$(LIBCHDR_ZSTD)/decompress/zstd_decompress_block.c \
$(LIBCHDR_ZSTD)/decompress/zstd_decompress.c

ZLIB_DIR = deps/libchdr/deps/zlib-1.3.1
ZLIB_INCFLAGS = -I$(ZLIB_DIR)
ZLIB_SOURCES_C = \
$(DEPS_DIR)/zlib-1.2.11/adler32.c \
$(DEPS_DIR)/zlib-1.2.11/crc32.c \
$(DEPS_DIR)/zlib-1.2.11/inffast.c \
$(DEPS_DIR)/zlib-1.2.11/inflate.c \
$(DEPS_DIR)/zlib-1.2.11/inftrees.c \
$(DEPS_DIR)/zlib-1.2.11/zutil.c
$(ZLIB_DIR)/adler32.c \
$(ZLIB_DIR)/crc32.c \
$(ZLIB_DIR)/inffast.c \
$(ZLIB_DIR)/inflate.c \
$(ZLIB_DIR)/inftrees.c \
$(ZLIB_DIR)/zutil.c

ifneq (,$(findstring msvc2003,$(platform)))
INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc
Expand Down Expand Up @@ -115,7 +131,7 @@ endif
FLAGS += -DNEED_CD

ifeq ($(HAVE_CHD), 1)
FLAGS += -DHAVE_CHD -D_7ZIP_ST
FLAGS += -DHAVE_CHD -DZ7_ST

ifeq ($(SYSTEM_LIBCHDR), 1)
INCFLAGS += $(shell pkg-config --cflags libchdr)
Expand Down
34 changes: 34 additions & 0 deletions deps/libchdr/.github/workflows/bsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: BSD

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
operating_system: [ freebsd, netbsd, openbsd ]
architecture: [ arm64, x86-64 ]
include:
- operating_system: freebsd
version: '14.0'
pkginstall: sudo pkg install -y cmake git ninja pkgconf
- operating_system: netbsd
version: '10.0'
pkginstall: sudo pkgin update && sudo pkgin -y install cmake gcc12 git ninja-build pkgconf && export PATH=/usr/pkg/gcc12/bin:$PATH
- operating_system: openbsd
version: '7.5'
pkginstall: sudo pkg_add cmake git ninja pkgconf

steps:
- uses: actions/checkout@v4

- uses: cross-platform-actions/[email protected]
with:
operating_system: ${{ matrix.operating_system }}
architecture: ${{ matrix.architecture }}
version: ${{ matrix.version }}
run: |
${{ matrix.pkginstall }}
cmake -B build -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build build --config Release
19 changes: 19 additions & 0 deletions deps/libchdr/.github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CMake

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release
17 changes: 17 additions & 0 deletions deps/libchdr/.github/workflows/switch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Nintendo Switch

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
container: devkitpro/devkita64:latest

steps:
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${DEVKITPRO}/cmake/Switch.cmake

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release
17 changes: 17 additions & 0 deletions deps/libchdr/.github/workflows/vita.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: PlayStation Vita

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
container: vitasdk/vitasdk:latest

steps:
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release
3 changes: 3 additions & 0 deletions deps/libchdr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.d
build/
116 changes: 53 additions & 63 deletions deps/libchdr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,51 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.9)

project(chdr C)
project(chdr VERSION 0.2 LANGUAGES C)

set(CHDR_VERSION_MAJOR 0)
set(CHDR_VERSION_MINOR 1)

option(BUILD_SHARED_LIBS "Build libchdr also as a shared library" ON)
option(WITH_SYSTEM_ZLIB "Use system provided zlib library" OFF)

if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC -O3 -flto")
endif()

include(FindPkgConfig)

if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
if (NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR "include")
if(CMAKE_PROJECT_NAME STREQUAL "chdr")
option(BUILD_SHARED_LIBS "Build libchdr also as a shared library" ON)
endif()
option(INSTALL_STATIC_LIBS "Install static libraries" OFF)
option(WITH_SYSTEM_ZLIB "Use system provided zlib library" OFF)

# Detect processor type.
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
set(CPU_ARCH "x64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
# MSVC x86/x64
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPU_ARCH "x64")
else()
set(CPU_ARCH "x86")
option(BUILD_LTO "Compile libchdr with link-time optimization if supported" OFF)
if(BUILD_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT HAVE_IPO)
if(HAVE_IPO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(CPU_ARCH "x86")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(CPU_ARCH "aarch64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
set(CPU_ARCH "arm")
else()
message(FATAL_ERROR "Unknown system processor: " ${CMAKE_SYSTEM_PROCESSOR})
endif()

include(GNUInstallDirs)

#--------------------------------------------------
# dependencies
#--------------------------------------------------


# lzma
add_subdirectory(deps/lzma-19.00 EXCLUDE_FROM_ALL)
add_subdirectory(deps/lzma-24.05 EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS lzma)
list(APPEND CHDR_INCLUDES lzma)

# zlib
if (WITH_SYSTEM_ZLIB)
pkg_check_modules(ZLIB REQUIRED zlib)
list(APPEND PLATFORM_INCLUDES ${ZLIB_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBS ${ZLIB_LIBRARIES})
find_package(ZLIB REQUIRED)
list(APPEND PLATFORM_LIBS ZLIB::ZLIB)
else()
add_subdirectory(deps/zlib-1.2.11 EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS zlib)
list(APPEND CHDR_INCLUDES zlib)
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
add_subdirectory(deps/zlib-1.3.1 EXCLUDE_FROM_ALL)
set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON)
list(APPEND CHDR_LIBS zlibstatic)
endif()

# zstd
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
add_subdirectory(deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS libzstd_static)
#--------------------------------------------------
# chdr
#--------------------------------------------------
Expand All @@ -78,34 +58,43 @@ set(CHDR_SOURCES
src/libchdr_huffman.c
)

list(APPEND CHDR_INCLUDES include ${CMAKE_CURRENT_BINARY_DIR}/include)
list(APPEND CHDR_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/include)

add_library(chdr-static STATIC ${CHDR_SOURCES})
target_include_directories(chdr-static PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES})
target_compile_definitions(chdr-static PRIVATE ${CHDR_DEFS})
target_link_libraries(chdr-static ${CHDR_LIBS} ${PLATFORM_LIBS})
target_include_directories(chdr-static PRIVATE ${CHDR_INCLUDES} PUBLIC include)
target_link_libraries(chdr-static PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})

if (BUILD_SHARED_LIBS)
set(LIBS ${PLATFORM_LIBS})
list(TRANSFORM LIBS PREPEND "-l")
list(JOIN LIBS " " LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
if(MSVC)
target_compile_definitions(chdr-static PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

if (INSTALL_STATIC_LIBS)
install(TARGETS chdr-static ${CHDR_LIBS}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()

if (BUILD_SHARED_LIBS)
add_library(chdr SHARED ${CHDR_SOURCES})
target_include_directories(chdr PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES})
target_compile_definitions(chdr PRIVATE ${CHDR_DEFS})
target_link_libraries(chdr ${CHDR_LIBS} ${PLATFORM_LIBS})
target_include_directories(chdr PRIVATE ${CHDR_INCLUDES} PUBLIC include)
target_link_libraries(chdr PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})

if(MSVC)
target_compile_definitions(chdr PUBLIC "CHD_DLL")
target_compile_definitions(chdr PRIVATE "CHD_DLL_EXPORTS")
target_compile_definitions(chdr PRIVATE _CRT_SECURE_NO_WARNINGS)
elseif(APPLE)
target_link_libraries(chdr PRIVATE -Wl,-dead_strip -Wl,-exported_symbol,_chd_*)
elseif(CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
target_link_libraries(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T)
else()
target_link_options(chdr PRIVATE -Wl,--version-script ${CMAKE_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
target_link_libraries(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
endif()

set_target_properties(chdr PROPERTIES PUBLIC_HEADER "include/libchdr/bitstream.h;include/libchdr/cdrom.h;include/libchdr/chd.h;include/libchdr/coretypes.h;include/libchdr/flac.h;include/libchdr/huffman.h")
set_target_properties(chdr PROPERTIES VERSION "${CHDR_VERSION_MAJOR}.${CHDR_VERSION_MINOR}")
set_target_properties(chdr PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(chdr PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
set_target_properties(chdr PROPERTIES PUBLIC_HEADER "include/libchdr/bitstream.h;include/libchdr/cdrom.h;include/libchdr/chd.h;include/libchdr/chdconfig.h;include/libchdr/coretypes.h;include/libchdr/flac.h;include/libchdr/huffman.h")
set_target_properties(chdr PROPERTIES VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" SOVERSION ${PROJECT_VERSION_MAJOR})

if (CMAKE_BUILD_TYPE MATCHES Release)
#add_custom_command(TARGET chdr POST_BUILD COMMAND ${CMAKE_STRIP} libchdr.so)
Expand All @@ -121,3 +110,4 @@ if (BUILD_SHARED_LIBS)
install(FILES ${CMAKE_BINARY_DIR}/libchdr.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

add_subdirectory(tests)
Loading