Unverified Commit 7d6e486a authored by moto's avatar moto Committed by GitHub
Browse files

Refactor cmake helper functions (#3672)

parent 1caa3fcc
......@@ -14,7 +14,7 @@ if ("caffe2::mkl" IN_LIST dep)
set_target_properties(torch_cpu PROPERTIES INTERFACE_LINK_LIBRARIES "${dep}")
endif()
function (torchaudio_library name source include_dirs link_libraries compile_defs)
function (_library destination name source include_dirs link_libraries compile_defs)
add_library(${name} SHARED ${source})
target_include_directories(${name} PRIVATE "${PROJECT_SOURCE_DIR}/src;${include_dirs}")
target_link_libraries(${name} ${link_libraries})
......@@ -25,11 +25,32 @@ function (torchaudio_library name source include_dirs link_libraries compile_def
endif(MSVC)
install(
TARGETS ${name}
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib # For Windows
LIBRARY DESTINATION "${destination}"
RUNTIME DESTINATION "${destination}" # For Windows
)
endfunction()
function(torchaudio_library name source include_dirs link_libraries compile_defs)
_library(
torchaudio/lib
"${name}"
"${source}"
"${include_dirs}"
"${link_libraries}"
"${compile_defs}"
)
endfunction()
function(torio_library name source include_dirs link_libraries compile_defs)
_library(
torio/lib
"${name}"
"${source}"
"${include_dirs}"
"${link_libraries}"
"${compile_defs}"
)
endfunction()
if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
# See https://github.com/pytorch/pytorch/issues/38122
......@@ -39,7 +60,7 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
find_package(Python3 ${PYTHON_VERSION} EXACT COMPONENTS Development)
set(ADDITIONAL_ITEMS Python3::Python)
endif()
function(torchaudio_extension name sources include_dirs libraries definitions)
function(_extension destination name sources include_dirs libraries definitions)
add_library(${name} SHARED ${sources})
target_compile_definitions(${name} PRIVATE "${definitions}")
target_include_directories(
......@@ -66,8 +87,29 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
endif()
install(
TARGETS ${name}
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib # For Windows
LIBRARY DESTINATION "${destination}"
RUNTIME DESTINATION "${destination}" # For Windows
)
endfunction()
function(torchaudio_extension name sources include_dirs libraries definitions)
_extension(
torchaudio/lib
"${name}"
"${sources}"
"${include_dirs}"
"${libraries}"
"${definitions}"
)
endfunction()
function(torio_extension name sources include_dirs libraries definitions)
_extension(
torio/lib
"${name}"
"${sources}"
"${include_dirs}"
"${libraries}"
"${definitions}"
)
endfunction()
endif()
......
......@@ -114,7 +114,7 @@ class CMakeBuild(build_ext):
# `torchaudio.[so|dylib|pyd]`, so we need something `torchaudio.foo`, that is
# interpreted as `torchaudio/foo.so` then use dirname to get the `torchaudio`
# directory.
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath("torchaudio.lib")))
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath("foo")))
# required for auto-detection of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
......
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