From 52732ed07fa453fe9d4d3bbeaba54165a9d0b336 Mon Sep 17 00:00:00 2001 From: xiemingxian <623158663@qq.com> Date: Thu, 9 May 2024 10:56:29 +0800 Subject: [PATCH] 2024-05-09 --- CMakeLists.txt | 5 +---- cmake-local/gflags.cmake | 21 +++++++++++++-------- cmake-local/glog.cmake | 15 ++++++++++++--- cmake-local/openfst.cmake | 13 ++++++++----- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bef488..3436311 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,7 @@ set(Red "${Esc}[31m") include(FetchContent) set(FETCHCONTENT_QUIET OFF) set(third_party_libraries) - - -message(STATUS 111) -set(LIB_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib_files) +set(LIB_BASE_DIR /root/projects/temp_xiaoke/asr_runtime/lib_files) set(FETCHCONTENT_BASE_DIR ${LIB_BASE_DIR}) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-local) diff --git a/cmake-local/gflags.cmake b/cmake-local/gflags.cmake index db7a0e5..750073c 100644 --- a/cmake-local/gflags.cmake +++ b/cmake-local/gflags.cmake @@ -1,12 +1,17 @@ -#FetchContent_Declare(gflags -# SOURCE_DIR ${LIB_BASE_DIR}/gflags-src) -#FetchContent_MakeAvailable(gflags) -# -#include_directories(${gflags_BINARY_DIR}/include) - - set(GFLAGS_ROOT_DIR ${LIB_BASE_DIR}/gflags-src) +set(GFLAGS_BUILD_DIR ${LIB_BASE_DIR}/gflags-build) +if(NOT EXISTS ${GLOG_BUILD_DIR}) + execute_process( + COMMAND mkdir ${GLOG_BUILD_DIR} && cmake -S ${GLOG_ROOT_DIR} -B ${GLOG_BUILD_DIR} + WORKING_DIRECTORY ${LIB_BASE_DIR}) + execute_process( + COMMAND cmake --build . -j4 + WORKING_DIRECTORY ${GLOG_BUILD_DIR}) +endif() + +set(GFLAGS_ROOT_DIR ${LIB_BASE_DIR}/gflags-build) find_package(gflags REQUIRED CONFIG HINTS ${GFLAGS_ROOT_DIR}) set(GFLAGS_INCLUDE_DIR ${LIB_BASE_DIR}/gflags-build/include) -list(APPEND third_party_libraries gflags) \ No newline at end of file +list(APPEND third_party_libraries gflags) +message(STATUS gflags_FOUND) \ No newline at end of file diff --git a/cmake-local/glog.cmake b/cmake-local/glog.cmake index 5c5dfd3..16db8c2 100644 --- a/cmake-local/glog.cmake +++ b/cmake-local/glog.cmake @@ -1,10 +1,19 @@ #find_package(glog REQUIRED) #list(APPEND third_party_libraries glog::glog) #在/usr/bin目录里面 我需要clion自动关联里面的库,有好几个库的 -set(GLOG_ROOT_DIR /root/projects/temp_xiaoke/asr_runtime/lib_files/glog-build) -find_package(glog REQUIRED CONFIG PATHS ${GLOG_ROOT_DIR}) +set(GLOG_ROOT_DIR ${LIB_BASE_DIR}/glog-src) +set(GLOG_BUILD_DIR ${LIB_BASE_DIR}/glog-build) +if(NOT EXISTS ${GLOG_BUILD_DIR}) + execute_process( + COMMAND mkdir ${GLOG_BUILD_DIR} && cmake -S ${GLOG_ROOT_DIR} -B ${GLOG_BUILD_DIR} + WORKING_DIRECTORY ${LIB_BASE_DIR}) + execute_process( + COMMAND cmake --build . -j4 + WORKING_DIRECTORY ${GLOG_BUILD_DIR}) +endif() + +include_directories(GLOG_BUILD_DIR) -set(GLOG_INCLUDE_DIR ${GLOG_ROOT_DIR}/include) # glog::glog is imported target list(APPEND third_party_libraries glog) \ No newline at end of file diff --git a/cmake-local/openfst.cmake b/cmake-local/openfst.cmake index d620910..8d261d3 100644 --- a/cmake-local/openfst.cmake +++ b/cmake-local/openfst.cmake @@ -1,6 +1,6 @@ # We can't build glog with gflags, unless gflags is pre-installed. # If build glog with pre-installed gflags, there will be conflict. -message(STATUS "${BoldGreen}CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}${ColourReset}") + set(openfst_BUILD "${LIB_BASE_DIR}/openfst-build") if(NOT EXISTS ${openfst_BUILD}) @@ -24,13 +24,14 @@ endif() # We can't build glog with gflags, unless gflags is pre-installed. # If build glog with pre-installed gflags, there will be conflict. # gflags和glog现在被我安装到了系统盘下/usr/lib/x86_64-linux-gnu -find_package(gflags) +include(gflags) if(TARGET gflags) - message(STATUS "${BoldGreen}TARGET: ${gflags_FOUND}${ColourReset}") + message(STATUS "${BoldGreen}Find Package gflags: ${gflags_FOUND}${ColourReset}") set_target_properties(gflags PROPERTIES INTERFACE_COMPILE_OPTIONS "-fPIC") endif() set(WITH_GFLAGS OFF CACHE BOOL "whether build glog with gflags" FORCE) -include(cmake-local/glog.cmake) +find_package(glog) +message(STATUS "${BoldGreen}Find Package glog: ${glog_FOUND}${ColourReset}") # 下面这堆关键字是防止cmake出一堆无关的提示 if(NOT GRAPH_TOOLS) set(HAVE_BIN OFF CACHE BOOL "Build the fst binaries" FORCE) @@ -52,9 +53,11 @@ FetchContent_Declare(openfst FetchContent_MakeAvailable(openfst) include_directories(${LIB_BASE_DIR}/openfst-src/src/include) + message(STATUS "${BoldGreen}openfst_BINARY_DIR: ${openfst_BINARY_DIR}${ColourReset}") -add_dependencies(fst gflags glog) +add_dependencies(fst gflags glog::glog) + target_link_libraries(fst PUBLIC gflags_nothreads_static glog) list(APPEND third_party_libraries fst) \ No newline at end of file