add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
# - Compile and run code to check for C features
#
# This functions compiles a source file under the `cmake` folder
# and adds the corresponding `HAVE_[FILENAME]` flag to the CMake
# environment
#
# c_feature_check(<FLAG> [<VARIANT>])
#
# - Example
#
# include(CFeatureCheck)
# c_feature_check(VLA)
if(__c_feature_check)
return()
endif()
set(__c_feature_check INCLUDED)
function(c_feature_check FILE)
string(TOLOWER ${FILE} FILE)
string(TOUPPER ${FILE} VAR)
string(TOUPPER "${VAR}_SUPPORTED" FEATURE)
if (DEFINED ${VAR}_SUPPORTED)
set(${VAR}_SUPPORTED 1 PARENT_SCOPE)
return()
endif()
if (NOT DEFINED COMPILE_${FEATURE})
message(STATUS "Performing Test ${FEATURE}")
try_compile(COMPILE_${FEATURE} ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/${FILE}.c)
endif()
if(COMPILE_${FEATURE})
message(STATUS "Performing Test ${FEATURE} -- success")
set(${VAR}_SUPPORTED 1 PARENT_SCOPE)
else()
message(STATUS "Performing Test ${FEATURE} -- failed to compile")
endif()
endfunction()

View File

@@ -0,0 +1,27 @@
# Set a default build type if none was specified
if(__opus_buildtype)
return()
endif()
set(__opus_buildtype INCLUDED)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if(CMAKE_C_FLAGS)
message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
else()
set(default_build_type "Release")
message(
STATUS
"Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported."
)
set(CMAKE_BUILD_TYPE "${default_build_type}"
CACHE STRING "Choose the type of build."
FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS
"Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo")
endif()
endif()

View File

