mirror of
https://github.com/csukuangfj/kaldifeat.git
synced 2025-08-09 10:02:20 +00:00
parent
e78f081327
commit
01f30d2e34
@ -16,8 +16,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|||||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||||
set(BUILD_RPATH_USE_ORIGIN TRUE)
|
set(BUILD_RPATH_USE_ORIGIN TRUE)
|
||||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
set(CMAKE_INSTALL_RPATH "$ORIGIN")
|
|
||||||
set(CMAKE_BUILD_RPATH "$ORIGIN")
|
if(NOT APPLE)
|
||||||
|
set(kaldifeat_rpath_origin "$ORIGIN")
|
||||||
|
else()
|
||||||
|
set(kaldifeat_rpath_origin "@loader_path")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_INSTALL_RPATH ${kaldifeat_rpath_origin})
|
||||||
|
set(CMAKE_BUILD_RPATH ${kaldifeat_rpath_origin})
|
||||||
|
|
||||||
set(BUILD_SHARED_LIBS ON)
|
set(BUILD_SHARED_LIBS ON)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
@ -52,11 +59,6 @@ if(kaldifeat_BUILD_TESTS)
|
|||||||
enable_testing()
|
enable_testing()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# TORCH_VERSION is defined in cmake/torch.cmake
|
|
||||||
configure_file(
|
|
||||||
${CMAKE_SOURCE_DIR}/kaldifeat/python/kaldifeat/torch_version.py.in
|
|
||||||
${CMAKE_SOURCE_DIR}/kaldifeat/python/kaldifeat/torch_version.py @ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
# disable various warnings for MSVC
|
# disable various warnings for MSVC
|
||||||
@ -71,4 +73,40 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR})
|
include_directories(${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
|
||||||
|
|
||||||
add_subdirectory(kaldifeat)
|
add_subdirectory(kaldifeat)
|
||||||
|
|
||||||
|
# TORCH_VERSION is defined in cmake/torch.cmake
|
||||||
|
configure_file(
|
||||||
|
${PROJECT_SOURCE_DIR}/kaldifeat/python/kaldifeat/torch_version.py.in
|
||||||
|
${PROJECT_SOURCE_DIR}/kaldifeat/python/kaldifeat/torch_version.py @ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${PROJECT_SOURCE_DIR}/cmake/kaldifeatConfigVersion.cmake.in
|
||||||
|
${PROJECT_BINARY_DIR}/kaldifeatConfigVersion.cmake
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${PROJECT_SOURCE_DIR}/cmake/kaldifeatConfig.cmake.in
|
||||||
|
${PROJECT_BINARY_DIR}/kaldifeatConfig.cmake
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
${PROJECT_BINARY_DIR}/kaldifeatConfigVersion.cmake
|
||||||
|
${PROJECT_BINARY_DIR}/kaldifeatConfig.cmake
|
||||||
|
DESTINATION share/cmake/kaldifeat
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
${PROJECT_SOURCE_DIR}/kaldifeat/python/kaldifeat/torch_version.py
|
||||||
|
DESTINATION ./
|
||||||
|
)
|
||||||
|
@ -67,27 +67,39 @@ class BuildExtension(build_ext):
|
|||||||
if cmake_args == "":
|
if cmake_args == "":
|
||||||
cmake_args = "-DCMAKE_BUILD_TYPE=Release"
|
cmake_args = "-DCMAKE_BUILD_TYPE=Release"
|
||||||
|
|
||||||
|
extra_cmake_args = " -Dkaldifeat_BUILD_TESTS=OFF "
|
||||||
|
extra_cmake_args += f" -DCMAKE_INSTALL_PREFIX={Path(self.build_lib).resolve()}/kaldifeat " # noqa
|
||||||
|
|
||||||
if "PYTHON_EXECUTABLE" not in cmake_args:
|
if "PYTHON_EXECUTABLE" not in cmake_args:
|
||||||
print(f"Setting PYTHON_EXECUTABLE to {sys.executable}")
|
print(f"Setting PYTHON_EXECUTABLE to {sys.executable}")
|
||||||
cmake_args += f" -DPYTHON_EXECUTABLE={sys.executable}"
|
cmake_args += f" -DPYTHON_EXECUTABLE={sys.executable}"
|
||||||
|
|
||||||
|
cmake_args += extra_cmake_args
|
||||||
|
|
||||||
if is_windows():
|
if is_windows():
|
||||||
build_cmd = f"""
|
build_cmd = f"""
|
||||||
cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}
|
cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}
|
||||||
cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m
|
cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m
|
||||||
|
cmake --build {self.build_temp} --target install --config Release -- -m
|
||||||
"""
|
"""
|
||||||
print(f"build command is:\n{build_cmd}")
|
print(f"build command is:\n{build_cmd}")
|
||||||
ret = os.system(
|
ret = os.system(
|
||||||
f"cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}"
|
f"cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}"
|
||||||
)
|
)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
raise Exception("Failed to build kaldifeat")
|
raise Exception("Failed to configure kaldifeat")
|
||||||
|
|
||||||
ret = os.system(
|
ret = os.system(
|
||||||
f"cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m"
|
f"cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m"
|
||||||
)
|
)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
raise Exception("Failed to build kaldifeat")
|
raise Exception("Failed to build kaldifeat")
|
||||||
|
|
||||||
|
ret = os.system(
|
||||||
|
f"cmake --build {self.build_temp} --target install --config Release -- -m"
|
||||||
|
)
|
||||||
|
if ret != 0:
|
||||||
|
raise Exception("Failed to install kaldifeat")
|
||||||
else:
|
else:
|
||||||
if make_args == "" and system_make_args == "":
|
if make_args == "" and system_make_args == "":
|
||||||
print("For fast compilation, run:")
|
print("For fast compilation, run:")
|
||||||
@ -101,7 +113,7 @@ class BuildExtension(build_ext):
|
|||||||
cmake {cmake_args} {kaldifeat_dir}
|
cmake {cmake_args} {kaldifeat_dir}
|
||||||
|
|
||||||
|
|
||||||
make {make_args} _kaldifeat
|
make {make_args} _kaldifeat install
|
||||||
"""
|
"""
|
||||||
print(f"build command is:\n{build_cmd}")
|
print(f"build command is:\n{build_cmd}")
|
||||||
|
|
||||||
@ -112,27 +124,3 @@ class BuildExtension(build_ext):
|
|||||||
"You can ask for help by creating an issue on GitHub.\n"
|
"You can ask for help by creating an issue on GitHub.\n"
|
||||||
"\nClick:\n\thttps://github.com/csukuangfj/kaldifeat/issues/new\n" # noqa
|
"\nClick:\n\thttps://github.com/csukuangfj/kaldifeat/issues/new\n" # noqa
|
||||||
)
|
)
|
||||||
|
|
||||||
lib_so = glob.glob(f"{self.build_temp}/lib/*kaldifeat*.so")
|
|
||||||
lib_so += glob.glob(f"{self.build_temp}/lib/*kaldifeat*.dylib") # macOS
|
|
||||||
|
|
||||||
# bin/Release/_kaldifeat.cp38-win_amd64.pyd
|
|
||||||
lib_so += glob.glob(
|
|
||||||
f"{self.build_temp}/**/*kaldifeat*.pyd", recursive=True
|
|
||||||
) # windows
|
|
||||||
|
|
||||||
# lib/Release/*.lib
|
|
||||||
lib_so += glob.glob(
|
|
||||||
f"{self.build_temp}/**/*kaldifeat*.lib", recursive=True
|
|
||||||
) # windows
|
|
||||||
for so in lib_so:
|
|
||||||
print(f"Copying {so} to {self.build_lib}/")
|
|
||||||
shutil.copy(f"{so}", f"{self.build_lib}/")
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"Copying {kaldifeat_dir}/kaldifeat/python/kaldifeat/torch_version.py to {self.build_lib}/kaldifeat" # noqa
|
|
||||||
)
|
|
||||||
shutil.copy(
|
|
||||||
f"{kaldifeat_dir}/kaldifeat/python/kaldifeat/torch_version.py",
|
|
||||||
f"{self.build_lib}/kaldifeat",
|
|
||||||
)
|
|
||||||
|
65
cmake/kaldifeatConfig.cmake.in
Normal file
65
cmake/kaldifeatConfig.cmake.in
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Findkaldifeat
|
||||||
|
# -------------
|
||||||
|
#
|
||||||
|
# Finds the kaldifeat library
|
||||||
|
#
|
||||||
|
# This will define the following variables:
|
||||||
|
#
|
||||||
|
# KALDIFEAT_FOUND -- True if the system has the kaldifeat library
|
||||||
|
# KALDIFEAT_INCLUDE_DIRS -- The include directories for kaldifeat
|
||||||
|
# KALDIFEAT_LIBRARIES -- Libraries to link against
|
||||||
|
# KALDIFEAT_CXX_FLAGS -- Additional (required) compiler flags
|
||||||
|
# KALDIFEAT_TORCH_VERSION_MAJOR -- The major version of PyTorch used to compile kaldifeat
|
||||||
|
# KALDIFEAT_TORCH_VERSION_MINOR -- The minor version of PyTorch used to compile kaldifeat
|
||||||
|
# KALDIFEAT_VERSION -- The version of kaldifeat
|
||||||
|
#
|
||||||
|
# and the following imported targets:
|
||||||
|
#
|
||||||
|
# kaldifeat_core
|
||||||
|
|
||||||
|
# This file is modified from pytorch/cmake/TorchConfig.cmake.in
|
||||||
|
|
||||||
|
set(KALDIFEAT_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
|
||||||
|
set(KALDIFEAT_TORCH_VERSION_MAJOR @KALDIFEAT_TORCH_VERSION_MAJOR@)
|
||||||
|
set(KALDIFEAT_TORCH_VERSION_MINOR @KALDIFEAT_TORCH_VERSION_MINOR@)
|
||||||
|
set(KALDIFEAT_VERSION @KALDIFEAT_VERSION@)
|
||||||
|
|
||||||
|
if(DEFINED ENV{KALDIFEAT_INSTALL_PREFIX})
|
||||||
|
set(KALDIFEAT_INSTALL_PREFIX $ENV{KALDIFEAT_INSTALL_PREFIX})
|
||||||
|
else()
|
||||||
|
# Assume we are in <install-prefix>/share/cmake/kaldifeat/kaldifeatConfig.cmake
|
||||||
|
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||||
|
get_filename_component(KALDIFEAT_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(KALDIFEAT_INCLUDE_DIRS ${KALDIFEAT_INSTALL_PREFIX}/include)
|
||||||
|
|
||||||
|
set(KALDIFEAT_LIBRARIES kaldifeat_core)
|
||||||
|
|
||||||
|
foreach(lib IN LISTS KALDIFEAT_LIBRARIES)
|
||||||
|
find_library(location_${lib} ${lib}
|
||||||
|
PATHS
|
||||||
|
"${KALDIFEAT_INSTALL_PREFIX}/lib"
|
||||||
|
"${KALDIFEAT_INSTALL_PREFIX}/lib64"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
|
add_library(${lib} SHARED IMPORTED)
|
||||||
|
else()
|
||||||
|
add_library(${lib} STATIC IMPORTED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${lib} PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${KALDIFEAT_INCLUDE_DIRS}"
|
||||||
|
IMPORTED_LOCATION "${location_${lib}}"
|
||||||
|
CXX_STANDARD 14
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET ${lib} PROPERTY INTERFACE_COMPILE_OPTIONS @CMAKE_CXX_FLAGS@)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(kaldifeat DEFAULT_MSG
|
||||||
|
location_kaldifeat_core
|
||||||
|
)
|
12
cmake/kaldifeatConfigVersion.cmake.in
Normal file
12
cmake/kaldifeatConfigVersion.cmake.in
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# This file is modified from pytorch/cmake/TorchConfigVersion.cmake.in
|
||||||
|
set(PACKAGE_VERSION "@kaldifeat_VERSION@")
|
||||||
|
|
||||||
|
# Check whether the requested PACKAGE_FIND_VERSION is compatible
|
||||||
|
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||||
|
else()
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||||
|
if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
|
||||||
|
set(PACKAGE_VERSION_EXACT TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
@ -53,5 +53,25 @@ if(kaldifeat_BUILD_TESTS)
|
|||||||
foreach(source IN LISTS test_srcs)
|
foreach(source IN LISTS test_srcs)
|
||||||
kaldifeat_add_test(${source})
|
kaldifeat_add_test(${source})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY
|
||||||
|
DESTINATION
|
||||||
|
${PROJECT_BINARY_DIR}/include/kaldifeat/csrc
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE all_headers *.h)
|
||||||
|
message(STATUS "All headers: ${all_headers}")
|
||||||
|
|
||||||
|
file(COPY
|
||||||
|
${all_headers}
|
||||||
|
DESTINATION
|
||||||
|
${PROJECT_BINARY_DIR}/include/kaldifeat/csrc
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS kaldifeat_core
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
install(FILES ${all_headers}
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kaldifeat/csrc
|
||||||
|
)
|
||||||
|
@ -21,6 +21,10 @@ if(APPLE)
|
|||||||
target_link_libraries(_kaldifeat PRIVATE "-Wl,-rpath,${PYTHON_SITE_PACKAGE_DIR}")
|
target_link_libraries(_kaldifeat PRIVATE "-Wl,-rpath,${PYTHON_SITE_PACKAGE_DIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT WIN32)
|
||||||
|
target_link_libraries(_kaldifeat PRIVATE "-Wl,-rpath,${kaldifeat_rpath_origin}/kaldifeat/${CMAKE_INSTALL_LIBDIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(_kaldifeat PRIVATE kaldifeat_core)
|
target_link_libraries(_kaldifeat PRIVATE kaldifeat_core)
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/libtorch_python.so)
|
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/libtorch_python.so)
|
||||||
@ -29,3 +33,7 @@ elseif(WIN32)
|
|||||||
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/torch_python.lib)
|
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/torch_python.lib)
|
||||||
target_link_libraries(_kaldifeat PUBLIC ${PYTHON_LIBRARIES})
|
target_link_libraries(_kaldifeat PUBLIC ${PYTHON_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
install(TARGETS _kaldifeat
|
||||||
|
DESTINATION ../
|
||||||
|
)
|
||||||
|
@ -23,3 +23,8 @@ from .offline_feature import OfflineFeature
|
|||||||
from .online_feature import OnlineFeature
|
from .online_feature import OnlineFeature
|
||||||
from .plp import OnlinePlp, Plp
|
from .plp import OnlinePlp, Plp
|
||||||
from .spectrogram import Spectrogram
|
from .spectrogram import Spectrogram
|
||||||
|
|
||||||
|
from pathlib import Path as _Path
|
||||||
|
|
||||||
|
cmake_prefix_path = _Path(__file__).parent / "share" / "cmake"
|
||||||
|
del _Path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user