# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# 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

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp)



#设置 库的属性   里面是名称 ，属性：引入地址把我们的真实地址填写进去
# 因为so库是二进制文件，在C++中引进来时需要跟随项目被编译，所以必须放置在src目录下，而不能放在app下的libs
# 中，因为libs下的文件也是需要通过gradle引进来编译的，而CMakeLists是无法引进编译的(libs文件夹下的库是给
# Java项目使用的！)，可知，只有src目录下的代码才会被编译。(可以看到在apk中，libs下的库没有被添加进来，因为
# C++代码根本不会理会libs下的库)

# 高版本gradle中，CMakeLists文件被放到了cpp文件夹下，而在低版本的项目中，CMakeList文件是放在app文件夹下
# 第三方的so库我们在引用时，必须添加到main文件夹下，而不能是cpp文件夹，因为cpp文件夹下的文件都会被编译(猜的，可能是！)，
# 导致的结果是，在Java代码中，我们通过System.loadLibrary时，无法找到对应的so库，所以so应该被放到main文件夹
# 下(通过文件路径来找so库是不可行的，因为通常一个库我们会有多个版本，只能通过库名来找)
# 由于高版本中，CMakeLists文件位于cpp文件夹下，导致我们在CMakeLists中使用保留常量CMAKE_SOURCE_DIR,PROJECT_SOURCE_DIR
# 无法正常定位到so库的文件夹(因为这两个变量都是定位到当前CMakeLists文件位置，也就是位于cpp文件夹下，而jniLibs是与
# cpp文件夹处于同一层级的)。

# 方案1，我们可以将CMakeLists文件移动到app文件夹下，这样就能够使用保留变量进行进行库文件夹的定位(注意，gradle
# 中CMakeLists文件的配置也必须修改)。

# 方案2，采用绝对路径来定位库文件的位置(这种做法不利于项目的移植！)。

add_library(libfmod
        SHARED
        IMPORTED)
set_target_properties(libfmod
        PROPERTIES IMPORTED_LOCATION
        # 采用绝对路径定位库文件
        H:/ndk_workplace/QQ_Voicer/app/src/main/jniLibs/${ANDROID_ABI}/libfmod.so)

add_library(libfmodL
        SHARED
        IMPORTED)
set_target_properties(libfmodL
        PROPERTIES IMPORTED_LOCATION
        H:/ndk_workplace/QQ_Voicer/app/src/main/jniLibs/${ANDROID_ABI}/libfmodL.so)

include_directories(inc)

# 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.
        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
        libfmod
        libfmodL
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})