From af09260f4a968a8aa57af8054cd0ae25f7aec0d7 Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Fri, 4 Mar 2022 10:56:21 +0000 Subject: [PATCH 1/2] refactor cmake --- speechx/CMakeLists.txt | 82 ++++++++++--------------- speechx/build.sh | 4 +- speechx/cmake/EnableCMP0048.cmake | 1 + speechx/cmake/external/absl.cmake | 11 ++++ speechx/cmake/external/eigen.cmake | 27 ++++++++ speechx/cmake/external/gflags.cmake | 12 ++++ speechx/cmake/external/glog.cmake | 10 +++ speechx/cmake/external/gtest.cmake | 8 +++ speechx/cmake/external/kenlm.cmake | 14 +++++ speechx/cmake/external/libsndfile.cmake | 26 ++++++++ 10 files changed, 144 insertions(+), 51 deletions(-) mode change 100644 => 100755 speechx/build.sh create mode 100644 speechx/cmake/EnableCMP0048.cmake create mode 100644 speechx/cmake/external/absl.cmake create mode 100644 speechx/cmake/external/eigen.cmake create mode 100644 speechx/cmake/external/gflags.cmake create mode 100644 speechx/cmake/external/glog.cmake create mode 100644 speechx/cmake/external/gtest.cmake create mode 100644 speechx/cmake/external/kenlm.cmake create mode 100644 speechx/cmake/external/libsndfile.cmake diff --git a/speechx/CMakeLists.txt b/speechx/CMakeLists.txt index af6582cd..13131adc 100644 --- a/speechx/CMakeLists.txt +++ b/speechx/CMakeLists.txt @@ -2,18 +2,29 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(paddlespeech VERSION 0.1) +set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/EnableCMP0048.cmake") + set(CMAKE_VERBOSE_MAKEFILE on) + # set std-14 set(CMAKE_CXX_STANDARD 14) -# include file +# cmake dir +set(speechx_cmake_dir ${PROJECT_SOURCE_DIR}/cmake) + +# Modules +list(APPEND CMAKE_MODULE_PATH ${speechx_cmake_dir}/external) +list(APPEND CMAKE_MODULE_PATH ${speechx_cmake_dir}) include(FetchContent) include(ExternalProject) + # 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}) +# compiler option +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -fPIC -O0 -Wall -g") ############################################################################### # Option Configurations @@ -25,66 +36,39 @@ option(TEST_DEBUG "option for debug" OFF) ############################################################################### # Include third party ############################################################################### -# #example for include third party -# # FetchContent_MakeAvailable was not added until CMake 3.14 +# example for include third party +# FetchContent_MakeAvailable was not added until CMake 3.14 # FetchContent_MakeAvailable() # include_directories() -# ABSEIL-CPP -include(FetchContent) -FetchContent_Declare( - absl - GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" - GIT_TAG "20210324.1" -) -FetchContent_MakeAvailable(absl) -include_directories(${absl_SOURCE_DIR}) - -# libsndfile -#include(FetchContent) -#FetchContent_Declare( -# libsndfile -# GIT_REPOSITORY "https://github.com/libsndfile/libsndfile.git" -# GIT_TAG "1.0.31" -#) -#FetchContent_MakeAvailable(libsndfile) +# ABSEIL-CPP, need before gtest +include(absl) + +# libsndfile, not work +#include(libsndfile) +# boost set(boost_SOURCE_DIR ${fc_patch}/boost-src) set(BOOST_ROOT ${boost_SOURCE_DIR}) -include(FetchContent) -FetchContent_Declare( - kenlm - GIT_REPOSITORY "https://github.com/kpu/kenlm.git" - GIT_TAG "df2d717e95183f79a90b2fa6e4307083a351ca6a" -) -FetchContent_MakeAvailable(kenlm) -include_directories(${kenlm_SOURCE_DIR}) +#find_package(boost REQUIRED PATHS ${BOOST_ROOT}) + +# Eigen +include(eigen) +find_package(Eigen3 REQUIRED) + +# Kenlm +include(kenlm) +add_dependencies(kenlm eigen boost) + -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -fPIC -O0 -Wall -g") # gflags -FetchContent_Declare( - gflags - URL https://github.com/gflags/gflags/archive/v2.2.1.zip - URL_HASH SHA256=4e44b69e709c826734dbbbd5208f61888a2faf63f239d73d8ba0011b2dccc97a -) -FetchContent_MakeAvailable(gflags) -include_directories(${gflags_BINARY_DIR}/include) +include(gflags) # glog -FetchContent_Declare( - glog - URL https://github.com/google/glog/archive/v0.4.0.zip - URL_HASH SHA256=9e1b54eb2782f53cd8af107ecf08d2ab64b8d0dc2b7f5594472f3bd63ca85cdc -) -FetchContent_MakeAvailable(glog) -include_directories(${glog_BINARY_DIR} ${glog_SOURCE_DIR}/src) +include(glog) # gtest -#FetchContent_Declare(googletest - #URL https://github.com/google/googletest/archive/release-1.10.0.zip - #URL_HASH SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91 -#) -#FetchContent_MakeAvailable(googletest) +#include(gtest) # openfst set(openfst_SOURCE_DIR ${fc_patch}/openfst-src) diff --git a/speechx/build.sh b/speechx/build.sh old mode 100644 new mode 100755 index effdacd0..2f28d8ce --- a/speechx/build.sh +++ b/speechx/build.sh @@ -6,7 +6,7 @@ boost_SOURCE_DIR=$PWD/fc_patch/boost-src if [ ! -d ${boost_SOURCE_DIR} ]; then - wget https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz + wget -c https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz tar xzfv boost_1_75_0.tar.gz mkdir -p $PWD/fc_patch mv boost_1_75_0 ${boost_SOURCE_DIR} @@ -17,7 +17,7 @@ if [ ! -d ${boost_SOURCE_DIR} ]; then echo -e "\n" fi -mkdir build +mkdir -p build cd build cmake .. -DBOOST_ROOT:STRING=${boost_SOURCE_DIR} diff --git a/speechx/cmake/EnableCMP0048.cmake b/speechx/cmake/EnableCMP0048.cmake new file mode 100644 index 00000000..f9afa013 --- /dev/null +++ b/speechx/cmake/EnableCMP0048.cmake @@ -0,0 +1 @@ +cmake_policy(SET CMP0048 NEW) diff --git a/speechx/cmake/external/absl.cmake b/speechx/cmake/external/absl.cmake new file mode 100644 index 00000000..b22e56d8 --- /dev/null +++ b/speechx/cmake/external/absl.cmake @@ -0,0 +1,11 @@ +include(FetchContent) + +FetchContent_Declare( + absl + GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" + GIT_TAG "20210324.1" +) +FetchContent_MakeAvailable(absl) + +set(EIGEN3_INCLUDE_DIR ${Eigen3_SOURCE_DIR}) +include_directories(${absl_SOURCE_DIR}) \ No newline at end of file diff --git a/speechx/cmake/external/eigen.cmake b/speechx/cmake/external/eigen.cmake new file mode 100644 index 00000000..12bd3cdf --- /dev/null +++ b/speechx/cmake/external/eigen.cmake @@ -0,0 +1,27 @@ +include(FetchContent) + +# update eigen to the commit id f612df27 on 03/16/2021 +set(EIGEN_PREFIX_DIR ${fc_patch}/eigen3) + +FetchContent_Declare( + Eigen3 + GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git + GIT_TAG master + PREFIX ${EIGEN_PREFIX_DIR} + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE) + +set(EIGEN_BUILD_DOC OFF) +# note: To disable eigen tests, +# you should put this code in a add_subdirectory to avoid to change +# BUILD_TESTING for your own project too since variables are directory +# scoped +set(BUILD_TESTING OFF) +set(EIGEN_BUILD_PKGCONFIG OFF) +set( OFF) +FetchContent_MakeAvailable(Eigen3) + +message(STATUS "eigen src dir: ${Eigen3_SOURCE_DIR}") +message(STATUS "eigen bin dir: ${Eigen3_BINARY_DIR}") +#include_directories(${Eigen3_SOURCE_DIR}) +#link_directories(${Eigen3_BINARY_DIR}) \ No newline at end of file diff --git a/speechx/cmake/external/gflags.cmake b/speechx/cmake/external/gflags.cmake new file mode 100644 index 00000000..66ae47f7 --- /dev/null +++ b/speechx/cmake/external/gflags.cmake @@ -0,0 +1,12 @@ +include(FetchContent) + +FetchContent_Declare( + gflags + URL https://github.com/gflags/gflags/archive/v2.2.1.zip + URL_HASH SHA256=4e44b69e709c826734dbbbd5208f61888a2faf63f239d73d8ba0011b2dccc97a +) + +FetchContent_MakeAvailable(gflags) + +# openfst need +include_directories(${gflags_BINARY_DIR}/include) \ No newline at end of file diff --git a/speechx/cmake/external/glog.cmake b/speechx/cmake/external/glog.cmake new file mode 100644 index 00000000..7bde9652 --- /dev/null +++ b/speechx/cmake/external/glog.cmake @@ -0,0 +1,10 @@ +include(FetchContent) + +FetchContent_Declare( + glog + URL https://github.com/google/glog/archive/v0.4.0.zip + URL_HASH SHA256=9e1b54eb2782f53cd8af107ecf08d2ab64b8d0dc2b7f5594472f3bd63ca85cdc +) +FetchContent_MakeAvailable(glog) + +include_directories(${glog_BINARY_DIR} ${glog_SOURCE_DIR}/src) diff --git a/speechx/cmake/external/gtest.cmake b/speechx/cmake/external/gtest.cmake new file mode 100644 index 00000000..da6f7cc5 --- /dev/null +++ b/speechx/cmake/external/gtest.cmake @@ -0,0 +1,8 @@ +include(FetchContent) +FetchContent_Declare( + gtest + URL https://github.com/google/googletest/archive/release-1.10.0.zip + URL_HASH SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91 +) +FetchContent_MakeAvailable(gtest) +include_directories(${gtest_BINARY_DIR} ${gtest_SOURCE_DIR}/src) \ No newline at end of file diff --git a/speechx/cmake/external/kenlm.cmake b/speechx/cmake/external/kenlm.cmake new file mode 100644 index 00000000..61f9714b --- /dev/null +++ b/speechx/cmake/external/kenlm.cmake @@ -0,0 +1,14 @@ +include(FetchContent) + +FetchContent_Declare( + kenlm + GIT_REPOSITORY "https://github.com/kpu/kenlm.git" + GIT_TAG "df2d717e95183f79a90b2fa6e4307083a351ca6a" +) + +# https://github.com/kpu/kenlm/blob/master/cmake/modules/FindEigen3.cmake +set(EIGEN3_INCLUDE_DIR ${Eigen3_SOURCE_DIR}) + +FetchContent_MakeAvailable(kenlm) + +include_directories(${kenlm_SOURCE_DIR}) \ No newline at end of file diff --git a/speechx/cmake/external/libsndfile.cmake b/speechx/cmake/external/libsndfile.cmake new file mode 100644 index 00000000..5b30bffe --- /dev/null +++ b/speechx/cmake/external/libsndfile.cmake @@ -0,0 +1,26 @@ +include(FetchContent) + + +set(LIBSNDFILE_GIT_REPO "https://github.com/erikd/libsndfile" CACHE STRING "libsndfile git repository url" FORCE) +set(LIBSNDFILE_GIT_TAG 1.0.31 CACHE STRING "libsndfile git tag" FORCE) + +FetchContent_Declare(libsndfile + GIT_REPOSITORY ${LIBSNDFILE_GIT_REPO} + GIT_TAG ${LIBSNDFILE_GIT_TAG} + CMAKE_ARGS "-G"Unix Makefiles"" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + ) + + +set(BUILD_SHARED_LIBS ON) +FetchContent_MakeAvailable(libsndfile) + + +set(LIBSNDFILE_ROOT_DIR ${libsndfile_SOURCE_DIR}) +set(LIBSNDFILE_INCLUDE_DIR "${libsndfile_BINARY_DIR}/src") + +#file(COPY "${libsndfile_SOURCE_DIR}/src/sndfile.hh" DESTINATION ${LIBSNDFILE_INCLUDE_DIR}) + +include_directories(${LIBSNDFILE_INCLUDE_DIR}) \ No newline at end of file From d7f55e500f5baffb74be6aabe2171c15eacc3a0d Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Fri, 4 Mar 2022 11:47:01 +0000 Subject: [PATCH 2/2] reorder gflags, gtest, glog --- speechx/CMakeLists.txt | 26 +++++++++++++------------- speechx/build.sh | 5 ++--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/speechx/CMakeLists.txt b/speechx/CMakeLists.txt index 13131adc..ffd4c559 100644 --- a/speechx/CMakeLists.txt +++ b/speechx/CMakeLists.txt @@ -24,7 +24,7 @@ get_filename_component(fc_patch "fc_patch" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR set(FETCHCONTENT_BASE_DIR ${fc_patch}) # compiler option -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -fPIC -O0 -Wall -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14 -pthread -fPIC -O0 -Wall -g") ############################################################################### # Option Configurations @@ -41,7 +41,16 @@ option(TEST_DEBUG "option for debug" OFF) # FetchContent_MakeAvailable() # include_directories() -# ABSEIL-CPP, need before gtest +# gflags +include(gflags) + +# glog +include(glog) + +# gtest +include(gtest) + +# ABSEIL-CPP include(absl) # libsndfile, not work @@ -61,15 +70,6 @@ include(kenlm) add_dependencies(kenlm eigen boost) -# gflags -include(gflags) - -# glog -include(glog) - -# gtest -#include(gtest) - # openfst set(openfst_SOURCE_DIR ${fc_patch}/openfst-src) set(openfst_BINARY_DIR ${fc_patch}/openfst-build) @@ -158,8 +158,6 @@ include_directories(${OpenBLAS_INSTALL_PREFIX}/include) # gfortan dir in the docker. link_directories(/usr/local/gcc-8.2/lib64) -add_subdirectory(speechx) - ############################################################################### # Add local library ############################################################################### @@ -171,3 +169,5 @@ add_subdirectory(speechx) #add_library(lib_name STATIC file.cc) #target_link_libraries(lib_name item0 item1) #add_dependencies(lib_name depend-target) + +add_subdirectory(speechx) \ No newline at end of file diff --git a/speechx/build.sh b/speechx/build.sh index 2f28d8ce..a5c93267 100755 --- a/speechx/build.sh +++ b/speechx/build.sh @@ -5,8 +5,7 @@ # https://www.paddlepaddle.org.cn/documentation/docs/zh/install/docker/linux-docker.html boost_SOURCE_DIR=$PWD/fc_patch/boost-src -if [ ! -d ${boost_SOURCE_DIR} ]; then - wget -c https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz +if [ ! -d ${boost_SOURCE_DIR} ]; then wget -c https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz tar xzfv boost_1_75_0.tar.gz mkdir -p $PWD/fc_patch mv boost_1_75_0 ${boost_SOURCE_DIR} @@ -20,7 +19,7 @@ fi mkdir -p build cd build -cmake .. -DBOOST_ROOT:STRING=${boost_SOURCE_DIR} +cmake .. -DBOOST_ROOT:STRING=${boost_SOURCE_DIR} --target clean make