Commit 7b5317b3 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Refactor CMake modules (#2930)

Summary: Pull Request resolved: https://github.com/pytorch/audio/pull/2930

Reviewed By: carolineechen, nateanl

Differential Revision: D42280966

Pulled By: mthrok

fbshipit-source-id: f9d5f1dc7c1a62d932fb2020aafb63734f2bf405
parent 5ee34516
......@@ -133,6 +133,9 @@ endif()
# TORCH_CXX_FLAGS contains the same -D_GLIBCXX_USE_CXX11_ABI value as PyTorch
if (MSVC)
set(warning_flags /W4)
# the following line is added in order to export symbols when building on Windows
# this approach has some limitations as documented in https://github.com/pytorch/pytorch/pull/3650
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
set(warning_flags -Wall)
endif()
......@@ -140,3 +143,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warning_flags} ${TORCH_CXX_FLAGS}")
add_subdirectory(third_party)
add_subdirectory(torchaudio/csrc)
if (BUILD_SOX)
add_subdirectory(torchaudio/csrc/sox)
endif()
if (USE_FFMPEG)
add_subdirectory(torchaudio/csrc/ffmpeg)
endif()
......@@ -2,7 +2,7 @@ find_package(Torch REQUIRED)
function (torchaudio_library name source include_dirs link_libraries compile_defs)
add_library(${name} SHARED ${source})
target_include_directories(${name} PRIVATE ${include_dirs})
target_include_directories(${name} PRIVATE "${PROJECT_SOURCE_DIR};${include_dirs}")
target_link_libraries(${name} ${link_libraries})
target_compile_definitions(${name} PRIVATE ${compile_defs})
set_target_properties(${name} PROPERTIES PREFIX "")
......@@ -57,3 +57,16 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
)
endfunction()
endif()
if (USE_CUDA)
add_library(cuda_deps INTERFACE)
target_include_directories(cuda_deps INTERFACE ${CUDA_TOOLKIT_INCLUDE})
target_compile_definitions(cuda_deps INTERFACE USE_CUDA)
target_link_libraries(
cuda_deps
INTERFACE
${C10_CUDA_LIBRARY}
${CUDA_CUDART_LIBRARY}
)
endif()
......@@ -36,7 +36,7 @@ set(
torchaudio_library(
libflashlight-text
"${libflashlight_src}"
submodule
"${CMAKE_CURRENT_SOURCE_DIR}/submodule"
""
FL_TEXT_USE_KENLM
)
......
# the following line is added in order to export symbols when building on Windows
# this approach has some limitations as documented in https://github.com/pytorch/pytorch/pull/3650
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
################################################################################
# libtorchaudio
################################################################################
set(
LIBTORCHAUDIO_SOURCES
sources
lfilter.cpp
overdrive.cpp
utils.cpp
)
set(
LIBTORCHAUDIO_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}
)
set(
LIBTORCHAUDIO_LINK_LIBRARIES
torch
additional_libs
)
set(
LIBTORCHAUDIO_COMPILE_DEFINITIONS)
compile_definitions)
#------------------------------------------------------------------------------#
# START OF CUSTOMIZATION LOGICS
......@@ -33,7 +21,7 @@ set(
if(BUILD_RNNT)
list(
APPEND
LIBTORCHAUDIO_SOURCES
sources
rnnt/cpu/compute_alphas.cpp
rnnt/cpu/compute_betas.cpp
rnnt/cpu/compute.cpp
......@@ -45,7 +33,7 @@ if(BUILD_RNNT)
if (USE_CUDA)
list(
APPEND
LIBTORCHAUDIO_SOURCES
sources
rnnt/gpu/compute_alphas.cu
rnnt/gpu/compute_betas.cu
rnnt/gpu/compute.cu
......@@ -56,32 +44,21 @@ endif()
if(USE_CUDA)
list(
APPEND
LIBTORCHAUDIO_INCLUDE_DIRS
${CUDA_TOOLKIT_INCLUDE}
)
list(
APPEND
LIBTORCHAUDIO_LINK_LIBRARIES
${C10_CUDA_LIBRARY}
${CUDA_CUDART_LIBRARY}
additional_libs
cuda_deps
)
list(
APPEND
LIBTORCHAUDIO_COMPILE_DEFINITIONS
USE_CUDA
)
endif()
if(BUILD_KALDI)
list(APPEND LIBTORCHAUDIO_LINK_LIBRARIES kaldi)
list(APPEND LIBTORCHAUDIO_SOURCES kaldi.cpp)
list(APPEND LIBTORCHAUDIO_COMPILE_DEFINITIONS INCLUDE_KALDI)
list(APPEND additional_libs kaldi)
list(APPEND sources kaldi.cpp)
list(APPEND compile_definitions INCLUDE_KALDI)
endif()
if(OpenMP_CXX_FOUND)
list(
APPEND
LIBTORCHAUDIO_LINK_LIBRARIES
additional_libs
OpenMP::OpenMP_CXX
)
endif()
......@@ -92,10 +69,10 @@ endif()
torchaudio_library(
libtorchaudio
"${LIBTORCHAUDIO_SOURCES}"
"${LIBTORCHAUDIO_INCLUDE_DIRS}"
"${LIBTORCHAUDIO_LINK_LIBRARIES}"
"${LIBTORCHAUDIO_COMPILE_DEFINITIONS}"
"${sources}"
""
"torch;${additional_libs}"
"${compile_definitions}"
)
if (APPLE)
......@@ -104,61 +81,6 @@ else()
set(TORCHAUDIO_LIBRARY -Wl,--no-as-needed libtorchaudio -Wl,--as-needed CACHE INTERNAL "")
endif()
################################################################################
# libtorchaudio_sox
################################################################################
if (BUILD_SOX)
set(
libtorchaudio_sox_sources
sox/io.cpp
sox/utils.cpp
sox/effects.cpp
sox/effects_chain.cpp
sox/types.cpp
)
torchaudio_library(
libtorchaudio_sox
"${libtorchaudio_sox_sources}"
"${LIBTORCHAUDIO_INCLUDE_DIRS}"
"torch;libsox"
"${LIBTORCHAUDIO_COMPILE_DEFINITIONS}"
)
endif()
################################################################################
# libtorchaudio_ffmpeg
################################################################################
if(USE_FFMPEG)
set(
LIBTORCHAUDIO_FFMPEG_SOURCES
ffmpeg/ffmpeg.cpp
ffmpeg/filter_graph.cpp
ffmpeg/stream_reader/buffer/common.cpp
ffmpeg/stream_reader/buffer/chunked_buffer.cpp
ffmpeg/stream_reader/buffer/unchunked_buffer.cpp
ffmpeg/stream_reader/decoder.cpp
ffmpeg/stream_reader/sink.cpp
ffmpeg/stream_reader/stream_processor.cpp
ffmpeg/stream_reader/stream_reader.cpp
ffmpeg/stream_reader/stream_reader_wrapper.cpp
ffmpeg/stream_reader/stream_reader_binding.cpp
ffmpeg/stream_reader/stream_reader_tensor_binding.cpp
ffmpeg/stream_writer/stream_writer.cpp
ffmpeg/stream_writer/stream_writer_wrapper.cpp
ffmpeg/stream_writer/stream_writer_binding.cpp
ffmpeg/utils.cpp
)
message(STATUS "FFMPEG_ROOT=$ENV{FFMPEG_ROOT}")
find_package(FFMPEG 4.1 REQUIRED COMPONENTS avdevice avfilter avformat avcodec avutil)
torchaudio_library(
libtorchaudio_ffmpeg
"${LIBTORCHAUDIO_FFMPEG_SOURCES}"
"${LIBTORCHAUDIO_INCLUDE_DIRS};${FFMPEG_INCLUDE_DIRS}"
"torch;${FFMPEG_LIBRARIES}"
"${LIBTORCHAUDIO_COMPILE_DEFINITIONS}"
)
endif()
################################################################################
# Python extensions
################################################################################
......@@ -174,37 +96,4 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
"libtorchaudio"
""
)
if(BUILD_SOX)
set(
sox_extension_sources
sox/pybind/pybind.cpp
sox/pybind/effects.cpp
sox/pybind/effects_chain.cpp
sox/pybind/io.cpp
sox/pybind/utils.cpp
)
torchaudio_extension(
_torchaudio_sox
"${sox_extension_sources}"
""
"libtorchaudio_sox"
""
)
endif()
if(USE_FFMPEG)
set(
FFMPEG_EXTENSION_SOURCES
ffmpeg/pybind/typedefs.cpp
ffmpeg/pybind/pybind.cpp
ffmpeg/pybind/stream_reader.cpp
ffmpeg/pybind/stream_writer.cpp
)
torchaudio_extension(
_torchaudio_ffmpeg
"${FFMPEG_EXTENSION_SOURCES}"
"${FFMPEG_INCLUDE_DIRS}"
"libtorchaudio_ffmpeg"
""
)
endif()
endif()
message(STATUS "FFMPEG_ROOT=$ENV{FFMPEG_ROOT}")
find_package(FFMPEG 4.1 REQUIRED COMPONENTS avdevice avfilter avformat avcodec avutil)
add_library(ffmpeg INTERFACE)
target_include_directories(ffmpeg INTERFACE "${FFMPEG_INCLUDE_DIRS}")
target_link_libraries(ffmpeg INTERFACE "${FFMPEG_LIBRARIES}")
set(
sources
ffmpeg.cpp
filter_graph.cpp
stream_reader/buffer/common.cpp
stream_reader/buffer/chunked_buffer.cpp
stream_reader/buffer/unchunked_buffer.cpp
stream_reader/decoder.cpp
stream_reader/sink.cpp
stream_reader/stream_processor.cpp
stream_reader/stream_reader.cpp
stream_reader/stream_reader_wrapper.cpp
stream_reader/stream_reader_binding.cpp
stream_reader/stream_reader_tensor_binding.cpp
stream_writer/stream_writer.cpp
stream_writer/stream_writer_wrapper.cpp
stream_writer/stream_writer_binding.cpp
utils.cpp
)
if (USE_CUDA)
set(
additional_lib
cuda_deps)
endif()
torchaudio_library(
libtorchaudio_ffmpeg
"${sources}"
""
"torch;ffmpeg;${additional_lib}"
""
)
if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
set(
ext_sources
pybind/typedefs.cpp
pybind/pybind.cpp
pybind/stream_reader.cpp
pybind/stream_writer.cpp
)
torchaudio_extension(
_torchaudio_ffmpeg
"${ext_sources}"
""
"libtorchaudio_ffmpeg"
""
)
endif ()
set(
sources
io.cpp
utils.cpp
effects.cpp
effects_chain.cpp
types.cpp
)
torchaudio_library(
libtorchaudio_sox
"${sources}"
""
"torch;libsox"
""
)
if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
set(
ext_sources
pybind/pybind.cpp
pybind/effects.cpp
pybind/effects_chain.cpp
pybind/io.cpp
pybind/utils.cpp
)
torchaudio_extension(
_torchaudio_sox
"${ext_sources}"
""
"libtorchaudio_sox"
""
)
endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment