CMakeLists.txt 4.1 KB
Newer Older
H
Hui Zhang 已提交
1 2
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

3
project(paddlespeech VERSION 0.1)
H
Hui Zhang 已提交
4

H
Hui Zhang 已提交
5 6
set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/EnableCMP0048.cmake")

H
Hui Zhang 已提交
7
set(CMAKE_VERBOSE_MAKEFILE on)
H
Hui Zhang 已提交
8

H
Hui Zhang 已提交
9 10 11
# set std-14
set(CMAKE_CXX_STANDARD 14)

H
Hui Zhang 已提交
12 13 14 15 16
# cmake dir
set(speechx_cmake_dir ${PROJECT_SOURCE_DIR}/cmake)

# Modules
list(APPEND CMAKE_MODULE_PATH ${speechx_cmake_dir})
H
Hui Zhang 已提交
17 18
include(FetchContent)
include(ExternalProject)
H
Hui Zhang 已提交
19

H
Hui Zhang 已提交
20 21 22 23 24
# fc_patch dir
set(FETCHCONTENT_QUIET off)
get_filename_component(fc_patch "fc_patch" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
set(FETCHCONTENT_BASE_DIR ${fc_patch})

H
Hui Zhang 已提交
25
# compiler option
H
Hui Zhang 已提交
26
# Keep the same with openfst, -fPIC or -fpic
H
Hui Zhang 已提交
27
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14 -pthread -fPIC -O0 -Wall -g")
H
Hui Zhang 已提交
28 29 30
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} --std=c++14 -pthread -fPIC -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} --std=c++14 -pthread -fPIC -O3 -Wall")

H
Hui Zhang 已提交
31 32 33 34
###############################################################################
# Option Configurations
###############################################################################
option(TEST_DEBUG "option for debug" OFF)
35
option(USE_PROFILING "enable c++ profling" OFF)
H
Hui Zhang 已提交
36

37 38 39 40
option(USING_U2  "compile u2 model." ON)
option(USING_DS2 "compile with ds2 model." ON)

option(USING_GPU "u2 compute on GPU." OFF)
H
Hui Zhang 已提交
41 42 43 44

###############################################################################
# Include third party
###############################################################################
H
Hui Zhang 已提交
45 46
# example for include third party
# FetchContent_MakeAvailable was not added until CMake 3.14
H
Hui Zhang 已提交
47 48 49
# FetchContent_MakeAvailable()
# include_directories()

H
Hui Zhang 已提交
50 51 52 53 54 55 56 57 58 59
# gflags
include(gflags)

# glog
include(glog)

# gtest
include(gtest)

# ABSEIL-CPP
H
Hui Zhang 已提交
60
include(absl)
S
SmileGoat 已提交
61

H
Hui Zhang 已提交
62 63
# libsndfile
include(libsndfile)
H
Hui Zhang 已提交
64 65

# boost
H
Hui Zhang 已提交
66
# include(boost) # not work
S
SmileGoat 已提交
67 68
set(boost_SOURCE_DIR ${fc_patch}/boost-src)
set(BOOST_ROOT ${boost_SOURCE_DIR})
Y
Yang Zhou 已提交
69 70
include_directories(${boost_SOURCE_DIR})
link_directories(${boost_SOURCE_DIR}/stage/lib)
H
Hui Zhang 已提交
71 72 73 74 75 76 77 78 79

# Eigen
include(eigen)
find_package(Eigen3 REQUIRED)

# Kenlm
include(kenlm)
add_dependencies(kenlm eigen boost)

80 81
#openblas
include(openblas)
H
Hui Zhang 已提交
82

83
# openfst
H
Hui Zhang 已提交
84
include(openfst)
85
add_dependencies(openfst gflags glog)
86 87


S
SmileGoat 已提交
88
# paddle lib
H
Hui Zhang 已提交
89
include(paddleinference)
H
Hui Zhang 已提交
90

S
SmileGoat 已提交
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
# paddle core.so
find_package(Threads REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(Python3 REQUIRED)
find_package(pybind11 CONFIG)

message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "Python3_EXECUTABLE = ${Python3_EXECUTABLE}")
message(STATUS "Pybind11_INCLUDES = ${pybind11_INCLUDE_DIRS}, pybind11_LIBRARIES=${pybind11_LIBRARIES}, pybind11_DEFINITIONS=${pybind11_DEFINITIONS}")

# paddle include and link option
execute_process(
    COMMAND python -c "import paddle ; print(' '.join(paddle.sysconfig.get_link_flags()), end='')"
    OUTPUT_VARIABLE PADDLE_LINK_FLAGS
    RESULT_VARIABLE SUCESS)

message(STATUS PADDLE_LINK_FLAGS= ${PADDLE_LINK_FLAGS})
string(STRIP ${PADDLE_LINK_FLAGS} PADDLE_LINK_FLAGS)

# paddle compile option
execute_process(
    COMMAND python -c "import paddle ; print(' '.join(paddle.sysconfig.get_compile_flags()), end='')"
    OUTPUT_VARIABLE PADDLE_COMPILE_FLAGS)
message(STATUS PADDLE_COMPILE_FLAGS= ${PADDLE_COMPILE_FLAGS})
string(STRIP ${PADDLE_COMPILE_FLAGS} PADDLE_COMPILE_FLAGS)


# for LD_LIBRARY_PATH
# set(PADDLE_LIB_DIRS /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages/paddle/fluid:/workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages/paddle/libs/)
execute_process(
    COMMAND python -c "import paddle ; print(':'.join(paddle.sysconfig.get_lib()), end='')"
    OUTPUT_VARIABLE PADDLE_LIB_DIRS)
message(STATUS PADDLE_LIB_DIRS= ${PADDLE_LIB_DIRS})


H
Hui Zhang 已提交
127 128 129 130
###############################################################################
# Add local library
###############################################################################
# system lib 
Z
zhouyang 已提交
131
#find_package()
H
Hui Zhang 已提交
132
# if dir have CmakeLists.txt 
Z
zhouyang 已提交
133
#add_subdirectory(speechx)
H
Hui Zhang 已提交
134
# if dir do not have CmakeLists.txt 
Z
zhouyang 已提交
135 136
#add_library(lib_name STATIC file.cc)
#target_link_libraries(lib_name item0 item1)
S
SmileGoat 已提交
137
#add_dependencies(lib_name depend-target)
H
Hui Zhang 已提交
138

H
Hui Zhang 已提交
139 140 141
set(SPEECHX_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/speechx)

add_subdirectory(speechx)