Skip to content
New issue

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

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

Already on GitHub? # to your account

Add cmake support #14

Open
wants to merge 17 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ tests/granulepos_theoraenc
tests/noop
tests/noop_theora
tests/noop_theoraenc

.vs/
out/
152 changes: 152 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
cmake_minimum_required(VERSION 3.30)
project(theora LANGUAGES C)

enable_testing()

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
find_package(Ogg CONFIG REQUIRED)

file(GLOB HEADERS
"include/theora/codec.h"
"include/theora/theora.h"
"include/theora/theoradec.h"
"include/theora/theoraenc.h"
)

if(MSVC)
set(LIBTHEORA_COMMON_X86
"lib/x86_vc/mmxfrag.c"
"lib/x86_vc/mmxidct.c"
"lib/x86_vc/mmxstate.c"
"lib/x86_vc/x86cpu.c"
"lib/x86_vc/x86state.c"
)
else()
set(LIBTHEORA_COMMON_X86
"lib/x86/mmxfrag.c"
"lib/x86/mmxidct.c"
"lib/x86/mmxstate.c"
"lib/x86/sse2idct.c"
"lib/x86/x86cpu.c"
"lib/x86/x86state.c"
)
endif()

set(LIBTHEORA_COMMON
"lib/apiwrapper.c"
"lib/bitpack.c"
"lib/dequant.c"
"lib/fragment.c"
"lib/idct.c"
"lib/info.c"
"lib/internal.c"
"lib/state.c"
"lib/quant.c"

${LIBTHEORA_COMMON_X86}
)

if(MSVC)
set(LIBTHEORA_ENC_X86
"lib/x86_vc/mmxencfrag.c"
"lib/x86_vc/mmxfdct.c"
"lib/x86_vc/x86enc.c"
)
else()
set(LIBTHEORA_ENC_X86
"lib/x86/mmxencfrag.c"
"lib/x86/mmxfdct.c"
"lib/x86/x86enc.c"
"lib/x86/x86enquant.c"
"lib/x86/sse2encfrag.c"
)
endif()

set(LIBTHEORA_ENC
"lib/analyze.c"
"lib/encapiwrapper.c"
"lib/encfrag.c"
"lib/encinfo.c"
"lib/encode.c"
"lib/enquant.c"
"lib/fdct.c"
"lib/huffenc.c"
"lib/mathops.c"
"lib/mcenc.c"
"lib/rate.c"
"lib/tokenize.c"

${LIBTHEORA_ENC_X86}
)

set(LIBTHEORA_DEC
"lib/decapiwrapper.c"
"lib/decinfo.c"
"lib/decode.c"
"lib/huffdec.c"
)

add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)

option(USE_X86 "Use x86 optimization" OFF)
if(USE_X86)
add_definitions(-DOC_X86_ASM)
endif()

if (BUILD_SHARED_LIBS)
add_definitions(-DLIBTHEORA_EXPORTS)
endif()

add_library(theora-common OBJECT ${LIBTHEORA_COMMON} ${HEADERS})
target_link_libraries(theora-common PUBLIC Ogg::ogg)
target_include_directories(theora-common PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
add_library(theora-enc OBJECT ${LIBTHEORA_ENC} ${HEADERS})
target_link_libraries(theora-enc PUBLIC Ogg::ogg)
target_include_directories(theora-enc PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
add_library(theora-dec OBJECT ${LIBTHEORA_DEC} ${HEADERS})
target_link_libraries(theora-dec PUBLIC Ogg::ogg)
target_include_directories(theora-dec PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

add_library(theora $<TARGET_OBJECTS:theora-common> $<TARGET_OBJECTS:theora-enc> $<TARGET_OBJECTS:theora-dec> "win32/xmingw32/libtheora.def")
target_link_libraries(theora PUBLIC Ogg::ogg)
target_include_directories(theora PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

add_library(theoraenc $<TARGET_OBJECTS:theora-common> $<TARGET_OBJECTS:theora-enc> "win32/xmingw32/libtheoraenc-all.def")
target_link_libraries(theoraenc PUBLIC Ogg::ogg)
target_include_directories(theoraenc PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

add_library(theoradec $<TARGET_OBJECTS:theora-common> $<TARGET_OBJECTS:theora-dec> "win32/xmingw32/libtheoradec-all.def")
target_link_libraries(theoradec PUBLIC Ogg::ogg)
target_include_directories(theoradec PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

include(CMakePackageConfigHelpers)

configure_package_config_file(theora-config.cmake.in theora-config.cmake
INSTALL_DESTINATION "lib/theora")

install(FILES ${HEADERS} DESTINATION include/theora)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/theora-config.cmake"
DESTINATION "lib/theora"
)

install(TARGETS theora theoraenc theoradec
EXPORT theora-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib
)

install(EXPORT theora-targets
NAMESPACE theora::
DESTINATION "lib/theora"
)

add_subdirectory(tests)

option(BUILD_EXAMPLES "Build examples" ON)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
76 changes: 76 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": [
{
"name": "USE_X86",
"value": "True",
"type": "BOOL"
}
]
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": [
{
"name": "USE_X86",
"value": "True",
"type": "BOOL"
}
]
},
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "USE_X86",
"value": "False",
"type": "BOOL"
}
]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": [
{
"name": "USE_X86",
"value": "False",
"type": "BOOL"
}
]
}
]
}
48 changes: 48 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.30)
project(examples LANGUAGES C)

