- 整合后結(jié)構(gòu):
項(xiàng)目結(jié)構(gòu)
- 外層CMakeList文件配置:
#指定需要CMAKE的最小版本
cmake_minimum_required(VERSION 3.4.1)
#C的編譯選項(xiàng)是 CMAKE_C_FLAGS
#指定編譯參數(shù)爽醋,可選
SET(CMAKE_CXX_FLAGS "-Wno-error=format-security -Wno-error=pointer-sign")
#設(shè)置生成的so動(dòng)態(tài)庫(kù)最后輸出的路徑
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
#設(shè)置頭文件搜索路徑(和此txt同個(gè)路徑的頭文件無需設(shè)置)拒贱,可選
#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common)
#指定用到的系統(tǒng)庫(kù)或者NDK庫(kù)或者第三方庫(kù)的搜索路徑,可選拦耐。
#LINK_DIRECTORIES(/usr/local/lib)
#添加子目錄,將會(huì)調(diào)用子目錄中的CMakeLists.txt
ADD_SUBDIRECTORY(ffmpeg)
- 內(nèi)層CMakeList文件配置:
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
find_library(android-lib android)
# 查找當(dāng)前目錄下的所有源文件轩猩,并保存到 DIR_LIB_SRCS 變量
aux_source_directory(. DIR_LIB_SRCS)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
# 根據(jù)c文件產(chǎn)生動(dòng)態(tài)庫(kù)
ADD_LIBRARY(native-lib SHARED ${DIR_LIB_SRCS})
set(JNI_LIBS_DIR ${CMAKE_SOURCE_DIR}/../jniLibs)
# 引入已編譯的庫(kù)
add_library(avutil
SHARED
IMPORTED )
set_target_properties(avutil
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libavutil.so )
add_library(swresample
SHARED
IMPORTED )
set_target_properties(swresample
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libswresample.so )
add_library(swscale
SHARED
IMPORTED )
set_target_properties(swscale
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libswscale.so )
add_library(avcodec
SHARED
IMPORTED )
set_target_properties(avcodec
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libavcodec.so )
add_library(avformat
SHARED
IMPORTED )
set_target_properties(avformat
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libavformat.so )
add_library(avfilter
SHARED
IMPORTED )
set_target_properties(avfilter
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libavfilter.so )
add_library(avdevice
SHARED
IMPORTED )
set_target_properties(avdevice
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/${ANDROID_ABI}/libavdevice.so )
include_directories(${JNI_LIBS_DIR}/includes)
target_link_libraries( # Specifies the target library.
native-lib
avutil swresample swscale avcodec avformat avfilter avdevice
# Links the target library to the log library
# included in the NDK.
${log-lib} ${android-lib} )