CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. cmake_minimum_required(VERSION 3.16)
  2. project(FunASRWebscoket)
  3. set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
  4. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  5. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  6. option(ENABLE_WEBSOCKET "Whether to build websocket server" ON)
  7. option(ENABLE_PORTAUDIO "Whether to build portaudio" ON)
  8. if(WIN32)
  9. file(REMOVE ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/config.h
  10. ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/glog/export.h
  11. ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/glog/logging.h
  12. ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/glog/raw_logging.h
  13. ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/glog/stl_logging.h
  14. ${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src/glog/vlog_is_on.h)
  15. else()
  16. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fPIC")
  17. endif()
  18. option(ENABLE_GLOG "Whether to build glog" ON)
  19. option(ENABLE_FST "Whether to build openfst" ON) # ITN need openfst compiled
  20. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  21. if(ENABLE_WEBSOCKET)
  22. # cmake_policy(SET CMP0135 NEW)
  23. include(FetchContent)
  24. if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/websocket/websocketpp )
  25. FetchContent_Declare(websocketpp
  26. GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
  27. GIT_TAG 0.8.2
  28. SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/websocket
  29. )
  30. FetchContent_MakeAvailable(websocketpp)
  31. endif()
  32. include_directories(${PROJECT_SOURCE_DIR}/third_party/websocket)
  33. if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/asio/asio )
  34. FetchContent_Declare(asio
  35. URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-24-0.tar.gz
  36. SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/asio
  37. )
  38. FetchContent_MakeAvailable(asio)
  39. endif()
  40. include_directories(${PROJECT_SOURCE_DIR}/third_party/asio/asio/include)
  41. if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third_party/json/ChangeLog.md )
  42. FetchContent_Declare(json
  43. URL https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.tar.gz
  44. SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/json
  45. )
  46. FetchContent_MakeAvailable(json)
  47. endif()
  48. include_directories(${PROJECT_SOURCE_DIR}/third_party/json/include)
  49. endif()
  50. if(ENABLE_PORTAUDIO)
  51. include(FetchContent)
  52. set(portaudio_URL "http://files.portaudio.com/archives/pa_stable_v190700_20210406.tgz")
  53. set(portaudio_URL2 "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/dep_libs/pa_stable_v190700_20210406.tgz")
  54. set(portaudio_HASH "SHA256=47efbf42c77c19a05d22e627d42873e991ec0c1357219c0d74ce6a2948cb2def")
  55. FetchContent_Declare(portaudio
  56. URL
  57. ${portaudio_URL}
  58. ${portaudio_URL2}
  59. URL_HASH ${portaudio_HASH}
  60. )
  61. FetchContent_GetProperties(portaudio)
  62. if(NOT portaudio_POPULATED)
  63. message(STATUS "Downloading portaudio from ${portaudio_URL}")
  64. FetchContent_Populate(portaudio)
  65. endif()
  66. message(STATUS "portaudio is downloaded to ${portaudio_SOURCE_DIR}")
  67. message(STATUS "portaudio's binary dir is ${portaudio_BINARY_DIR}")
  68. add_subdirectory(${portaudio_SOURCE_DIR} ${portaudio_BINARY_DIR} EXCLUDE_FROM_ALL)
  69. if(NOT WIN32)
  70. target_compile_options(portaudio PRIVATE "-Wno-deprecated-declarations")
  71. else()
  72. install(TARGETS portaudio DESTINATION ..)
  73. endif()
  74. endif()
  75. # Include generated *.pb.h files
  76. link_directories(${ONNXRUNTIME_DIR}/lib)
  77. link_directories(${FFMPEG_DIR}/lib)
  78. if(ENABLE_GLOG)
  79. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog/src)
  80. set(BUILD_TESTING OFF)
  81. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/glog glog)
  82. include_directories(${glog_BINARY_DIR})
  83. endif()
  84. if(ENABLE_FST)
  85. # fst depend on glog and gflags
  86. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/gflags)
  87. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/gflags gflags)
  88. include_directories(${gflags_BINARY_DIR}/include)
  89. # the following openfst if cloned from https://github.com/kkm000/openfst.git
  90. # with some patch to fix the make errors.
  91. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/openfst openfst)
  92. include_directories(${openfst_SOURCE_DIR}/src/include)
  93. if(WIN32)
  94. include_directories(${openfst_SOURCE_DIR}/src/lib)
  95. endif()
  96. endif()
  97. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/include/)
  98. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/src)
  99. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/yaml-cpp/include/)
  100. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi-native-fbank)
  101. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/jieba/include)
  102. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/jieba/include/limonp/include)
  103. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party)
  104. include_directories(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi)
  105. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/yaml-cpp yaml-cpp)
  106. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi-native-fbank/kaldi-native-fbank/csrc csrc)
  107. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/src src)
  108. add_subdirectory(${PROJECT_SOURCE_DIR}/../onnxruntime/third_party/kaldi kaldi)
  109. # install openssl first apt-get install libssl-dev
  110. find_package(OpenSSL REQUIRED)
  111. message("CXX_FLAGS "${CMAKE_CXX_FLAGS})
  112. # 获取项目中所有包含文件夹的路径
  113. get_property(includes DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
  114. # 遍历并输出每个包含文件夹的路径
  115. foreach(include ${includes})
  116. message("Include directory: ${include}")
  117. endforeach()
  118. add_subdirectory(bin)