if(MSVC)
set(GETOPT_SOURCES
"${CMAKE_SOURCE_DIR}/win32/experimental/wincompat/getopt.c"
"${CMAKE_SOURCE_DIR}/win32/experimental/wincompat/getopt_long.c"
)
set(GETOPT_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/win32/experimental/wincompat"
)
else()
set(GETOPT_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/getopt.c"
"${CMAKE_CURRENT_SOURCE_DIR}/getopt1.c"
)
set(GETOPT_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}
)
endif()

find_package(Vorbis CONFIG)

add_executable(dump_psnr dump_psnr.c ${GETOPT_SOURCES})
target_include_directories(dump_psnr PRIVATE ${GETOPT_INCLUDE_DIR})
target_link_libraries(dump_psnr PRIVATE theora)

add_executable(dump_video dump_video.c ${GETOPT_SOURCES})
target_include_directories(dump_video PRIVATE ${GETOPT_INCLUDE_DIR})
target_link_libraries(dump_video PRIVATE theora)

if(Vorbis_FOUND)
add_executable(encoder_example encoder_example.c ${GETOPT_SOURCES})
target_include_directories(encoder_example PRIVATE ${GETOPT_INCLUDE_DIR})
target_link_libraries(encoder_example PRIVATE theora Vorbis::vorbisenc)
endif()

add_executable(libtheora_info libtheora_info.c)
target_link_libraries(libtheora_info PRIVATE theora)

if(MSVC)
add_executable(transcoder_example
"${CMAKE_SOURCE_DIR}/win32/experimental/transcoder/transcoder_example.c"
${GETOPT_SOURCES}
)
target_include_directories(transcoder_example PRIVATE ${GETOPT_INCLUDE_DIR})
target_link_libraries(transcoder_example PRIVATE theora Vorbis::vorbisenc)
endif()
8 changes: 0 additions & 8 deletions examples/encoder_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@
/*supply missing headers and functions to Win32. going to hell, I know*/
#include <fcntl.h>
#include <io.h>

static double rint(double x)
{
if (x < 0.0)
return (double)(int)(x - 0.5);
else
return (double)(int)(x + 0.5);
}
#endif

#if defined(OC_COLLECT_METRICS)
Expand Down
21 changes: 21 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.30)
project(tests LANGUAGES C)

add_executable(comment comment.c)
add_executable(comment_theora comment_theora.c)
add_executable(granulepos granulepos.c)
add_executable(granulepos_theora granulepos_theora.c)
add_executable(noop noop.c)
add_executable(noop_theora noop_theora.c)
target_link_libraries(comment PRIVATE theora)
target_link_libraries(comment_theora PRIVATE theora)
target_link_libraries(granulepos PRIVATE theora)
target_link_libraries(granulepos_theora PRIVATE theora)
target_link_libraries(noop PRIVATE theora)
target_link_libraries(noop_theora PRIVATE theora)
add_test(test_comment comment)
add_test(test_comment_theora comment_theora)
add_test(test_granulepos granulepos)
add_test(test_granulepos_theora granulepos_theora)
add_test(test_noop noop)
add_test(test_noop_theora noop_theora)
4 changes: 3 additions & 1 deletion tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

********************************************************************/

#include "config.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
Expand Down
3 changes: 3 additions & 0 deletions theora-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/theora-targets.cmake")
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "0c4cf19224a049cf82f4521e29e39f7bd680440c",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
6 changes: 6 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": [
"libogg",
"libvorbis"
]
}
22 changes: 0 additions & 22 deletions win32/VS2005/README

This file was deleted.

Loading