注意:CMakeList文件中根路径是 CMakeList.txt文件所在的目录
cmake_minimum_required(VERSION 3.10.2)
# Declares and names the project.
project("ndk_01")
#显示执行构建过程中详细的信息
set(CMAKE_VERBOSE_MAKEFILE on)
#打印日志
message("CMAKE_ANDROID_ARCH_ABI:${CMAKE_ANDROID_ARCH_ABI}")
#命令,并包含 头文件的路
include_directories(src/main/cpp/include)
#定义全局的file 引入c c++资源
#file(GLOB source src/main/cpp/*.c src/main/cpp/*.cpp)
#引入c C++资源
aux_source_directory(src/main/cpp source)
#SHARED 动态库 STATIC 静态库
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).
${source})
##如果有多个 需要写多个
##引入静态库或者动态库
##引入静态库
##IMPORTED:表示我们这一个静态库是以导入的形式添加进来(预编译静态库)
#add_library(
# avutil
# STATIC
# IMPORTED)
###怎么导入 设置导入的路径
###设置目标属性方法
###设置test的导入路径属性
###CMAKE_SOURCE_DIR 当前cmakelists.txt的路径(cmake工具内置的)
#set_target_properties(
# avutil
# PROPERTIES IMPORTED_LOCATION
# ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libavutil.a)
#和Makefile不同,cmake有其他办法引入库,
#-L:库的查找路径 libavcodec.a
# 设置链接库 查找的位置
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/src/main/jniLibs/${CMAKE_ANDROID_ARCH_ABI}")
#链接(不能换位置)
#要生成的目标so库
#编译native-lib模块,需要链接(依赖)avcodec模块
target_link_libraries( # Specifies the target library.
native-lib
avutil
# Links the target library to the log library
# included in the NDK.
log)
cmake_minimum_required(VERSION 3.10.2)
project("ndk")
#显示执行构建过程中详细的信息
set(CMAKE_VERBOSE_MAKEFILE on)
#打印日志
message("CMAKE_ANDROID_ARCH_ABI:${CMAKE_ANDROID_ARCH_ABI}")
#命令,并包含 头文件的路
include_directories(${CMAKE_SOURCE_DIR}/include)
#定义全局的file 引入c c++资源
#file(GLOB source src/main/cpp/*.c src/main/cpp/*.cpp)
#引入c C++资源
# 查找cpp目录下的所有源文件
# 并将名称保存到 source 变量
aux_source_directory(${CMAKE_SOURCE_DIR} source)
#SHARED 动态库 STATIC 静态库
add_library( # Sets the name of the library.
ndk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${source})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}")
find_library( # Sets the name of the path variable.
log-lib
log )
target_link_libraries(
ndk
avcodec avfilter avformat avutil swresample swscale
${log-lib}