Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
cmake_minimum_required(VERSION 3.0)

# Extract project version from configure.ac
file(READ configure.ac CONFIGURE_AC_CONTENTS)
string(REGEX MATCH "AM_INIT_AUTOMAKE\\(libvorbisidec,([0-9]*\\.[0-9]*\\.[0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})

project(tremor VERSION ${CMAKE_MATCH_1} LANGUAGES C)

# Required modules
include(GNUInstallDirs)
include(CheckIncludeFiles)
include(CMakePackageConfigHelpers)
include(CTest)

# Build options
option(BUILD_SHARED_LIBS "Build shared library" OFF)
if(APPLE)
option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
endif()
option(BUILD_LOW_ACCURACY "Enable 32 bit only multiply operations" OFF)

# Install options
option(INSTALL_DOCS "Install documentation" ON)
option(INSTALL_PKG_CONFIG_MODULE "Install vorbisidec.pc file" ON)
option(INSTALL_CMAKE_PACKAGE_MODULE "Install CMake package configuration module" ON)

# Extract library version from configure.ac
string(REGEX MATCH "LIB_CURRENT=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_CURRENT ${CMAKE_MATCH_1})

string(REGEX MATCH "LIB_AGE=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_AGE ${CMAKE_MATCH_1})

string(REGEX MATCH "LIB_REVISION=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_REVISION ${CMAKE_MATCH_1})

math(EXPR LIB_SOVERSION "${LIB_CURRENT} - ${LIB_AGE}")
set(LIB_VERSION "${LIB_SOVERSION}.${LIB_AGE}.${LIB_REVISION}")


# Helper function to configure pkg-config files
function(configure_pkg_config_file pkg_config_file_in)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set(VERSION ${PROJECT_VERSION})
string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
configure_file(${pkg_config_file_in} ${pkg_config_file} @ONLY)
endfunction()

message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")

# Find ogg dependency
if(NOT TARGET Ogg::ogg)
find_package(Ogg REQUIRED)
endif()

include(CheckIncludeFile)
check_include_file(alloca.h HAVE_ALLOCA_H)
check_include_file(memory.h HAVE_MEMORY_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)

include(CheckSymbolExists)
if(HAVE_ALLOCA_H)
check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA)
else()
check_symbol_exists(alloca "stdlib.h;malloc.h" HAVE_ALLOCA)
endif()
check_symbol_exists(__arm__ "" HAVE_ARM_ASM)

include(TestBigEndian)
test_big_endian(WORDS_BIGENDIAN)

set(VORBISIDEC_PUBLIC_HEADERS
ivorbiscodec.h
ivorbisfile.h
)

set(VORBISIDEC_HEADERS
codebook.h
misc.h
mdct_lookup.h
os.h
mdct.h
block.h
lsp_lookup.h
registry.h
window.h
window_lookup.h
codec_internal.h
backends.h
asm_arm.h
)

set(VORBISIDEC_SOURCES
mdct.c
block.c
window.c
synthesis.c
info.c
floor1.c
floor0.c
vorbisfile.c
res012.c
mapping0.c
registry.c
codebook.c
sharedbook.c
)

if(BUILD_FRAMEWORK)
set(BUILD_SHARED_LIBS TRUE)
endif()

if(WIN32 AND BUILD_SHARED_LIBS)
list(APPEND VORBISIDEC_SOURCES win32/vorbisidec.def)
endif()

add_library(vorbisidec ${VORBISIDEC_PUBLIC_HEADERS} ${VORBISIDEC_HEADERS} ${VORBISIDEC_SOURCES})
add_library(Tremor::vorbisidec ALIAS vorbisidec)
target_include_directories(vorbisidec PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(vorbisidec PUBLIC Ogg::ogg)

if(BUILD_LOW_ACCURACY)
target_compile_definitions(vorbisidec PRIVATE -D_LOW_ACCURACY_)
endif()
if(HAVE_ALLOCA_H)
target_compile_definitions(vorbisidec PRIVATE -DHAVE_ALLOCA_H)
endif()
if(HAVE_MEMORY_H)
target_compile_definitions(vorbisidec PRIVATE -DHAVE_MEMORY_H)
endif()
if(HAVE_SYS_TYPES_H)
target_compile_definitions(vorbisidec PRIVATE -DHAVE_SYS_TYPES_H)
endif()
if(HAVE_ALLOCA)
target_compile_definitions(vorbisidec PRIVATE -DHAVE_ALLOCA)
endif()
if(HAVE_ARM_ASM)
target_compile_definitions(vorbisidec PRIVATE -D_ARM_ASSEM_)
endif()
if(WORDS_BIGENDIAN)
target_compile_definitions(vorbisidec PRIVATE -DWORDS_BIGENDIAN)
endif(WORDS_BIGENDIAN)

set_target_properties(
vorbisidec PROPERTIES
SOVERSION ${LIB_SOVERSION}
VERSION ${LIB_VERSION}
PUBLIC_HEADER "${VORBISIDEC_PUBLIC_HEADERS}"
)

if(BUILD_FRAMEWORK)
set_target_properties(vorbisidec PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION ${PROJECT_VERSION}
MACOSX_FRAMEWORK_IDENTIFIER org.xiph.tremor
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
OUTPUT_NAME Tremor
)
endif()

configure_pkg_config_file(vorbisidec.pc.in)

install(TARGETS vorbisidec
EXPORT TremorTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tremor
)

export(EXPORT TremorTargets NAMESPACE Tremor:: FILE TremorTargets.cmake)

if(INSTALL_CMAKE_PACKAGE_MODULE)
set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Tremor)
install(EXPORT TremorTargets
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
NAMESPACE Tremor::
)

include(CMakePackageConfigHelpers)

configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/TremorConfig.cmake.in ${PROJECT_BINARY_DIR}/TremorConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
)

write_basic_package_version_file(${PROJECT_BINARY_DIR}/TremorConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES ${PROJECT_BINARY_DIR}/TremorConfig.cmake ${PROJECT_BINARY_DIR}/TremorConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
)
endif()

if(INSTALL_PKG_CONFIG_MODULE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vorbisidec.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif()

set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
include(CPack)
94 changes: 94 additions & 0 deletions cmake/FindOgg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#[=======================================================================[.rst:

FindOgg
--------

Find the native Ogg includes and library.

IMPORTED Targets
^^^^^^^^^^^^^^^^

This module defines :prop_tgt:`IMPORTED` target ``Ogg::ogg``, if
Ogg has been found.

Result Variables
^^^^^^^^^^^^^^^^

This module defines the following variables:

::

OGG_INCLUDE_DIRS - where to find ogg.h, etc.
OGG_LIBRARIES - List of libraries when using ogg.
OGG_FOUND - True if ogg found.

::

OGG_VERSION_STRING - The version of ogg found (x.y.z)

Hints
^^^^^

A user may set ``OGG_ROOT`` to a ogg installation root to tell this
module where to look.
#]=======================================================================]

if(OGG_INCLUDE_DIR)
# Already in cache, be silent
set(OGG_FIND_QUIETLY TRUE)
endif()

find_package(PkgConfig QUIET)
pkg_check_modules(PC_OGG QUIET ogg)

set(OGG_VERSION_STRING ${PC_OGG_VERSION})

find_path(OGG_INCLUDE_DIR ogg/ogg.h
HINTS
${PC_OGG_INCLUDEDIR}
${PC_OGG_INCLUDE_DIRS}
${OGG_ROOT}
PATH_SUFFIXES
include
)
# MSVC built ogg may be named ogg_static.
# The provided project files name the library with the lib prefix.
find_library(OGG_LIBRARY
NAMES
ogg
ogg_static
libogg
libogg_static
HINTS
${PC_OGG_LIBDIR}
${PC_OGG_LIBRARY_DIRS}
${OGG_ROOT}
PATH_SUFFIXES
lib
)

# Handle the QUIETLY and REQUIRED arguments and set OGG_FOUND
# to TRUE if all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Ogg
REQUIRED_VARS
OGG_LIBRARY
OGG_INCLUDE_DIR
VERSION_VAR
OGG_VERSION_STRING
)

if(OGG_FOUND)
set(OGG_LIBRARIES ${OGG_LIBRARY})
set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR})

