Skip to content

Commit

Permalink
Build libogg and libvorbis with CMake
Browse files Browse the repository at this point in the history
- Update libogg to 1.3.5
  • Loading branch information
encelo committed Mar 4, 2024
1 parent 6b9f728 commit c38c029
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 23 deletions.
35 changes: 25 additions & 10 deletions cmake/ogg.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
set(TARGET_OGG ogg)
set(URL_OGG http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz)
set(URL_MD5_OGG 1eda7efc22a97d08af98265107d65f95)
set(TARGET_OGG_STATIC ogg_static)
set(URL_OGG http://downloads.xiph.org/releases/ogg/libogg-1.3.5.tar.gz)
set(URL_MD5_OGG 3267127fe8d7ba77d3e00cb9d7ad578d)
set(DEST_OGG ${DESTINATION_PATH}/ogg)
set(INCLUDE_DIR_OGG ${EP_BASE}/Source/project_${TARGET_OGG}/include)

ExternalProject_Add(project_${TARGET_OGG}
URL ${URL_OGG}
URL_MD5 ${URL_MD5_OGG}
CONFIGURE_COMMAND ./configure ${CONFIGURE_TOOLCHAIN_ARGS}
BUILD_COMMAND make -j${CPUS}
BUILD_IN_SOURCE 1
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_OGG}/src/.libs/libogg.so ${DEST_OGG}/${ARCH}/libogg.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_OGG}/src/.libs/libogg.a ${DEST_OGG}/${ARCH}/libogg.a
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/ogg/ogg.h ${DEST_OGG}/include/ogg/ogg.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/ogg/os_types.h ${DEST_OGG}/include/ogg/os_types.h
PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/patches/ogg.patch
CMAKE_ARGS ${CMAKE_TOOLCHAIN_ARGS} -DBUILD_SHARED_LIBS=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different libogg.so ${DEST_OGG}/${ARCH}/libogg.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INCLUDE_DIR_OGG}/ogg/ogg.h ${DEST_OGG}/include/ogg/ogg.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INCLUDE_DIR_OGG}/ogg/os_types.h ${DEST_OGG}/include/ogg/os_types.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/ogg/config_types.h ${DEST_OGG}/include/ogg/config_types.h
)

ExternalProject_Add(project_${TARGET_OGG_STATIC}
DEPENDS project_${TARGET_OGG}
DOWNLOAD_COMMAND ""
SOURCE_DIR ${EP_BASE}/Source/project_${TARGET_OGG}
CMAKE_ARGS ${CMAKE_TOOLCHAIN_ARGS} -DBUILD_SHARED_LIBS=OFF
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different libogg.a ${DEST_OGG}/${ARCH}/libogg.a
)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET project_${TARGET_OGG} POST_BUILD
COMMAND ${STRIP} ${STRIP_SHARED_ARGS} ${DEST_OGG}/${ARCH}/libogg.so
COMMENT "Stripping OGG shared library")

add_custom_command(TARGET project_${TARGET_OGG_STATIC} POST_BUILD
COMMAND ${STRIP} ${STRIP_STATIC_ARGS} ${DEST_OGG}/${ARCH}/libogg.a
COMMENT "Stripping OGG libraries")
COMMENT "Stripping OGG static library")
endif()
40 changes: 27 additions & 13 deletions cmake/vorbis.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,46 @@ if(NOT DEFINED TARGET_OGG)
endif()

set(TARGET_VORBIS vorbis)
set(TARGET_VORBIS_STATIC vorbis_static)
set(URL_VORBIS http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.gz)
set(URL_MD5_VORBIS 9b8034da6edc1a17d18b9bc4542015c7)

set(DEST_VORBIS ${DESTINATION_PATH}/vorbis)
set(INCLUDE_DIR_VORBIS ${EP_BASE}/Source/project_${TARGET_VORBIS}/include)

ExternalProject_Add(project_${TARGET_VORBIS}
DEPENDS project_${TARGET_OGG}
URL ${URL_VORBIS}
URL_MD5 ${URL_MD5_VORBIS}
CONFIGURE_COMMAND ./configure ${CONFIGURE_TOOLCHAIN_ARGS} OGG_LIBS=-L${DESTINATION_PATH}/ogg/${ARCH} OGG_CFLAGS=-I${EP_BASE}/Source/project_${TARGET_OGG}/include
BUILD_COMMAND make -j${CPUS}
BUILD_IN_SOURCE 1
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_VORBIS}/lib/.libs/libvorbis.so ${DEST_VORBIS}/${ARCH}/libvorbis.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_VORBIS}/lib/.libs/libvorbis.a ${DEST_VORBIS}/${ARCH}/libvorbis.a
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_VORBIS}/lib/.libs/libvorbisfile.so ${DEST_VORBIS}/${ARCH}/libvorbisfile.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EP_BASE}/Source/project_${TARGET_VORBIS}/lib/.libs/libvorbisfile.a ${DEST_VORBIS}/${ARCH}/libvorbisfile.a
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/vorbis/codec.h ${DEST_VORBIS}/include/vorbis/codec.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/vorbis/vorbisenc.h ${DEST_VORBIS}/include/vorbis/vorbisenc.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different include/vorbis/vorbisfile.h ${DEST_VORBIS}/include/vorbis/vorbisfile.h
PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/patches/vorbis.patch
CMAKE_ARGS ${CMAKE_TOOLCHAIN_ARGS} -DOGG_LIBRARY=${DESTINATION_PATH}/ogg/${ARCH}/libogg.so -DOGG_INCLUDE_DIR=${DEST_OGG}/include -DBUILD_SHARED_LIBS=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different lib/libvorbis.so ${DEST_VORBIS}/${ARCH}/libvorbis.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different lib/libvorbisfile.so ${DEST_VORBIS}/${ARCH}/libvorbisfile.so
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INCLUDE_DIR_VORBIS}/vorbis/codec.h ${DEST_VORBIS}/include/vorbis/codec.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INCLUDE_DIR_VORBIS}/vorbis/vorbisenc.h ${DEST_VORBIS}/include/vorbis/vorbisenc.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INCLUDE_DIR_VORBIS}/vorbis/vorbisfile.h ${DEST_VORBIS}/include/vorbis/vorbisfile.h
)

