@@ -65,6 +65,12 @@ function(make_torchcodec_sublibrary
6565 PUBLIC
6666 ${library_dependencies}
6767 )
68+
69+ # Debug output for Windows builds
70+ if (WIN32 )
71+ message (STATUS "Created library: ${library_name} " )
72+ message (STATUS "Library dependencies: ${library_dependencies} " )
73+ endif ()
6874endfunction ()
6975
7076function (make_torchcodec_libraries
@@ -198,6 +204,45 @@ function(make_torchcodec_libraries
198204 ${pybind_ops_library_name}
199205 )
200206
207+ # The install step is invoked within CMakeBuild.build_library() in
208+ # setup.py and just copies the built files from the temp
209+ # cmake/setuptools build folder into the CMAKE_INSTALL_PREFIX folder. We
210+ # still need to manually pass "DESTINATION ..." for cmake to copy those
211+ # files in CMAKE_INSTALL_PREFIX instead of CMAKE_INSTALL_PREFIX/lib.
212+ install (
213+ TARGETS ${all_libraries}
214+ LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
215+ RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} # For Windows DLLs
216+ ibrary to prevent
217+ # stray initialization of py::objects. The rest of the object code must
218+ # match. See:
219+ # https://pybind11.readthedocs.io/en/stable/faq.html#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclass-member-wattributes
220+ if (NOT WIN32 ) # TODO unify WIN detection
221+ target_compile_options (
222+ ${pybind_ops_library_name}
223+ PUBLIC
224+ "-fvisibility=hidden"
225+ )
226+ endif ()
227+ if (APPLE ) # TODO unify APPLE detection
228+ # If we don't make sure this flag is set, we run into segfauls at import
229+ # time on Mac. See:
230+ # https://github.com/pybind/pybind11/issues/3907#issuecomment-1170412764
231+ target_link_options (
232+ ${pybind_ops_library_name}
233+ PUBLIC
234+ "LINKER:-undefined,dynamic_lookup"
235+ )
236+ endif ()
237+
238+ # Install all libraries.
239+ set (
240+ all_libraries
241+ ${decoder_library_name}
242+ ${custom_ops_library_name}
243+ ${pybind_ops_library_name}
244+ )
245+
201246 # The install step is invoked within CMakeBuild.build_library() in
202247 # setup.py and just copies the built files from the temp
203248 # cmake/setuptools build folder into the CMAKE_INSTALL_PREFIX folder. We
@@ -246,6 +291,21 @@ else()
246291 libswscale
247292 )
248293
294+ # On Windows, explicitly add the conda library directory to the linker search path
295+ if (WIN32 AND DEFINED ENV{CONDA_PREFIX})
296+ link_directories ("$ENV{CONDA_PREFIX} /Library/lib" )
297+ message (STATUS "Added conda library directory to linker search path: $ENV{CONDA_PREFIX} /Library/lib" )
298+
299+ # Also add the library path to CMAKE_PREFIX_PATH for better library finding
300+ list (APPEND CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX} /Library" )
301+ message (STATUS "Added conda prefix to CMAKE_PREFIX_PATH: $ENV{CONDA_PREFIX} /Library" )
302+
303+ # Debug: Show what LIBAV variables are set
304+ message (STATUS "LIBAV_INCLUDE_DIRS: ${LIBAV_INCLUDE_DIRS} " )
305+ message (STATUS "LIBAV_LIBRARY_DIRS: ${LIBAV_LIBRARY_DIRS} " )
306+ message (STATUS "LIBAV_LIBRARIES: ${LIBAV_LIBRARIES} " )
307+ endif ()
308+
249309 # Split libavcodec's version string by '.' and convert it to a list
250310 string (REPLACE "." ";" libavcodec_version_list ${LIBAV_libavcodec_VERSION} )
251311 # Get the first element of the list, which is the major version
0 commit comments