Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将Flite包含在C++;与cmake合作的项目?_C++_Cmake_Include_Ubuntu 16.04_Flite - Fatal编程技术网

C++ 如何将Flite包含在C++;与cmake合作的项目?

C++ 如何将Flite包含在C++;与cmake合作的项目?,c++,cmake,include,ubuntu-16.04,flite,C++,Cmake,Include,Ubuntu 16.04,Flite,我必须在我的应用程序中使用TTS引擎,我尝试使用Flite。 我已经从命令行安装并测试了它,但当我试图把它放到我的应用程序中时,我无法让它工作。我已经在网上搜索过了,但没有成功,因为大多数说明都是针对windows或android的。我也知道Barath Kannan的C++包装器,但它需要C++ 17,现在我不能使用它。 我在Ubuntu 16.04上使用C++11 这是我的密码: TTSFliteManager:(使用Flite的类) 查看文档中的示例,我知道我的项目中缺少了几个库(“-lf

我必须在我的应用程序中使用TTS引擎,我尝试使用Flite。 我已经从命令行安装并测试了它,但当我试图把它放到我的应用程序中时,我无法让它工作。我已经在网上搜索过了,但没有成功,因为大多数说明都是针对windows或android的。我也知道Barath Kannan的C++包装器,但它需要C++ 17,现在我不能使用它。 我在Ubuntu 16.04上使用C++11

这是我的密码:

TTSFliteManager:(使用Flite的类)

查看文档中的示例,我知道我的项目中缺少了几个库(“-lflite\u cmu\u us\u kal”“-lflite\u usenglish”“-lflite\u cmulex”“-lflite”“-lm”)

我应该使用“查找包”吗?“包含目录”?如果是这样的话,让它工作的合适参数是什么?我使用的(Flite,flitedl)返回了一个错误,表明找不到这样的包

我相信我需要正确地配置CMakeLists,但我不知道在那里写些什么来让项目看到flite库

编辑

插件CMakeList:

set(PLUGSOURCECD_DIR "$ENV{DEV_ROOT}/Plugin/ModPlugin")
set(PLUGSOURCEMD_DIR "$ENV{DEV_ROOT}/src/")
set(PLUGSOURCEAWT_DIR "$ENV{DEV_ROOT}/AWT/sources")
set(PLUG_DIR "$ENV{DEV_ROOT}/Plugin")
include( "$ENV{CMAKE_ADDITIONAL_MODULES_DIR}/CommonRules.cmake" )

MESSAGE("Dir = ${PLUGSOURCECD_DIR}")
MESSAGE("CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")


IF(WIN32)

    IF(NOT CMAKE_DEBUG_POSTFIX)
      set(CMAKE_DEBUG_POSTFIX d)
    ENDIF()
    if(POLICY CMP0020)
      cmake_policy(SET CMP0020 NEW)
    endif()
    if(POLICY CMP0074)
      cmake_policy(SET CMP0074 NEW)
    endif()
    if(POLICY CMP0011)
      cmake_policy(SET CMP0011 NEW)
    endif()
ENDIF()

IF(CMAKE_SOURCE_DIR STREQUAL PLUGSOURCECD_DIR)

# CMake compatibility issues.
cmake_minimum_required(VERSION 2.8)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
project(modPlugin)
#include( "Project.cmake" )

include( "Target.cmake" )

find_package(Qt5 5.8 COMPONENTS Widgets Multimedia MultimediaWidgets REQUIRED)
# The Qt5Widgets_INCLUDES also includes the include directories for
  # dependencies QtCore and QtGui
  include_directories(${Qt5Widgets_INCLUDE_DIRS})
    MESSAGE("QT Qt5Widgets_INCLUDES = ${Qt5Widgets_INCLUDE_DIRS}")
  # We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
  add_definitions(${Qt5Widgets_DEFINITIONS})
set(QT_LIBRARIES 
    Qt5::Gui Qt5::Core Qt5::Multimedia Qt5::MultimediaWidgets )
MESSAGE("QT5LIB = ${QT_LIBRARIES}")
set(QT_CLILIBRARIES ${QT_LIBRARIES})

ENDIF(CMAKE_SOURCE_DIR STREQUAL PLUGSOURCECD_DIR)

# LiquidSDR
find_package(liquiddsp REQUIRED)
include_directories(${liquiddsp_INCLUDE_DIR})
MESSAGE("LiquidDSP = ${liquiddsp_LIBRARY}")
MESSAGE("LiquidDSP include = ${liquiddsp_INCLUDE_DIR}")

INCLUDE_DIRECTORIES(${PLUGSOURCECD_DIR})


set(PCDSOURCES
#list of .cpp files
...
    ${PLUGSOURCECD_DIR}/sources/TTSFliteManager.cpp
...
        )     

set(PCDHEADER
#list of .h files
...
    ${PLUGSOURCECD_DIR}/sources/TTSFliteManager.h
...
        )               

set ( UIS
lust of .ui files
...
)

set(CMAKE_AUTORCC ON)
SET(CMAKE_AUTOUIC ON)

QT5_WRAP_CPP(PLUGINTMOCCD_SOURCES ${PCDHEADER})
QT5_WRAP_UI( UI_HEADERS ${UIS} )
set(PLUGIN_DIR "${CMAKE_BINARY_DIR}/plugins")

file(MAKE_DIRECTORY ${PLUGIN_DIR})

MESSAGE("Source = ${PCDSOURCES}")
set(modPlugin_LIBRARIES modPlugin)
add_library(${modPlugin_LIBRARIES} SHARED ${PCDSOURCES} ${PLUGINTMOCCD_SOURCES} ${UI_HEADERS})

target_link_libraries( 
    ${modPlugin_LIBRARIES} 
    ${gui_LIBRARIES} 
    ${QT_LIBRARIES}  
    ${liquiddsp_LIBRARY}
)

add_custom_command(TARGET ${modPlugin_LIBRARIES} 
                   POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${modPlugin_LIBRARIES}> ${PLUGIN_DIR})
# CMake compatibility issues.
cmake_minimum_required(VERSION 2.6)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)

