创建 CMake 构建脚本CMakeLists.txt

2017-06-21  本文已影响0人  ChiangCMBA

1.add_library

Normal Libraries

Imported Libraries

Object Libraries

Alias Libraries

Interface Libraries

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当前的工程地址

#添加静态链接库

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 )


#添加动态库

add_library(opencv_java SHARED IMPORTED)

#设置导入的路径

set_target_properties(opencv_java PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)

#添加原生库

add_library(Live SHARED  src/main/cpp/Live.c  src/main/cpp/queue.c)

#指定标头(.h文件)的路径

include_directories(src/main/cpp src/main/cpp/faac/include/ src/main/cpp/rtmpdump/include/ src/main/cpp/x264/include/)

#find_library定位 NDK 库,并将其路径存储为一个变量。定位Android 特定的日志支持库并将其路径存储在log-lib

find_library(log-lib log)

#要将预构建库关联到自己的原生库Live

target_link_libraries( Live x264 faac rtmpdump ${log-lib})

#最终生成:libLive.so

上一篇下一篇

猜你喜欢

热点阅读