ExternalProject_Add(project_${TARGET_VORBIS_STATIC}
DEPENDS project_${TARGET_VORBIS}
DOWNLOAD_COMMAND ""
SOURCE_DIR ${EP_BASE}/Source/project_${TARGET_VORBIS}
CMAKE_ARGS ${CMAKE_TOOLCHAIN_ARGS} -DOGG_LIBRARY=${DESTINATION_PATH}/ogg/${ARCH}/libogg.a -DOGG_INCLUDE_DIR=${DEST_OGG}/include -DBUILD_SHARED_LIBS=OFF
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel
BUILD_IN_SOURCE 0
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different lib/libvorbis.a ${DEST_VORBIS}/${ARCH}/libvorbis.a
COMMAND ${CMAKE_COMMAND} -E copy_if_different lib/libvorbisfile.a ${DEST_VORBIS}/${ARCH}/libvorbisfile.a
)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET project_${TARGET_VORBIS} POST_BUILD
COMMAND ${STRIP} ${STRIP_SHARED_ARGS} ${DEST_VORBIS}/${ARCH}/libvorbis.so
COMMAND ${STRIP} ${STRIP_STATIC_ARGS} ${DEST_VORBIS}/${ARCH}/libvorbis.a
COMMAND ${STRIP} ${STRIP_SHARED_ARGS} ${DEST_VORBIS}/${ARCH}/libvorbisfile.so
COMMENT "Stripping Vorbis shared libraries")

add_custom_command(TARGET project_${TARGET_VORBIS_STATIC} POST_BUILD
COMMAND ${STRIP} ${STRIP_STATIC_ARGS} ${DEST_VORBIS}/${ARCH}/libvorbis.a
COMMAND ${STRIP} ${STRIP_STATIC_ARGS} ${DEST_VORBIS}/${ARCH}/libvorbisfile.a
COMMENT "Stripping Vorbis libraries")
COMMENT "Stripping Vorbis static libraries")
endif()
12 changes: 12 additions & 0 deletions patches/ogg.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -urN libogg-1.3.5.orig/CMakeLists.txt libogg-1.3.5/CMakeLists.txt
--- libogg-1.3.5.orig/CMakeLists.txt 2021-05-10 19:40:30.000000000 +0200
+++ libogg-1.3.5/CMakeLists.txt 2024-03-03 18:38:01.623796959 +0100
@@ -100,8 +100,6 @@

set_target_properties(
ogg PROPERTIES
- SOVERSION ${LIB_SOVERSION}
- VERSION ${LIB_VERSION}
PUBLIC_HEADER "${OGG_HEADERS}"
)

15 changes: 15 additions & 0 deletions patches/vorbis.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff -urN libvorbis-1.3.7.orig/lib/CMakeLists.txt libvorbis-1.3.7/lib/CMakeLists.txt
--- libvorbis-1.3.7.orig/lib/CMakeLists.txt 2020-04-15 18:20:52.000000000 +0200
+++ libvorbis-1.3.7/lib/CMakeLists.txt 2024-03-03 18:39:03.367128679 +0100
@@ -79,11 +79,8 @@
add_library(vorbisfile ${VORBISFILE_SOURCES})

get_version_info(VORBIS_VERSION_INFO "V_LIB_CURRENT" "V_LIB_AGE" "V_LIB_REVISION")
- set_target_properties(vorbis PROPERTIES SOVERSION ${VORBIS_VERSION_INFO})
get_version_info(VORBISENC_VERSION_INFO "VE_LIB_CURRENT" "VE_LIB_AGE" "VE_LIB_REVISION")
- set_target_properties(vorbisenc PROPERTIES SOVERSION ${VORBISENC_VERSION_INFO})
get_version_info(VORBISFILE_VERSION_INFO "VF_LIB_CURRENT" "VF_LIB_AGE" "VF_LIB_REVISION")
- set_target_properties(vorbisfile PROPERTIES SOVERSION ${VORBISFILE_VERSION_INFO})

target_include_directories(vorbis
PUBLIC

0 comments on commit c38c029

Please sign in to comment.