1.add_library
Normal Libraries
add_library(]]> [STATIC | SHARED | MODULE]
[EXCLUDE_FROM_ALL]
source1 [source2 …])
Imported Libraries
add_library( ]]> IMPORTED
[GLOBAL])
ObjectLibraries
add_library(]]> OBJECT …)
Alias Libraries
add_library( ALIAS ]]>)
Interface Libraries
add_library(]]> INTERFACE [IMPORTED [GLOBAL]])
2.find_library
find_library ( name1 [path1 path2 …])
find_library (
name | NAMES name1 [name2 ...] [NAMES_PER_DIR]
[HINTS path1 [path2 ... ENV var]]
[PATHS path1 [path2 ... ENV var]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_PACKAGE_ROOT_PATH]
[NO_CMAKE_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH]
)
3.target_link_libraries
target_link_libraries(]]> ... ... …)
4.include_directories
include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 …])
5.set_target_properties
set_target_properties(target1 target2 ...
PROPERTIES prop1 value1
prop2 value2 …)
===============================================
set(PROJECT_DIR /Users/m/Documents/Live/app)
#${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR是Cmake提供的變量,代表cmakt.txt當(dāng)前的工程地址
#添加靜態(tài)鏈接庫(kù)
add_library(x264 STATIC IMPORTED)
set_target_properties(x264 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/libx264.a )
add_library(faac STATIC IMPORTED)
set_target_properties(faac PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/libfaac.a )
add_library(rtmpdump STATIC IMPORTED)
set_target_properties(rtmpdump PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/librtmp.a )
#添加動(dòng)態(tài)庫(kù)
add_library(opencv_java SHARED IMPORTED)
#設(shè)置導(dǎo)入的路徑
set_target_properties(opencv_java PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
#添加原生庫(kù)
add_library(Live SHARED? src/main/cpp/Live.c? src/main/cpp/queue.c)
#指定標(biāo)頭(.h文件)的路徑
include_directories(src/main/cpp src/main/cpp/faac/include/ src/main/cpp/rtmpdump/include/ src/main/cpp/x264/include/)
#find_library定位 NDK 庫(kù)饼问,并將其路徑存儲(chǔ)為一個(gè)變量影兽。定位Android 特定的日志支持庫(kù)并將其路徑存儲(chǔ)在log-lib
find_library(log-lib log)
#要將預(yù)構(gòu)建庫(kù)關(guān)聯(lián)到自己的原生庫(kù)Live
target_link_libraries( Live x264 faac rtmpdump ${log-lib})
#最終生成:libLive.so