1 diff --git a/CMakeLists.txt b/CMakeLists.txt
2 index 17c7032..12ed398 100644
6 cmake_minimum_required(VERSION 3.13.0)
7 project(kaldi_binaries)
9 -include(ExternalProject)
10 -include(ProcessorCount)
14 - set(MAKE_FLAGS -j${NCPU})
17 -set(DST ${PROJECT_SOURCE_DIR}/kaldi_active_grammar/exec)
18 -if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
19 - set(DST ${DST}/macos/)
20 -elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
21 - set(DST ${DST}/linux/)
23 - set(DST ${DST}/windows/)
29 src/lib/libkaldi-dragonfly${CMAKE_SHARED_LIBRARY_SUFFIX}
32 -# For MacOS, we handle all the "indirect" shared libraries manually.
33 -if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
34 - list(APPEND LIBRARIES
35 - tools/openfst/lib/libfst${CMAKE_SHARED_LIBRARY_SUFFIX}
36 - tools/openfst/lib/libfstscript${CMAKE_SHARED_LIBRARY_SUFFIX}
37 - src/lib/libkaldi-base${CMAKE_SHARED_LIBRARY_SUFFIX}
38 - src/lib/libkaldi-chain${CMAKE_SHARED_LIBRARY_SUFFIX}
39 - src/lib/libkaldi-cudamatrix${CMAKE_SHARED_LIBRARY_SUFFIX}
40 - src/lib/libkaldi-decoder${CMAKE_SHARED_LIBRARY_SUFFIX}
41 - src/lib/libkaldi-feat${CMAKE_SHARED_LIBRARY_SUFFIX}
42 - src/lib/libkaldi-fstext${CMAKE_SHARED_LIBRARY_SUFFIX}
43 - src/lib/libkaldi-gmm${CMAKE_SHARED_LIBRARY_SUFFIX}
44 - src/lib/libkaldi-hmm${CMAKE_SHARED_LIBRARY_SUFFIX}
45 - src/lib/libkaldi-ivector${CMAKE_SHARED_LIBRARY_SUFFIX}
46 - src/lib/libkaldi-lat${CMAKE_SHARED_LIBRARY_SUFFIX}
47 - src/lib/libkaldi-lm${CMAKE_SHARED_LIBRARY_SUFFIX}
48 - src/lib/libkaldi-matrix${CMAKE_SHARED_LIBRARY_SUFFIX}
49 - src/lib/libkaldi-nnet2${CMAKE_SHARED_LIBRARY_SUFFIX}
50 - src/lib/libkaldi-nnet3${CMAKE_SHARED_LIBRARY_SUFFIX}
51 - src/lib/libkaldi-online2${CMAKE_SHARED_LIBRARY_SUFFIX}
52 - src/lib/libkaldi-rnnlm${CMAKE_SHARED_LIBRARY_SUFFIX}
53 - src/lib/libkaldi-transform${CMAKE_SHARED_LIBRARY_SUFFIX}
54 - src/lib/libkaldi-tree${CMAKE_SHARED_LIBRARY_SUFFIX}
55 - src/lib/libkaldi-util${CMAKE_SHARED_LIBRARY_SUFFIX}
59 -if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
60 - message(FATAL_ERROR "CMake build not supported on Windows")
61 - # FIXME: copy files?
62 - # https://cmake.org/cmake/help/latest/command/foreach.html
63 - # https://stackoverflow.com/questions/34799916/copy-file-from-source-directory-to-binary-directory-using-cmake
66 -find_program(MAKE_EXE NAMES make gmake nmake)
68 -if(DEFINED ENV{INTEL_MKL_DIR})
69 - # Default: INTEL_MKL_DIR=/opt/intel/mkl/
70 - message("Compiling with MKL in: $ENV{INTEL_MKL_DIR}")
71 - set(KALDI_CONFIG_FLAGS --shared --static-math --use-cuda=no --mathlib=MKL --mkl-root=$ENV{INTEL_MKL_DIR})
72 - set(MATHLIB_BUILD_COMMAND true)
74 - message("Compiling with OpenBLAS")
75 - set(KALDI_CONFIG_FLAGS --shared --static-math --use-cuda=no --mathlib=OPENBLAS)
76 - set(MATHLIB_BUILD_COMMAND cd tools
77 - && git clone -b v0.3.13 --single-branch https://github.com/xianyi/OpenBLAS
78 - && ${MAKE_EXE} ${MAKE_FLAGS} -C OpenBLAS DYNAMIC_ARCH=1 TARGET=GENERIC USE_LOCKING=1 USE_THREAD=0 all
79 - && ${MAKE_EXE} ${MAKE_FLAGS} -C OpenBLAS PREFIX=install install
83 -if(DEFINED ENV{KALDI_BRANCH})
84 - set(KALDI_BRANCH $ENV{KALDI_BRANCH})
86 - message(FATAL_ERROR "KALDI_BRANCH not set! Use 'origin/master'?")
87 - # set(KALDI_BRANCH "origin/master")
90 message("MAKE_EXE = ${MAKE_EXE}")
91 message("PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
92 message("PYTHON_INCLUDE_DIR = ${PYTHON_INCLUDE_DIR}")
93 @@ -94,65 +19,4 @@ message("CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}")
95 # CXXFLAGS are set and exported in kaldi-configure-wrapper.sh
97 -if(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
98 - set(STRIP_LIBS_COMMAND find src/lib tools/openfst/lib -name *${CMAKE_SHARED_LIBRARY_SUFFIX} | xargs strip)
99 - # set(STRIP_DST_COMMAND find ${DST} [[[other specifiers]]] | xargs strip)
100 - if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
101 - list(APPEND STRIP_LIBS_COMMAND -x)
102 - # list(APPEND STRIP_DST_COMMAND -x)
104 - # set(STRIP_LIBS_COMMAND true)
105 - set(STRIP_DST_COMMAND true)
106 - ExternalProject_Add(kaldi
107 - GIT_CONFIG advice.detachedHead=false
108 - GIT_REPOSITORY https://github.com/daanzu/kaldi-fork-active-grammar.git
109 - GIT_TAG ${KALDI_BRANCH}
111 - CONFIGURE_COMMAND sed -i.bak -e "s/status=0/exit 0/g" tools/extras/check_dependencies.sh && sed -i.bak -e "s/openfst_add_CXXFLAGS = -g -O2/openfst_add_CXXFLAGS = -g0 -O3/g" tools/Makefile && cp ${PROJECT_SOURCE_DIR}/building/kaldi-configure-wrapper.sh src/
112 - BUILD_IN_SOURCE TRUE
113 - BUILD_COMMAND ${MATHLIB_BUILD_COMMAND} && cd tools && ${MAKE_EXE} ${MAKE_FLAGS} && cd openfst && autoreconf && cd ../../src && bash ./kaldi-configure-wrapper.sh ./configure ${KALDI_CONFIG_FLAGS} && ${MAKE_EXE} ${MAKE_FLAGS} depend && ${MAKE_EXE} ${MAKE_FLAGS} dragonfly
115 - INSTALL_COMMAND ${STRIP_LIBS_COMMAND} && mkdir -p ${DST} && cp ${BINARIES} ${LIBRARIES} ${DST} && ${STRIP_DST_COMMAND}
119 -# Fix dynamic libraries loading paths on macOS. The libraries and
120 -# executables are built with RPATH settings embedded in them, pointing
121 -# to the locations in temporary directories used to build the
122 -# binaries. After package installation is done, these directories are
123 -# deleted and the dynamic libraries cannot be loaded. The following
124 -# commands generate a shell script that fixes the paths to the dynamic
125 -# libraries in the built executables and the libraries themselves.
126 -# Also the commands add a custom target to invoke the generated script
127 -# after the external project (kaldi) has been built. An alternative
128 -# would be to change the kaldi engine build system to accept a path to
129 -# where the binaries would be placed and point RPATH to that location.
130 -if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
131 - string (REPLACE ";" " " BINARIES_STR "${BINARIES}")
132 - string (REPLACE ";" " " LIBRARIES_STR "${LIBRARIES}")
133 - file(GENERATE OUTPUT name_fixer
135 - "for a in ${BINARIES_STR} ; do
137 - install_name_tool -change ${PROJECT_BINARY_DIR}/kaldi-prefix/src/kaldi/tools/openfst-1.6.7/lib/libfst.10.dylib \"@loader_path/libfst.dylib\" ${DST}$a_bare
138 - install_name_tool -change ${PROJECT_BINARY_DIR}/kaldi-prefix/src/kaldi/tools/openfst-1.6.7/lib/libfstscript.10.dylib \"@loader_path/libfstscript.dylib\" ${DST}$a_bare
139 - for b in ${LIBRARIES_STR} ; do
141 - install_name_tool -change \"@rpath/$b_bare\" \"@loader_path/$b_bare\" ${DST}$a_bare
144 - for a in ${LIBRARIES_STR} ; do
146 - install_name_tool -id \"@loader_path/$a_bare\" ${DST}$a_bare
147 - install_name_tool -change ${PROJECT_BINARY_DIR}/kaldi-prefix/src/kaldi/tools/openfst-1.6.7/lib/libfst.10.dylib \"@loader_path/libfst.dylib\" ${DST}$a_bare
148 - install_name_tool -change ${PROJECT_BINARY_DIR}/kaldi-prefix/src/kaldi/tools/openfst-1.6.7/lib/libfstscript.10.dylib \"@loader_path/libfstscript.dylib\" ${DST}$a_bare
149 - for b in ${LIBRARIES_STR} ; do
151 - install_name_tool -change \"@rpath/$b_bare\" \"@loader_path/$b_bare\" ${DST}$a_bare
154 - add_custom_target(fixer ALL COMMAND /bin/sh name_fixer)
155 - add_dependencies(fixer kaldi)
158 install(CODE "MESSAGE(\"Installed kaldi engine binaries.\")")