CMakeList配置JNI包含多個(gè)cpp文件

  • 整合后結(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è)路徑的頭文件無(wú)需設(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} )

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容