cmake_minimum_required(VERSION 3.4.1)##---指定cmake的最小版本
set(TARGET wenet)##---将字符串wenet 副给TARGET
project(${TARGET} CXX)##---指定工程名字,和语言,cxx代表c++
set(CMAKE_CXX_STANDARD 14)##---
include(ExternalProject)
##--CMAKE_SOURCE_DIR工程顶层目录
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/kaldi # for not changing c++ header names in kaldi source files
) ##--添加头文件搜索路径,可添加多个地址
set(CMAKE_VERBOSE_MAKEFILE on) ##---显示执行构建过程中详细的信息(比如为了得到更详细的出错信息)
set(build_DIR ${CMAKE_SOURCE_DIR}/../../../build)
string(REPLACE "-Wl,--exclude-libs,libgcc_real.a" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
##--将${CMAKE_EXE_LINKER_FLAGS}中的"-Wl,--exclude-libs,libgcc_real.a"替换为"", 并赋值给CMAKE_EXE_LINKER_FLAGS
set(openfst_BINARY_DIR ${build_DIR}/wenet-openfst-android-1.0.1.aar/jni)
include_directories(${openfst_BINARY_DIR}/include)##--添加头文件搜索路径,可添加多个地址
link_directories(${openfst_BINARY_DIR}/${ANDROID_ABI})##--向工程添加多个特定的库文件搜索路径
link_libraries(log gflags_nothreads glog fst)##--Link libraries to all targets added later. 上一步添加了库的搜索路径,这一步将log fst等链接到targets
# Pytorch
file(GLOB PYTORCH_INCLUDE_DIRS "${build_DIR}/pytorch_android*.aar/headers") ##--Generate a list of files that match the "${build_DIR}/pytorch_android*.aar/headers" and store it into the PYTORCH_INCLUDE_DIRS
file(GLOB PYTORCH_LINK_DIRS "${build_DIR}/pytorch_android*.aar/jni/${ANDROID_ABI}")
find_library(PYTORCH_LIBRARY pytorch_jni
PATHS ${PYTORCH_LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH
)###--This command is used to find a library. A cache entry, or a normal variable if NO_CACHE is specified, named by <VAR> is created to store the result of this command.
find_library(FBJNI_LIBRARY fbjni
PATHS ${PYTORCH_LINK_DIRS} ##-- PATHS Specify directories to search in addition to the default locations.
NO_CMAKE_FIND_ROOT_PATH##--Do not use the CMAKE_FIND_ROOT_PATH variable.
)
include_directories(
${PYTORCH_INCLUDE_DIRS}
${PYTORCH_INCLUDE_DIRS}/torch/csrc/api/include
)##--添加头文件搜索路径
# utils
add_library(utils STATIC
utils/string.cc
utils/utils.cc
)##--生成静态库文件
# frontend
add_library(frontend STATIC
frontend/feature_pipeline.cc
frontend/fft.cc
)##--生成静态库文件
target_link_libraries(frontend PUBLIC utils)##--为frontend添加需要链接的共享库utils
# kaldi: wfst based decoder
add_subdirectory(kaldi)##--向当前工程添加存放源文件的子目录,并编译子目录中的CMakeLists.txt。 子目录CMakeLists.txt生成的库 能直接在本CMakeLists.txt中使用
# decoder
add_library(decoder STATIC
decoder/context_graph.cc
decoder/ctc_endpoint.cc
decoder/ctc_prefix_beam_search.cc
decoder/ctc_wfst_beam_search.cc
decoder/torch_asr_decoder.cc
decoder/torch_asr_model.cc
post_processor/post_processor.cc
)##--生成静态库文件
target_link_libraries(decoder PUBLIC kaldi-decoder utils ${PYTORCH_LIBRARY} ${FBJNI_LIBRARY})##--为decoder添加需要链接的共享库,,kaldi-decoder是由add_subdirectory(kaldi)生成的库
## link_libraries():Specify libraries or flags to use when linking any targets created later in the current directory or below by commands such as add_executable() or add_library().
link_libraries(utils frontend decoder android)##--Link libraries to all targets added later.
add_library(${TARGET} SHARED wenet.cc)##--生成动态库文件
add_executable(decoder_main bin/decoder_main.cc) ##--生成可执行文件
target_link_libraries(decoder_main PUBLIC libc++_shared.so)##--为decoder_main添加需要链接的共享库