使用ExternalProject_Add将Opus包含在Android中 [英] Use ExternalProject_Add to include Opus in Android

查看:258
本文介绍了使用ExternalProject_Add将Opus包含在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很简单.

我有一个使用NDK的Android项目.我想在本地代码中包含 opus 源代码.我尝试使用CMake的ExternalProject_Add属性,但是我的本机代码仍然无法从Opus库导入标头,并且无法构建.

I have an Android project that uses NDK. I will like to include the opus source code in the native code. I have tried using the ExternalProject_Add property of CMake but my native code still cannot import headers from the Opus library and fails to build.

以下是我的ExternalProject_Add定义:

Below is my ExternalProject_Add definition:

ExternalProject_Add(project_opus
  URL https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz
  CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
  BUILD_COMMAND make
  INSTALL_COMMAND make install
)

ExternalProject_Get_Property(project_opus install_dir)
include_directories(${install_dir}/include)

add_library(opus SHARED IMPORTED)
add_dependencies(opus project_opus)

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} opus oboe OpenSLES)

推荐答案

因此,这是 CMakeLists.txt :

cmake_minimum_required(VERSION 3.4.1)
include(ExternalProject)

set(OPUS_ROOT ${Project_BINARY_DIR}/project_opus-prefix/src/project_opus)

ExternalProject_Add(project_opus
  URL https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz
  CONFIGURE_COMMAND ""
  INSTALL_COMMAND ""
  BUILD_COMMAND
    ${ANDROID_NDK}/ndk-build
    -C ${OPUS_ROOT}
    NDK_PROJECT_PATH=null
    APP_BUILD_SCRIPT=${Project_SOURCE_DIR}/opus.mk
    NDK_OUT=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../..
    NDK_LIBS_OUT=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/..
    APP_ABI=${ANDROID_ABI}
    NDK_ALL_ABIS=${ANDROID_ABI}
    APP_PLATFORM=${ANDROID_PLATFORM}
  BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopus.so
)

add_library(opus SHARED IMPORTED)
add_dependencies(opus project_opus)

set_target_properties(opus PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopus.so )
include_directories(${OPUS_ROOT}/include)

target_link_libraries( # Specifies the target library.
                   native-lib

                   # Links the target library to the log library
                   # included in the NDK.
                   log opus oboe OpenSLES)

在此文件旁边,您必须放置我从

Next to this file, you must put this opus.mk file which I borrowed from android-ffmpeg-builder on GitHub:

LOCAL_PATH := .

include $(CLEAR_VARS)

#include the .mk files
include $(LOCAL_PATH)/celt_sources.mk
include $(LOCAL_PATH)/silk_sources.mk
include $(LOCAL_PATH)/opus_sources.mk

MY_MODULE_DIR       := opus

LOCAL_MODULE        := $(MY_MODULE_DIR)

#fixed point sources
SILK_SOURCES += $(SILK_SOURCES_FIXED)

#ARM build
CELT_SOURCES += $(CELT_SOURCES_ARM)
SILK_SOURCES += $(SILK_SOURCES_ARM)
LOCAL_SRC_FILES     := \
    $(CELT_SOURCES) \
    $(SILK_SOURCES) \
    $(OPUS_SOURCES) \
    $(OPUS_SOURCES_FLOAT)

LOCAL_LDLIBS        := -lm -llog

LOCAL_C_INCLUDES    := \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/silk \
    $(LOCAL_PATH)/silk/fixed \
    $(LOCAL_PATH)/silk/float \
    $(LOCAL_PATH)/celt

# don't disable the float api
LOCAL_CFLAGS        := -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS        += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT=1 -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -O3 -fno-math-errno
LOCAL_CPPFLAGS      := -DBSD=1
LOCAL_CPPFLAGS      += -ffast-math -O3 -funroll-loops

include $(BUILD_SHARED_LIBRARY)

表面上,这仅支持ARM构建.

On the face of it, this only supports ARM build.

这篇关于使用ExternalProject_Add将Opus包含在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