PROJECT(SSTUDIO)

include(Target.cmake)

INCLUDE(Project.cmake)

SET(BUILD_SHARED_LIBS "true")
set(SMSSTYLEDIR "$ENV{DEV_ROOT}/styles")
IF(BUILD_SHARED_LIBS)
MESSAGE(STATUS "=====>>>>> Compile internal libraries as shared")
ELSE()
MESSAGE(STATUS "=====>>>>> Compile internal libraries as static")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
ENDIF()

IF(WIN32)
    IF(BUILD_SHARED_LIBS)
        ADD_DEFINITIONS(-DBUILD_SHARED_LIBS)
    ENDIF()
    IF(NOT CMAKE_DEBUG_POSTFIX)
        SET(CMAKE_DEBUG_POSTFIX d)
    ENDIF()

    cmake_policy(SET CMP0020 NEW)
ENDIF()

INCLUDE("$ENV{CMAKE_ADDITIONAL_MODULES_DIR}/CommonRules.cmake")

set(SSTUDIO_SOURCES
#list of .cpp files
...
)

SET(SSTUDIO_MOC_HEADERS
#list of .h files
...
)


FIND_PACKAGE(Boost 1.57.0 REQUIRED system date_time program_options filesystem chrono thread)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
IF(WIN32)
    ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB)
    ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK)
    ADD_DEFINITIONS(-DBOOST_NO_RVALUE_REFERENCES)

    LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})
ENDIF()

# fftw3
find_package(FFTW REQUIRED)
include_directories(${FFTW_INCLUDES})
MESSAGE(STATUS "FFTW_INCLUDES : '${FFTW_INCLUDES}'")


find_package(ZeroMQ REQUIRED)
INCLUDE_DIRECTORIES(${ZeroMQ_INCLUDE_DIRS})


#TTS Flite commented out since is not working anyway
#set(TTS_DIR "/home/user/flite")
#find_package(FliteDll REQUIRED flite_cmu_us_kal flite_usenglish flite_cmulex flite m)
#include_directories(${FliteDll_INCLUDES})


set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Libsndfile
find_package(sndfile REQUIRED)
include_directories(${sndfile_INCLUDE_DIR})
MESSAGE("Libsndfile = ${sndfile_LIBRARY}")
MESSAGE("Libsndfile include = ${sndfile_INCLUDE_DIR}")


IF($ENV{QT_SELECT} STREQUAL "4")
    set(QT_QMAKE_EXECUTABLE "$ENV{QTDIR}/Bin/qmake.exe")
    find_package(Qt4 4.8.6 REQUIRED QtGui QtCore QtSql QtNetwork QtTest QtUiTools QtXml)
    include (Qt4Macros)
    include(${QT_USE_FILE})
    include_directories(${QT_INCLUDES})
    ADD_DEFINITIONS( ${QT_DEFINITIONS} )
ELSE()
    find_package(Qt5 5.8 COMPONENTS Widgets Core Network Xml Sql UiTools Multimedia MultimediaWidgets Concurrent REQUIRED)
    # The Qt5Widgets_INCLUDES also includes the include directories for dependencies QtCore and QtGui
    include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Multimedia_INCLUDE_DIRS} ${Qt5Concurrent_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS})

    # We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
    add_definitions(${Qt5Widgets_DEFINITIONS})
    set(SSTUDIO_QT_LIBRARIES Qt5::Gui Qt5::Core Qt5::Sql Qt5::Network Qt5::UiTools Qt5::Xml Qt5::Multimedia Qt5::MultimediaWidgets)
