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.
Before proceeding, make sure you have the following prerequisites installed:
- CMake
- Git (optional, but recommended for version control integration)
- Working C compiler
Follow the steps below to build the Opus project using CMake:
-
Clone the Opus repository using Git:
git clone https://gitlab.xiph.org/xiph/opus
-
Create a build directory within the Opus repository:
cd opus mkdir build cd build
-
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:
cmake .. -DOPUS_BUILD_PROGRAMS=ON -DOPUS_BUILD_TESTING=ON
-
Build the Opus project:
cmake --build .
-
After a successful build, you can find the compiled Opus library and associated files in the build directory.
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:
-
Navigate to the build directory after configuring and building the project with CMake:
cd build
-
Execute the tests using CTest:
ctest
Note: For Windows you need to specify which configuration to test
ctest -C Debug
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.
When reporting an issue, please provide the following information to help us understand and reproduce the configuration problem effectively:
- Detailed description of the issue, including any error messages or unexpected behavior observed.
- Steps to reproduce the problem, including the CMake command and any specific configuration options used.
- Operating system and version (e.g., Windows 10, macOS Big Sur, Ubuntu 20.04).
- CMake version (e.g., CMake 3.21.1).
- Any relevant information about the platform, toolchain, or dependencies used.
- 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.
Note: Examples can go out of date. Always refer to documentation for latest reference.
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.
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.
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.