1. 程式人生 > >cmakelist.txt配置

cmakelist.txt配置

設定cmake的最小使用版本,camke_minimum_required(VERSION 3.4.1)

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# 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.

add_library( # Sets the name of the library.
        native-lib //這是so庫的名稱

        # Sets the library as a shared library.
        SHARED // 靜態庫 MODULE就是模組庫

        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp  //這裡是so庫的原始檔路徑 可以使用萬用字元)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.


find_library( # Sets the name of the path variable. // find_library 這個一般是系統庫,放在這個命令裡面的不會被打包到我們的apk裡面
        log-lib //庫的特定位置 log庫放在log-lib中


        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log //指定使用的庫
        )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library. //本地庫(自己的庫native-lib)想要呼叫log庫的方法,就要在以下命令進行關聯

        native-lib

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib}  //要關聯的庫,要使用的庫)