if(NOT TARGET Ogg::ogg)
add_library(Ogg::ogg UNKNOWN IMPORTED)
set_target_properties(Ogg::ogg PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIRS}"
IMPORTED_LOCATION "${OGG_LIBRARIES}"
)
endif()
endif()

mark_as_advanced(OGG_INCLUDE_DIR OGG_LIBRARY)
16 changes: 16 additions & 0 deletions cmake/TremorConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
if(NOT TARGET Ogg::ogg)
find_dependency(Ogg REQUIRED)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/TremorTargets.cmake)

set(Tremor_Vorbisidec_FOUND 0)

if(TARGET Tremor::vorbisidec)
set(Tremor_Vorbisidec_FOUND TRUE)
endif()

check_required_components(Vorbisidec)
58 changes: 58 additions & 0 deletions win32/vorbisidec.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
; vorbisidec.def
;

EXPORTS
_floor_P
_mapping_P
_residue_P
;
vorbis_info_init
vorbis_info_clear
vorbis_info_blocksize
;
vorbis_comment_init
vorbis_comment_query
vorbis_comment_query_count
vorbis_comment_clear
;
vorbis_block_init
vorbis_block_clear
vorbis_dsp_clear
;
vorbis_synthesis_idheader
vorbis_synthesis_headerin
vorbis_synthesis_init
vorbis_synthesis_restart
vorbis_synthesis
vorbis_synthesis_trackonly
vorbis_synthesis_blockin
vorbis_synthesis_pcmout
vorbis_synthesis_read
vorbis_packet_blocksize
;
ov_clear
ov_fopen
ov_open
ov_open_callbacks
ov_test
ov_test_callbacks
ov_test_open
ov_bitrate
ov_bitrate_instant
ov_streams
ov_seekable
ov_serialnumber
ov_raw_total
ov_pcm_total
ov_time_total
ov_raw_seek
ov_pcm_seek
ov_pcm_seek_page
ov_time_seek
ov_time_seek_page
ov_raw_tell
ov_pcm_tell
ov_time_tell
ov_info
ov_comment
ov_read