CMakeList方法

Context

将CMakeList 和编译器g++对应


cmake_minimum_required(VERSION 3.4.1)

//设置常量
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static-libstdc++")

//设置查找link 库的路径
LINK_DIRECTORIES(${OpenCV_DIR}/native/libs/arm64-v8a)
LINK_DIRECTORIES(${model_git_dir})
LINK_DIRECTORIES(${TensorFlow_DIR}/tensorflow/lite/delegates/gpu/gen-lib)
LINK_DIRECTORIES(${TensorFlow_DIR}/tensorflow/lite/tools/make/gen/aarch64_armv8-a/lib)

//设置查找头文件的路径
INCLUDE_DIRECTORIES(${OpenCV_DIR}/native/jni/include)
INCLUDE_DIRECTORIES(${TensorFlow_DIR})
INCLUDE_DIRECTORIES(${flat_dir})
INCLUDE_DIRECTORIES(src/main/cpp)

//设置build的library(名称document_lib,share类型,源文件)
add_library(document_lib SHARED
        src/main/cpp/com_sogou_cameratest_ocr_DocumentExtract.c
        src/main/cpp/ImageProcess.cpp
        src/main/cpp/RD.cpp
        )

//设置library 需要链接的第三方库(系统的库log,EGL,NDK里的库 会在NDK路径下查找
target_link_libraries( # Specifies the target library.
        document_lib
                       # Links the target library to the log library
                       # included in the NDK.
        opencv_java3
        tflite_gpu_gl
        rd
        tensorflow-lite
        z
        EGL
        GLESv3
        log
        m
        jnigraphics
        )

//打第二个包
add_library(enhance_lib SHARED
        src/main/cpp/com_sogou_cameratest_ocr_OcrEnhance.c
        src/main/cpp/ImageProcess.cpp
        src/main/cpp/RD.cpp
        )

target_link_libraries( # Specifies the target library.
        enhance_lib
                       # Links the target library to the log library
                       # included in the NDK.
        opencv_java3
        tflite_gpu_gl
        rd
        tensorflow-lite
        z
        EGL
        GLESv3
        log
        m
        jnigraphics
        )

CMakeList在gradle中的配置

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.minSdkVersion
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName "document_lib" //System.loadLibrary("JNITest")
            ldLibs "log"
        }

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
                abiFilters 'arm64-v8a'
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
//            fsdf?
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path 'CMakeLists.txt'
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

你可能感兴趣的:(Android)