From 580b11b57ac4b62f7e2acda73813a4e10e8e4cd3 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期二, 10 十月 2023 17:17:29 +0800
Subject: [PATCH] v0.8.0

---
 funasr/runtime/websocket/CMakeLists.txt |   95 +++++++++++++++++++++++++++++++----------------
 1 files changed, 62 insertions(+), 33 deletions(-)

diff --git a/funasr/runtime/websocket/CMakeLists.txt b/funasr/runtime/websocket/CMakeLists.txt
index d975a85..7291172 100644
--- a/funasr/runtime/websocket/CMakeLists.txt
+++ b/funasr/runtime/websocket/CMakeLists.txt
@@ -7,34 +7,46 @@
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
 
 option(ENABLE_WEBSOCKET "Whether to build websocket server" ON)
-option(ENABLE_PORTAUDIO "Whether to build websocket server" ON)
+option(ENABLE_PORTAUDIO "Whether to build portaudio" ON)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fPIC")
+option(ENABLE_GLOG "Whether to build glog" ON)
+option(ENABLE_FST "Whether to build openfst" ON) # ITN need openfst compiled
+option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  
 if(ENABLE_WEBSOCKET)
   # cmake_policy(SET CMP0135 NEW)
   include(FetchContent)
-  FetchContent_Declare(websocketpp
-  GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
-    GIT_TAG 0.8.2
-    SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/websocket
-    )
-  
-  FetchContent_MakeAvailable(websocketpp)
+
+  if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/websocket )
+    FetchContent_Declare(websocketpp
+    GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
+      GIT_TAG 0.8.2
+      SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/websocket
+      )
+    
+    FetchContent_MakeAvailable(websocketpp)
+  endif()
   include_directories(${PROJECT_SOURCE_DIR}/third_party/websocket)
    
-  FetchContent_Declare(asio
-     URL   https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-24-0.tar.gz
-   SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/asio
-  )
-  
-  FetchContent_MakeAvailable(asio)
+  if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/asio )
+    FetchContent_Declare(asio
+      URL   https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-24-0.tar.gz
+    SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/asio
+    )
+    
+    FetchContent_MakeAvailable(asio)
+  endif()
   include_directories(${PROJECT_SOURCE_DIR}/third_party/asio/asio/include)
  
-  FetchContent_Declare(json
-     URL   https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.tar.gz
-   SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/json
-  )
-  
-  FetchContent_MakeAvailable(json)
+  if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/json )
+    FetchContent_Declare(json
+      URL   https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.tar.gz
+    SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/json
+    )
+    
+    FetchContent_MakeAvailable(json)
+  endif()
   include_directories(${PROJECT_SOURCE_DIR}/third_party/json/include)
 
 endif()
@@ -74,6 +86,28 @@
 link_directories(${ONNXRUNTIME_DIR}/lib)
 link_directories(${FFMPEG_DIR}/lib)
 
+if(ENABLE_GLOG)
+    include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src)
+    set(BUILD_TESTING OFF)
+    add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog glog)
+    include_directories(${glog_BINARY_DIR})
+
+endif()
+
+if(ENABLE_FST)
+    # fst depend on glog and gflags
+    include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/gflags)
+    add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/gflags gflags)
+    include_directories(${gflags_BINARY_DIR}/include)
+      
+    # the following openfst if cloned from https://github.com/kkm000/openfst.git
+    # with some patch to fix the make errors. 
+    add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/openfst openfst)
+    include_directories(${openfst_SOURCE_DIR}/src/include)
+    
+endif()
+
+
 include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/include/)
 include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/yaml-cpp/include/)
 include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi-native-fbank)
@@ -82,20 +116,15 @@
 add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi-native-fbank/kaldi-native-fbank/csrc csrc)
 add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/src src)
 
-include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog)
-set(BUILD_TESTING OFF)
-add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog glog)
-
 # install openssl first apt-get install libssl-dev
 find_package(OpenSSL REQUIRED)
 
-#message("CXX_FLAGS "${CMAKE_CXX_FLAGS})
-add_executable(funasr-wss-server "funasr-wss-server.cpp" "websocket-server.cpp")
-add_executable(funasr-wss-server-2pass "funasr-wss-server-2pass.cpp" "websocket-server-2pass.cpp")
-add_executable(funasr-wss-client "funasr-wss-client.cpp")
-add_executable(funasr-wss-client-2pass "funasr-wss-client-2pass.cpp" "microphone.cpp")
+message("CXX_FLAGS "${CMAKE_CXX_FLAGS})
+# 鑾峰彇椤圭洰涓墍鏈夊寘鍚枃浠跺す鐨勮矾寰�
+get_property(includes DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
+# 閬嶅巻骞惰緭鍑烘瘡涓寘鍚枃浠跺す鐨勮矾寰�
+foreach(include ${includes})
+  message("Include directory: ${include}")
+endforeach()
 
-target_link_libraries(funasr-wss-client PUBLIC funasr ssl crypto)
-target_link_libraries(funasr-wss-client-2pass PUBLIC funasr ssl crypto portaudio)
-target_link_libraries(funasr-wss-server PUBLIC funasr ssl crypto)
-target_link_libraries(funasr-wss-server-2pass PUBLIC funasr ssl crypto)
+add_subdirectory(bin)

--
Gitblit v1.9.1