Fixed Windows build

This commit is contained in:
Daniel Wolf 2015-12-21 13:09:09 +01:00
parent fd842111dc
commit 4baab9b207
4 changed files with 31 additions and 8 deletions

View File

@ -16,16 +16,21 @@ if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
endif()
# Use static run-time
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
endif()
# Set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# Define flags variables for later use
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(enableWarningsFlags "-Wall;-Wextra")
set(disableWarningsFlags "-w")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(enableWarningsFlags "/W4")
set(disableWarningsFlags "/W0")
endif()
@ -46,13 +51,13 @@ add_library(cppFormat ${cppFormatFiles})
target_compile_options(cppFormat PRIVATE ${disableWarningsFlags})
# ... sphinxbase
include_directories(SYSTEM "lib/sphinxbase-5prealpha-2015-08-05/include")
include_directories(SYSTEM "lib/sphinxbase-redefine/include" "lib/sphinxbase-5prealpha-2015-08-05/include")
FILE(GLOB_RECURSE sphinxbaseFiles "lib/sphinxbase-5prealpha-2015-08-05/src/libsphinxbase/*.c")
add_library(sphinxbase ${sphinxbaseFiles})
target_compile_options(sphinxbase PRIVATE ${disableWarningsFlags})
# ... PocketSphinx
include_directories(SYSTEM "lib/pocketsphinx-5prealpha-2015-08-05/include")
include_directories(SYSTEM "lib/pocketsphinx-redefine/include" "lib/pocketsphinx-5prealpha-2015-08-05/include")
FILE(GLOB pocketSphinxFiles "lib/pocketsphinx-5prealpha-2015-08-05/src/libpocketsphinx/*.c")
add_library(pocketSphinx ${pocketSphinxFiles})
target_link_libraries(pocketSphinx sphinxbase)

View File

@ -0,0 +1,7 @@
#ifndef __POCKETSPHINX_EXPORT_H__
#define __POCKETSPHINX_EXPORT_H__
// We're creating a static library. No __declspec!
#define POCKETSPHINX_EXPORT
#endif /* __POCKETSPHINX_EXPORT_H__ */

View File

@ -0,0 +1,7 @@
#ifndef __SPHINXBASE_EXPORT_H__
#define __SPHINXBASE_EXPORT_H__
// We're creating a static library. No __declspec!
#define SPHINXBASE_EXPORT
#endif /* __SPHINXBASE_EXPORT_H__ */

View File

@ -1,14 +1,17 @@
#include <pocketsphinx.h>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <sphinxbase/err.h>
#include "phone_extraction.h"
#include "audio_input/SampleRateConverter.h"
#include "audio_input/ChannelDownmixer.h"
#include "platform_tools.h"
#include "tools.h"
extern "C" {
#include <pocketsphinx.h>
#include <sphinxbase/err.h>
}
using std::runtime_error;
using std::unique_ptr;
using std::shared_ptr;
@ -128,7 +131,7 @@ void sphinxErrorCallback(void* user_data, err_lvl_t errorLevel, const char* form
// Create varArgs list
va_list args;
va_start(args, format);
auto _ = finally([&args](){ va_end(args); });
auto _ = finally([&args]() { va_end(args); });
// Format message
const int initialSize = 256;
@ -174,7 +177,8 @@ map<centiseconds, Phone> detectPhones(unique_ptr<AudioStream> audioStream) {
// Collect results into map
return getPhones(*recognizer.get());
} catch (...) {
}
catch (...) {
std::throw_with_nested(runtime_error("Error detecting phones via Pocketsphinx. " + errorMessage));
}
}