Skip to content

Commit

Permalink
[smpeg2] Cleanup, fix build, export config (microsoft#32807)
Browse files Browse the repository at this point in the history
* [smpeg2] Fix non-msvc-build

* Update CI baseline

* [smpeg2] Cleanup, cmake config

* Update copyright

* Fix config
  • Loading branch information
dg0yt authored Aug 1, 2023
1 parent 6de3d0c commit 0895a81
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 277 deletions.
17 changes: 0 additions & 17 deletions ports/smpeg2/001-correct-sdl-headers-dir.patch

This file was deleted.

229 changes: 0 additions & 229 deletions ports/smpeg2/002-use-SDL2-headers.patch

This file was deleted.

38 changes: 22 additions & 16 deletions ports/smpeg2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
cmake_minimum_required(VERSION 2.6)
project(SMPEG2 CXX)
cmake_minimum_required(VERSION 3.25)
project(smpeg2 CXX)

find_path(SDL_INCLUDE_DIR SDL2/SDL.h)
find_package(SDL2 CONFIG REQUIRED)

include_directories(${SDL_INCLUDE_DIR})
include_directories(${SDL_INCLUDE_DIR}/SDL2)
include_directories(${CMAKE_SOURCE_DIR})

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# some c++ code just assumes memset is available
add_definitions(-FIstring.h)
endif()
add_definitions(-DNOCONTROLS -DTHREADED_AUDIO)

# some c++ code just assumes memset is available
file(WRITE ${CMAKE_SOURCE_DIR}/declare_memset.h "#include <string.h>\n")
add_definitions(-FIdeclare_memset.h)

add_library(smpeg2
audio/bitwindow.cpp
audio/filter.cpp
Expand Down Expand Up @@ -45,21 +38,34 @@ add_library(smpeg2
MPEGsystem.cpp
smpeg.cpp)

set_target_properties(smpeg2 PROPERTIES DEFINE_SYMBOL DLL_EXPORT)
if(BUILD_SHARED_LIBS)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(smpeg2 PRIVATE -DDLL_EXPORT)
endif()

target_include_directories(smpeg2 PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
$<INSTALL_INTERFACE:include>
)


if(TARGET SDL2::SDL2)
target_link_libraries(smpeg2 SDL2::SDL2)
else()
target_link_libraries(smpeg2 SDL2::SDL2-static)
endif()

install(TARGETS smpeg2
EXPORT smpeg2-targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

install(EXPORT smpeg2-targets
FILE unofficial-smpeg2-config.cmake
NAMESPACE unofficial::smpeg2::
DESTINATION share/unofficial-smpeg2
)

if(NOT DEFINED SMPEG_SKIP_HEADERS)
install(FILES smpeg.h MPEGframe.h DESTINATION include)
endif()

message(STATUS "Link-time dependencies:")
message(STATUS " " ${SDL_LIBRARY})
27 changes: 27 additions & 0 deletions ports/smpeg2/hufftable-uint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/audio/hufftable.cpp b/audio/hufftable.cpp
index 6bc8e86..1ef2d7e 100644
--- a/audio/hufftable.cpp
+++ b/audio/hufftable.cpp
@@ -550,11 +550,11 @@ htd33[ 31][2]={{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 1},

const HUFFMANCODETABLE MPEGaudio::ht[HTN]=
{
- { 0, 0-1, 0-1, 0, 0, htd33},
+ { 0, 0u-1, 0u-1, 0, 0, htd33},
{ 1, 2-1, 2-1, 0, 7,htd01},
{ 2, 3-1, 3-1, 0, 17,htd02},
{ 3, 3-1, 3-1, 0, 17,htd03},
- { 4, 0-1, 0-1, 0, 0, htd33},
+ { 4, 0u-1, 0u-1, 0, 0, htd33},
{ 5, 4-1, 4-1, 0, 31,htd05},
{ 6, 4-1, 4-1, 0, 31,htd06},
{ 7, 6-1, 6-1, 0, 71,htd07},
@@ -564,7 +564,7 @@ const HUFFMANCODETABLE MPEGaudio::ht[HTN]=
{11, 8-1, 8-1, 0,127,htd11},
{12, 8-1, 8-1, 0,127,htd12},
{13,16-1,16-1, 0,511,htd13},
- {14, 0-1, 0-1, 0, 0, htd33},
+ {14, 0u-1, 0u-1, 0, 0, htd33},
{15,16-1,16-1, 0,511,htd15},
{16,16-1,16-1, 1,511,htd16},
{17,16-1,16-1, 2,511,htd16},
27 changes: 18 additions & 9 deletions ports/smpeg2/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

set(VERSION 2.0.0)
vcpkg_download_distfile(ARCHIVE
URLS "https://www.libsdl.org/projects/smpeg/release/smpeg2-${VERSION}.tar.gz"
FILENAME "smpeg2-${VERSION}.tar.gz"
Expand All @@ -9,21 +7,32 @@ vcpkg_download_distfile(ARCHIVE
vcpkg_extract_source_archive(
SOURCE_PATH
ARCHIVE "${ARCHIVE}"
SOURCE_BASE "${VERSION}"
PATCHES
"001-correct-sdl-headers-dir.patch"
"002-use-SDL2-headers.patch"
"003-fix-double-ptr-to-int-comparison.patch"
hufftable-uint.patch
003-fix-double-ptr-to-int-comparison.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS_DEBUG
-DSMPEG_SKIP_HEADERS=ON)

-DSMPEG_SKIP_HEADERS=ON
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()

file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-smpeg2)
file(READ "${CURRENT_PACKAGES_DIR}/share/unofficial-smpeg2/unofficial-smpeg2-config.cmake" config)
file(WRITE "${CURRENT_PACKAGES_DIR}/share/unofficial-smpeg2/unofficial-smpeg2-config.cmake"
"include(CMakeFindDependencyMacro)
find_dependency(SDL2 CONFIG)
${config}"
)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

file(READ "${SOURCE_PATH}/video/video.h" video_terms)
string(REGEX REPLACE "#ifndef .*" "" video_terms "${video_terms}")
file(WRITE "${SOURCE_PATH}/Additional notes" "${video_terms}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING" "${SOURCE_PATH}/Additional notes")
Loading

0 comments on commit 0895a81

Please sign in to comment.