ENDIF()

SET(CMAKE_AUTORCC ON)
SET(CMAKE_AUTOUIC ON)

# moc'ing
if(Qt4_FOUND OR QT4_FOUND)
  QT4_WRAP_CPP( SSTUDIO_MOC_SOURCES ${SSTUDIO_MOC_HEADERS} )
ELSE()
  QT5_WRAP_CPP( SSTUDIO_MOC_SOURCES ${SSTUDIO_MOC_HEADERS})
endif(Qt4_FOUND OR QT4_FOUND)

find_package(Poco REQUIRED Net NetSSL)
find_package(OpenSSL REQUIRED)

INCLUDE("Dependencies.cmake")


SET(SSTUDIO_LIBS
    ${Boost_LIBRARIES}
    ${ZeroMQ_LIBRARIES}
    ${FFTW_LIBRARIES}
    ${SSTUDIO_QT_LIBRARIES}
...
    ${modPlugin_LIBRARIES}
    ${ftpPlugin_LIBRARIES}
    ${sndfile_LIBRARIES}
#    ${FliteDll_LIBRARIES} commented out since is not working anyway
)

IF(UNIX)
    #target_link_libraries(${roofipc_LIBRARIES} ${ZeroMQ_LIBRARIES})
ENDIF()


add_executable(
    ${TARGET_NAME} 
    ${SSTUDIO_SOURCES} 
    ${SSTUDIO_MOC_SOURCES} 
)
target_link_libraries(
    ${TARGET_NAME} 
    ${SSTUDIO_LIBS} 
    ${Poco_LIBRARIES}
)


INCLUDE("$ENV{CMAKE_ADDITIONAL_MODULES_DIR}/ProductInfo.cmake")

# ----- POST-BUILD -----
#

# post build package creation
add_custom_target( pack
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/pack.cmake
    COMMENT "Creating package..." )

# postbuild copies
include ( copyConfig.cmake )
include ( copyScripts.cmake )

# post RUNTIME Environment Setup
add_custom_target( runtime COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/runtimeConfiguration.sh ${TARGET_NAME} COMMENT "Setup Runtime..." )

此库不附带pkg配置文件或CMake支持,但它使用常规的autotools安装结构(PREFIX/include、PREFIX/lib)

这意味着您可以让CMake搜索它:

find_path(FLITE_ROOT flite/flite.h PATH_SUFFIXES include)

add_library(FLite INTERFACE IMPORTED)
target_include_directories(FLite INTERFACE ${FLITE_ROOT}/include)
target_link_directories(FLite INTERFACE ${FLITE_ROOT}/lib)
target_link_libraries(FLite INTERFACE -lflite_cmu_us_kal -lflite_usenglish -lflite_cmulex -lflite -lm)
此块在CMake搜索路径上查找
include/flite/flite.h
,并用路径填充flite_根变量。 然后,我们创建一个导入的接口目标,该目标使用正确的头路径、库路径和链接库进行设置。 如果您想使其可重用,上述内容通常会放在
FindFLite.cmake
中,但现在您可以将其留在CMakeLists.txt中

最后,将您自己的目标与此CMake目标联系起来:

target_link_libraries(Plugin PUBLIC FLite)
第一次运行CMake时,可能需要将
CMake\u PREFIX\u路径
指向
/home/user/flite


编辑:将共享导入更改为接口导入。前者希望找到一个libFLite.so,而我已经指定了所有库依赖项。

也显示你的CMakeLists.txt。我将你的代码复制粘贴到插件的CMakeLists.txt的.cpp文件列表之前,然后运行“cmake-DCMAKE_PREFIX_PATH=/home/user/flite”,但我得到以下错误:“无法为目标指定链接目录”flite“这不是这个项目建立的。”我还做错了什么?哦,我搞错了Flite中“l”的大小写。到处都应该是大写的l。为了运行Cmake,我必须将“PUBLIC”更改为“INTERFACE”“.仍然不能正常建造,虽然抱歉,我今天只能自己测试。我忘了你需要一个接口导入的目标,而不是一个共享导入的目标。只有在我正确配置了“FindFLite.cmake”并添加了libasound之后,它才起作用。出于某种原因,将它放在CMakeList.txt中不起作用
find_path(FLITE_ROOT flite/flite.h PATH_SUFFIXES include)

add_library(FLite INTERFACE IMPORTED)
target_include_directories(FLite INTERFACE ${FLITE_ROOT}/include)
target_link_directories(FLite INTERFACE ${FLITE_ROOT}/lib)
target_link_libraries(FLite INTERFACE -lflite_cmu_us_kal -lflite_usenglish -lflite_cmulex -lflite -lm)
target_link_libraries(Plugin PUBLIC FLite)