@@ -11,10 +11,29 @@ find_package(Python3 ${PYTHON_VERSION} EXACT COMPONENTS Development)
1111if (DEFINED TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR AND TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR)
1212 set (TORCHCODEC_WERROR_OPTION "" )
1313else ()
14- set (TORCHCODEC_WERROR_OPTION "-Werror" )
14+ if (WIN32 )
15+ # TODO set warnings as errors on Windows as well.
16+ # set(TORCHCODEC_WERROR_OPTION "/WX")
17+ else ()
18+ set (TORCHCODEC_WERROR_OPTION "-Werror" )
19+ endif ()
20+ endif ()
21+
22+ if (WIN32 )
23+ # Avoid warnings about non-ASCII characters in source files.
24+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819" )
25+ # Important for when we add Windows CUDA: exporting all symbols is limited to
26+ # 65535 symbols, which (apparently) will not work for CUDA.
27+ # https://github.com/pytorch/pytorch/pull/3650
28+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
29+ endif ()
30+
31+ if (WIN32 )
32+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS} " )
33+ else ()
34+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS} " )
1535endif ()
1636
17- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS} " )
1837
1938function (make_torchcodec_sublibrary
2039 library_name
@@ -34,11 +53,26 @@ function(make_torchcodec_sublibrary
3453 # Avoid adding the "lib" prefix which we already add explicitly.
3554 set_target_properties (${library_name} PROPERTIES PREFIX "" )
3655
56+ if (WIN32 )
57+ # On Windows, the built artifacts are put in Release/Debug
58+ # subdirectories by default. We want to avoid that, otherwise our
59+ # install() step would not know where to find those.
60+ set_target_properties (${library_name} PROPERTIES
61+ RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}
62+ RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}
63+ LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}
64+ LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}
65+ ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}
66+ ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}
67+ )
68+ endif ()
69+
3770 target_link_libraries (
3871 ${library_name}
3972 PUBLIC
4073 ${library_dependencies}
4174 )
75+
4276endfunction ()
4377
4478function (make_torchcodec_libraries
@@ -144,11 +178,14 @@ function(make_torchcodec_libraries
144178 # stray initialization of py::objects. The rest of the object code must
145179 # match. See:
146180 # https://pybind11.readthedocs.io/en/stable/faq.html#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclass-member-wattributes
147- target_compile_options (
148- ${pybind_ops_library_name}
149- PUBLIC
150- "-fvisibility=hidden"
151- )
181+ if (NOT WIN32 )
182+ target_compile_options (
183+ ${pybind_ops_library_name}
184+ PUBLIC
185+ "-fvisibility=hidden"
186+ )
187+ endif ()
188+
152189 # The value we use here must match the value we return from
153190 # _get_pybind_ops_module_name() on the Python side. If the values do not
154191 # match, then we will be unable to import the C++ shared library as a
@@ -158,14 +195,17 @@ function(make_torchcodec_libraries
158195 PRIVATE
159196 PYBIND_OPS_MODULE_NAME=core_pybind_ops
160197 )
161- # If we don't make sure this flag is set, we run into segfauls at import
162- # time on Mac. See:
163- # https://github.com/pybind/pybind11/issues/3907#issuecomment-1170412764
164- target_link_options (
165- ${pybind_ops_library_name}
166- PUBLIC
167- "LINKER:-undefined,dynamic_lookup"
168- )
198+
199+ if (APPLE )
200+ # If we don't make sure this flag is set, we run into segfauls at import
201+ # time on Mac. See:
202+ # https://github.com/pybind/pybind11/issues/3907#issuecomment-1170412764
203+ target_link_options (
204+ ${pybind_ops_library_name}
205+ PUBLIC
206+ "LINKER:-undefined,dynamic_lookup"
207+ )
208+ endif ()
169209
170210 # Install all libraries.
171211 set (
@@ -183,7 +223,9 @@ function(make_torchcodec_libraries
183223 install (
184224 TARGETS ${all_libraries}
185225 LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
226+ RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} # For Windows DLLs
186227 )
228+
187229endfunction ()
188230
189231if (DEFINED ENV{BUILD_AGAINST_ALL_FFMPEG_FROM_S3})
0 commit comments