@@ -0,0 +1,118 @@
if(__opus_config)
return()
endif()
set(__opus_config INCLUDED)
include(OpusFunctions)
configure_file(cmake/config.h.cmake.in config.h @ONLY)
add_definitions(-DHAVE_CONFIG_H)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(MSVC)
# For compilers that have no notion of a C standard level,
# such as Microsoft Visual C++ before VS 16.7,
# this property has no effect.
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
include(CFeatureCheck)
c_feature_check(VLA)
include(CheckIncludeFile)
check_include_file(alloca.h HAVE_ALLOCA_H)
include(CheckSymbolExists)
if(HAVE_ALLOCA_H)
add_definitions(-DHAVE_ALLOCA_H)
check_symbol_exists(alloca "alloca.h" USE_ALLOCA_SUPPORTED)
else()
check_symbol_exists(alloca "stdlib.h;malloc.h" USE_ALLOCA_SUPPORTED)
endif()
include(CMakePushCheckState)
cmake_push_check_state(RESET)
include(CheckLibraryExists)
check_library_exists(m floor "" HAVE_LIBM)
if(HAVE_LIBM)
list(APPEND OPUS_REQUIRED_LIBRARIES m)
set(CMAKE_REQUIRED_LIBRARIES m)
endif()
check_symbol_exists(lrintf "math.h" HAVE_LRINTF)
check_symbol_exists(lrint "math.h" HAVE_LRINT)
cmake_pop_check_state()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(OPUS_CPU_X64 1)
else()
set(OPUS_CPU_X86 1)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
set(OPUS_CPU_ARM 1)
endif()
if(NOT OPUS_DISABLE_INTRINSICS)
opus_supports_cpu_detection(RUNTIME_CPU_CAPABILITY_DETECTION)
endif()
if(OPUS_CPU_X86 OR OPUS_CPU_X64 AND NOT OPUS_DISABLE_INTRINSICS)
opus_detect_sse(COMPILER_SUPPORT_SIMD)
elseif(OPUS_CPU_ARM AND NOT OPUS_DISABLE_INTRINSICS)
opus_detect_neon(COMPILER_SUPPORT_NEON)
if(COMPILER_SUPPORT_NEON)
option(OPUS_USE_NEON "Option to enable NEON" ON)
option(OPUS_MAY_HAVE_NEON "Does runtime check for neon support" ON)
option(OPUS_PRESUME_NEON "Assume target CPU has NEON support" OFF)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(OPUS_PRESUME_NEON ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
set(OPUS_PRESUME_NEON ON)
endif()
endif()
endif()
if(MSVC)
check_flag(FAST_MATH /fp:fast)
check_flag(STACK_PROTECTOR /GS)
check_flag(STACK_PROTECTOR_DISABLED /GS-)
else()
check_flag(FAST_MATH -ffast-math)
check_flag(STACK_PROTECTOR -fstack-protector-strong)
check_flag(HIDDEN_VISIBILITY -fvisibility=hidden)
set(FORTIFY_SOURCE_SUPPORTED 1)
endif()
if(MINGW)
# For MINGW we need to link ssp lib for security features such as
# stack protector and fortify_sources
check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP)
if(NOT HAVE_LIBSSP)
message(WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE")
set(STACK_PROTECTOR_SUPPORTED 0)
set(FORTIFY_SOURCE_SUPPORTED 0)
endif()
endif()
if(MSVC)
# move cosmetic warnings to level 4
add_compile_options(/w44244 /w44305 /w44267)
else()
set(WARNING_LIST -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow)
include(CheckCCompilerFlag)
foreach(WARNING_FLAG ${WARNING_LIST})
string(REPLACE - "" WARNING_VAR ${WARNING_FLAG})
check_c_compiler_flag(${WARNING_FLAG} ${WARNING_VAR}_SUPPORTED)
if(${WARNING_VAR}_SUPPORTED)
add_compile_options(${WARNING_FLAG})
endif()
endforeach()
endif()

View File

@@ -0,0 +1,20 @@
set(OPUS_VERSION @PROJECT_VERSION@)
set(OPUS_VERSION_STRING @PROJECT_VERSION@)
set(OPUS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
set(OPUS_VERSION_MINOR @PROJECT_VERSION_MINOR@)
set(OPUS_VERSION_PATCH @PROJECT_VERSION_PATCH@)
@PACKAGE_INIT@
set_and_check(OPUS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR};${OPUS_INCLUDE_DIR}/opus)
set(OPUS_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@;@PACKAGE_INCLUDE_INSTALL_DIR@/opus")
include(${CMAKE_CURRENT_LIST_DIR}/OpusTargets.cmake)
set(OPUS_LIBRARY Opus::opus)
set(OPUS_LIBRARIES Opus::opus)
check_required_components(Opus)
set(OPUS_FOUND 1)

View File

@@ -0,0 +1,231 @@
if(__opus_functions)
return()
endif()
set(__opus_functions INCLUDED)
function(get_library_version OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
file(STRINGS configure.ac opus_lt_current_string
LIMIT_COUNT 1
REGEX "OPUS_LT_CURRENT=")
string(REGEX MATCH
"OPUS_LT_CURRENT=([0-9]*)"
_
${opus_lt_current_string})
set(OPUS_LT_CURRENT ${CMAKE_MATCH_1})
file(STRINGS configure.ac opus_lt_revision_string
LIMIT_COUNT 1
REGEX "OPUS_LT_REVISION=")
string(REGEX MATCH
"OPUS_LT_REVISION=([0-9]*)"
_
${opus_lt_revision_string})
set(OPUS_LT_REVISION ${CMAKE_MATCH_1})
file(STRINGS configure.ac opus_lt_age_string
LIMIT_COUNT 1
REGEX "OPUS_LT_AGE=")
string(REGEX MATCH
"OPUS_LT_AGE=([0-9]*)"
_
${opus_lt_age_string})
set(OPUS_LT_AGE ${CMAKE_MATCH_1})
math(EXPR OPUS_LIBRARY_VERSION_MAJOR "${OPUS_LT_CURRENT} - ${OPUS_LT_AGE}")
set(OPUS_LIBRARY_VERSION_MINOR ${OPUS_LT_AGE})
set(OPUS_LIBRARY_VERSION_PATCH ${OPUS_LT_REVISION})
set(
OPUS_LIBRARY_VERSION
"${OPUS_LIBRARY_VERSION_MAJOR}.${OPUS_LIBRARY_VERSION_MINOR}.${OPUS_LIBRARY_VERSION_PATCH}"
PARENT_SCOPE)
set(OPUS_LIBRARY_VERSION_MAJOR ${OPUS_LIBRARY_VERSION_MAJOR} PARENT_SCOPE)
endfunction()
function(check_flag NAME FLAG)
include(CheckCCompilerFlag)
check_c_compiler_flag(${FLAG} ${NAME}_SUPPORTED)
endfunction()
include(CheckIncludeFile)
# This function determines if the compiler has support for SSE, SSE2, SSE4.1, AVX,
# AVX2 and FMA. Should the target systems potentially lack SSE support, the
# OPUS_MAY_HAVE_SSE option is recommended for use. If, however, the target system is
# assured to support SSE, the OPUS_PRESUME_SSE option can be employed, thus
# eliminating the necessity for an SSE runtime check.
function(opus_detect_sse COMPILER_SUPPORT_SIMD)
message(STATUS "Check SIMD support by compiler")
check_include_file(xmmintrin.h HAVE_XMMINTRIN_H) # SSE1
if(HAVE_XMMINTRIN_H)
if(MSVC)
# different arch options for 32 and 64 bit target for MSVC
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
check_flag(SSE1 /arch:SSE)
else()
set(SSE1_SUPPORTED
1
PARENT_SCOPE)
endif()
else()
check_flag(SSE1 -msse)
endif()
else()
set(SSE1_SUPPORTED
0
PARENT_SCOPE)
endif()
check_include_file(emmintrin.h HAVE_EMMINTRIN_H) # SSE2
if(HAVE_EMMINTRIN_H)
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
check_flag(SSE2 /arch:SSE2)
else()
set(SSE2_SUPPORTED
1
PARENT_SCOPE)
endif()
else()
check_flag(SSE2 -msse2)
endif()
else()
set(SSE2_SUPPORTED
0
PARENT_SCOPE)
endif()
check_include_file(smmintrin.h HAVE_SMMINTRIN_H) # SSE4.1
if(HAVE_SMMINTRIN_H)
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
check_flag(SSE4_1 /arch:SSE2) # SSE2 and above
else()
set(SSE4_1_SUPPORTED
1
PARENT_SCOPE)
endif()
else()
check_flag(SSE4_1 -msse4.1)
endif()
else()
set(SSE4_1_SUPPORTED
0
PARENT_SCOPE)
endif()
check_include_file(immintrin.h HAVE_IMMINTRIN_H) # AVX2
if(HAVE_IMMINTRIN_H)
if(MSVC)
check_flag(AVX2 /arch:AVX2)
else()
check_flag(AVX2 -mavx2 -mfma -mavx)
endif()
else()
set(AVX2_SUPPORTED
0
PARENT_SCOPE)
endif()
if(SSE1_SUPPORTED OR SSE2_SUPPORTED OR SSE4_1_SUPPORTED OR AVX2_SUPPORTED)
set(COMPILER_SUPPORT_SIMD 1 PARENT_SCOPE)
else()
message(STATUS "No SIMD support in compiler")
endif()
endfunction()
function(opus_detect_neon COMPILER_SUPPORT_NEON)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
message(STATUS "Check NEON support by compiler")
check_include_file(arm_neon.h HAVE_ARM_NEON_H)
if(HAVE_ARM_NEON_H)
set(COMPILER_SUPPORT_NEON ${HAVE_ARM_NEON_H} PARENT_SCOPE)
endif()
endif()
endfunction()
function(opus_supports_cpu_detection RUNTIME_CPU_CAPABILITY_DETECTION)
set(RUNTIME_CPU_CAPABILITY_DETECTION 0 PARENT_SCOPE)
if(OPUS_CPU_X86 OR OPUS_CPU_X64)
if(MSVC)
check_include_file(intrin.h HAVE_INTRIN_H)
if(HAVE_INTRIN_H)
# if intrin.h is available we assume __cpuid is there
set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
endif()
else()
include(CFeatureCheck)
c_feature_check(CPU_INFO_BY_ASM)
set(CPU_INFO_BY_ASM_SUPPORTED ${CPU_INFO_BY_ASM_SUPPORTED} PARENT_SCOPE)
check_include_file(cpuid.h HAVE_CPUID_H)
if(HAVE_CPUID_H)
c_feature_check(CPU_INFO_BY_C)
set(CPU_INFO_BY_C_SUPPORTED ${CPU_INFO_BY_C_SUPPORTED} PARENT_SCOPE)
endif()
if(CPU_INFO_BY_ASM_SUPPORTED OR CPU_INFO_BY_C_SUPPORTED)
set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
endif()
endif()
elseif(OPUS_CPU_ARM)
# ARM cpu detection is implemented for Windows and anything
# using a Linux kernel (such as Android).
if (CMAKE_SYSTEM_NAME MATCHES "(Windows|Linux|Android)")
set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
endif ()
else()
set(RUNTIME_CPU_CAPABILITY_DETECTION 0 PARENT_SCOPE)
endif()
endfunction()
function(add_sources_group target group)
target_sources(${target} PRIVATE ${ARGN})
source_group(${group} FILES ${ARGN})
endfunction()
function(get_opus_sources SOURCE_GROUP MAKE_FILE SOURCES)
# read file, each item in list is one group
file(STRINGS ${MAKE_FILE} opus_sources)
# add wildcard for regex match
string(CONCAT SOURCE_GROUP ${SOURCE_GROUP} ".*$")
# find group
foreach(val IN LISTS opus_sources)
if(val MATCHES ${SOURCE_GROUP})
list(LENGTH val list_length)
if(${list_length} EQUAL 1)
# for tests split by '=' and clean up the rest into a list
string(FIND ${val} "=" index)
math(EXPR index "${index} + 1")
string(SUBSTRING ${val}
${index}
-1
sources)
string(REPLACE " "
";"
sources
${sources})
else()
# discard the group
list(REMOVE_AT val 0)
set(sources ${val})
endif()
break()
endif()
endforeach()
list(LENGTH sources list_length)
if(${list_length} LESS 1)
message(
FATAL_ERROR
"No files parsed successfully from ${SOURCE_GROUP} in ${MAKE_FILE}")
endif()
# remove trailing whitespaces
set(list_var "")
foreach(source ${sources})
string(STRIP "${source}" source)
list(APPEND list_var "${source}")
endforeach()
set(${SOURCES} ${list_var} PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,70 @@
if(__opus_version)
return()
endif()
set(__opus_version INCLUDED)
function(get_package_version PACKAGE_VERSION PROJECT_VERSION)
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE}
--git-dir=${CMAKE_CURRENT_LIST_DIR}/.git describe
--tags --match "v*" OUTPUT_VARIABLE OPUS_PACKAGE_VERSION)
if(OPUS_PACKAGE_VERSION)
string(STRIP ${OPUS_PACKAGE_VERSION}, OPUS_PACKAGE_VERSION)
string(REPLACE \n
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(REPLACE ,
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(SUBSTRING ${OPUS_PACKAGE_VERSION}
1
-1
OPUS_PACKAGE_VERSION)
message(STATUS "Opus package version from git repo: ${OPUS_PACKAGE_VERSION}")
endif()
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/package_version"
AND NOT OPUS_PACKAGE_VERSION)
# Not a git repo, lets' try to parse it from package_version file if exists
file(STRINGS package_version OPUS_PACKAGE_VERSION
LIMIT_COUNT 1
REGEX "PACKAGE_VERSION=")
string(REPLACE "PACKAGE_VERSION="
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(REPLACE "\""
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
# In case we have a unknown dist here we just replace it with 0
string(REPLACE "unknown"
"0"
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
message(STATUS "Opus package version from package_version file: ${OPUS_PACKAGE_VERSION}")
endif()
if(OPUS_PACKAGE_VERSION)
string(REGEX
REPLACE "^([0-9]+.[0-9]+\\.?([0-9]+)?).*"
"\\1"
OPUS_PROJECT_VERSION
${OPUS_PACKAGE_VERSION})
else()
# fail to parse version from git and package version
message(WARNING "Could not get package version.")
set(OPUS_PACKAGE_VERSION 0)
set(OPUS_PROJECT_VERSION 0)
endif()
message(STATUS "Opus project version: ${OPUS_PROJECT_VERSION}")
set(PACKAGE_VERSION ${OPUS_PACKAGE_VERSION} PARENT_SCOPE)
set(PROJECT_VERSION ${OPUS_PROJECT_VERSION} PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,71 @@
if(__opus_sources)
return()
endif()
set(__opus_sources INCLUDED)
include(OpusFunctions)
get_opus_sources(SILK_HEAD silk_headers.mk silk_headers)
get_opus_sources(SILK_SOURCES silk_sources.mk silk_sources)
get_opus_sources(SILK_SOURCES_FLOAT silk_sources.mk silk_sources_float)
get_opus_sources(SILK_SOURCES_FIXED silk_sources.mk silk_sources_fixed)
get_opus_sources(SILK_SOURCES_X86_RTCD silk_sources.mk silk_sources_x86_rtcd)
get_opus_sources(SILK_SOURCES_SSE4_1 silk_sources.mk silk_sources_sse4_1)
get_opus_sources(SILK_SOURCES_FIXED_SSE4_1 silk_sources.mk
silk_sources_fixed_sse4_1)
get_opus_sources(SILK_SOURCES_AVX2 silk_sources.mk silk_sources_avx2)
get_opus_sources(SILK_SOURCES_FLOAT_AVX2 silk_sources.mk silk_sources_float_avx2)
get_opus_sources(SILK_SOURCES_ARM_RTCD silk_sources.mk silk_sources_arm_rtcd)
get_opus_sources(SILK_SOURCES_ARM_NEON_INTR silk_sources.mk
silk_sources_arm_neon_intr)
get_opus_sources(SILK_SOURCES_FIXED_ARM_NEON_INTR silk_sources.mk
silk_sources_fixed_arm_neon_intr)
get_opus_sources(OPUS_HEAD opus_headers.mk opus_headers)
get_opus_sources(OPUS_SOURCES opus_sources.mk opus_sources)
get_opus_sources(OPUS_SOURCES_FLOAT opus_sources.mk opus_sources_float)
get_opus_sources(CELT_HEAD celt_headers.mk celt_headers)
get_opus_sources(CELT_SOURCES celt_sources.mk celt_sources)
get_opus_sources(CELT_SOURCES_X86_RTCD celt_sources.mk celt_sources_x86_rtcd)
get_opus_sources(CELT_SOURCES_SSE celt_sources.mk celt_sources_sse)
get_opus_sources(CELT_SOURCES_SSE2 celt_sources.mk celt_sources_sse2)
get_opus_sources(CELT_SOURCES_SSE4_1 celt_sources.mk celt_sources_sse4_1)
get_opus_sources(CELT_SOURCES_AVX2 celt_sources.mk celt_sources_avx2)
get_opus_sources(CELT_SOURCES_ARM_RTCD celt_sources.mk celt_sources_arm_rtcd)
get_opus_sources(CELT_SOURCES_ARM_ASM celt_sources.mk celt_sources_arm_asm)
get_opus_sources(CELT_AM_SOURCES_ARM_ASM celt_sources.mk
celt_am_sources_arm_asm)
get_opus_sources(CELT_SOURCES_ARM_NEON_INTR celt_sources.mk
celt_sources_arm_neon_intr)
get_opus_sources(CELT_SOURCES_ARM_NE10 celt_sources.mk celt_sources_arm_ne10)
get_opus_sources(DEEP_PLC_HEAD lpcnet_headers.mk deep_plc_headers)
get_opus_sources(DRED_HEAD lpcnet_headers.mk dred_headers)
get_opus_sources(OSCE_HEAD lpcnet_headers.mk osce_headers)
get_opus_sources(DEEP_PLC_SOURCES lpcnet_sources.mk deep_plc_sources)
get_opus_sources(DRED_SOURCES lpcnet_sources.mk dred_sources)
get_opus_sources(OSCE_SOURCES lpcnet_sources.mk osce_sources)
get_opus_sources(DNN_SOURCES_X86_RTCD lpcnet_sources.mk dnn_sources_x86_rtcd)
get_opus_sources(DNN_SOURCES_SSE2 lpcnet_sources.mk dnn_sources_sse2)
get_opus_sources(DNN_SOURCES_SSE4_1 lpcnet_sources.mk dnn_sources_sse4_1)
get_opus_sources(DNN_SOURCES_AVX2 lpcnet_sources.mk dnn_sources_avx2)
get_opus_sources(DNN_SOURCES_NEON lpcnet_sources.mk dnn_sources_arm_neon)
get_opus_sources(DNN_SOURCES_DOTPROD lpcnet_sources.mk dnn_sources_arm_dotprod)
get_opus_sources(opus_demo_SOURCES Makefile.am opus_demo_sources)
get_opus_sources(opus_custom_demo_SOURCES Makefile.am opus_custom_demo_sources)
get_opus_sources(opus_compare_SOURCES Makefile.am opus_compare_sources)
get_opus_sources(tests_test_opus_api_SOURCES Makefile.am test_opus_api_sources)
get_opus_sources(tests_test_opus_encode_SOURCES Makefile.am
test_opus_encode_sources)
get_opus_sources(tests_test_opus_extensions_SOURCES Makefile.am
test_opus_extensions_sources)
get_opus_sources(tests_test_opus_decode_SOURCES Makefile.am
test_opus_decode_sources)
get_opus_sources(tests_test_opus_padding_SOURCES Makefile.am
test_opus_padding_sources)
get_opus_sources(tests_test_opus_dred_SOURCES Makefile.am
test_opus_dred_sources)
get_opus_sources(tests_test_opus_custom_SOURCES Makefile.am
test_opus_custom_sources)

View File

@@ -0,0 +1,132 @@
# Using CMake for the Opus Project
This guide provides instructions for using CMake to build the Opus project with various configuration options. CMake is a widely used build system generator that helps manage the build process across different platforms.
Note: Please keep in mind that software documentation can sometimes go out of date as new versions are released. It is always recommended to refer to the official CMake documentation for the most up-to-date and accurate information. You can find the official CMake documentation at [cmake.org/documentation](https://cmake.org/documentation/).
## Prerequisites
Before proceeding, make sure you have the following prerequisites installed:
- CMake
- Git (optional, but recommended for version control integration)
- Working C compiler
## Build Instructions
Follow the steps below to build the Opus project using CMake:
1. Clone the Opus repository using Git:
```shell
git clone https://gitlab.xiph.org/xiph/opus
```
2. Create a build directory within the Opus repository:
```shell
cd opus
mkdir build
cd build
```
3. Configure the build with CMake. You can set the desired configuration options using CMake's `-D` flag. Here are some available options:
- `OPUS_BUILD_SHARED_LIBRARY`: build shared library.
- `OPUS_BUILD_TESTING`: build tests.
- `OPUS_BUILD_PROGRAMS`: build programs.
- `OPUS_CUSTOM_MODES`, enable non-Opus modes, e.g. 44.1 kHz & 2^n frames.
For example, to enable the custom modes and build programs, use the following command:
```shell
cmake .. -DOPUS_BUILD_PROGRAMS=ON -DOPUS_BUILD_TESTING=ON
```
4. Build the Opus project:
```shell
cmake --build .
```
5. After a successful build, you can find the compiled Opus library and associated files in the build directory.
## Testing with CTest
Opus provides a comprehensive test suite to ensure the functionality and correctness of the project. You can execute the tests using CTest, a part of the CMake build system. CTest allows for automated testing and provides useful features for managing and evaluating the test results.
To run the Opus tests using CTest, follow these steps:
1. Navigate to the build directory after configuring and building the project with CMake:
```shell
cd build
```
2. Execute the tests using CTest:
```shell
ctest
```
Note: For Windows you need to specify which configuration to test
```shell
ctest -C Debug
```
## Platform Support and Bug Reporting
CMake aims to provide broad platform support, allowing the Opus project to be built and used on major operating systems and platforms. The supported platforms include:
- Windows
- macOS
- Linux
- Android
- iOS
CMake achieves platform support by generating platform-specific build files (e.g., Makefiles, Visual Studio projects) based on the target platform. This allows developers to build and configure the Opus project consistently across different operating systems and environments.
While CMake strives to ensure compatibility and stability across platforms, bugs or issues may still arise in specific configurations. If you encounter any problems during the configuration process or while building the Opus project, we encourage you to file an issue in the [project's issue tracker](https://gitlab.xiph.org/xiph/opus/-/issues).
When reporting an issue, please provide the following information to help us understand and reproduce the configuration problem effectively:
1. Detailed description of the issue, including any error messages or unexpected behavior observed.
2. Steps to reproduce the problem, including the CMake command and any specific configuration options used.
3. Operating system and version (e.g., Windows 10, macOS Big Sur, Ubuntu 20.04).
4. CMake version (e.g., CMake 3.21.1).
5. Any relevant information about the platform, toolchain, or dependencies used.
6. Additional context or details that might assist in troubleshooting the issue.
By providing thorough information when reporting configuration issues, you contribute to improving the Opus project's compatibility and reliability across different platforms.
We appreciate your help in identifying and addressing any configuration-related problems, ensuring a better experience for all users of the Opus project.
## Platform Specific Examples
Note: Examples can go out of date. Always refer to documentation for latest reference.
### Cross compiling for Android
```shell
cmake .. -DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a
```
For more information about cross compiling for android, you can refer to the [Cross compiling for Android documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android).
### Cross compiling for iOS
```shell
cmake .. -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64
```
For more information about cross compilation for iOS, you can refer to the [Cross compiling for iOS documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos).
### Windows Visual Studio
```shell
cmake .. -G "Visual Studio 17 2022" -A x64
```
For more information about the Visual Studio generator options and additional customization, you can refer to the [Visual Studio Generator documentation](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html).

View File

@@ -0,0 +1,61 @@
if(NOT EXISTS ${TEST_EXECUTABLE})
message(FATAL_ERROR "Error could not find ${TEST_EXECUTABLE}, ensure that you built the test binary")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# support to run plain old binary on android devices
# requires android debug bridge to be installed
find_program(adb_executable adb)
if(NOT adb_executable)
message(FATAL_ERROR "Error could not find adb")
endif()
# check if any device emulator is attached
execute_process(COMMAND ${adb_executable} shell echo RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error adb: no devices/emulators found")
endif()
# push binary
set(android_path /data/local/tmp)
execute_process(COMMAND ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error running ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} failed with result ${CMD_RESULT}")
endif()
# set permissions
get_filename_component(test_executable ${TEST_EXECUTABLE} NAME)
set(test_executable_on_android /data/local/tmp/${test_executable})
execute_process(COMMAND ${adb_executable} shell chmod 555 ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error running ${adb_executable} shell chmod 555 ${test_executable_on_android} failed with result ${CMD_RESULT}")
endif()
# run executable
execute_process(COMMAND ${adb_executable} shell ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error running ${adb_executable} shell ${test_executable_on_android} failed with result ${CMD_RESULT}")
endif()
# clean up binary
execute_process(COMMAND ${adb_executable} shell rm ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error running ${adb_executable} shell rm ${test_executable_on_android} failed with result ${CMD_RESULT}")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
# CTest doesn't support iOS
message(FATAL_ERROR "Error CTest is not supported on iOS")
else()
# for other platforms just execute test binary on host
execute_process(COMMAND ${TEST_EXECUTABLE} RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
message(FATAL_ERROR "Error running ${TEST_EXECUTABLE} failed with result ${CMD_RESULT}")
endif()
endif()

View File

@@ -0,0 +1 @@
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"

View File

@@ -0,0 +1,31 @@
#include <stdio.h>
int main() {
unsigned int CPUInfo0;
unsigned int CPUInfo1;
unsigned int CPUInfo2;
unsigned int CPUInfo3;
unsigned int InfoType;
#if defined(__i386__) && defined(__PIC__)
/* %ebx is PIC register in 32-bit, so mustn't clobber it. */
__asm__ __volatile__ (
"xchg %%ebx, %1\n"
"cpuid\n"
"xchg %%ebx, %1\n":
"=a" (CPUInfo0),
"=r" (CPUInfo1),
"=c" (CPUInfo2),
"=d" (CPUInfo3) :
"0" (InfoType), "2" (0)
);
#else
__asm__ __volatile__ (
"cpuid":
"=a" (CPUInfo0),
"=b" (CPUInfo1),
"=c" (CPUInfo2),
"=d" (CPUInfo3) :
"0" (InfoType), "2" (0)
);
#endif
return 0;
}

View File

@@ -0,0 +1,9 @@
#include <cpuid.h>
int main() {
unsigned int CPUInfo0;
unsigned int CPUInfo1;
unsigned int CPUInfo2;
unsigned int CPUInfo3;
unsigned int InfoType;
return __get_cpuid_count(InfoType, 0, &CPUInfo0, &CPUInfo1, &CPUInfo2, &CPUInfo3);
}

View File

@@ -0,0 +1,7 @@
int main() {
static int x;
char a[++x];
a[sizeof a - 1] = 0;
int N;
return a[0];
}