@@ -11,10 +11,29 @@ find_package(Python3 ${PYTHON_VERSION} EXACT COMPONENTS Development)
11
11
if (DEFINED TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR AND TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR)
12
12
set (TORCHCODEC_WERROR_OPTION "" )
13
13
else ()
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} " )
15
35
endif ()
16
36
17
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS} " )
18
37
19
38
function (make_torchcodec_sublibrary
20
39
library_name
@@ -34,11 +53,26 @@ function(make_torchcodec_sublibrary
34
53
# Avoid adding the "lib" prefix which we already add explicitly.
35
54
set_target_properties (${library_name} PROPERTIES PREFIX "" )
36
55
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
+
37
70
target_link_libraries (
38
71
${library_name}
39
72
PUBLIC
40
73
${library_dependencies}
41
74
)
75
+
42
76
endfunction ()
43
77
44
78
function (make_torchcodec_libraries
@@ -144,11 +178,14 @@ function(make_torchcodec_libraries
144
178
# stray initialization of py::objects. The rest of the object code must
145
179
# match. See:
146
180
# 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
+
152
189
# The value we use here must match the value we return from
153
190
# _get_pybind_ops_module_name() on the Python side. If the values do not
154
191
# match, then we will be unable to import the C++ shared library as a
@@ -158,14 +195,17 @@ function(make_torchcodec_libraries
158
195
PRIVATE
159
196
PYBIND_OPS_MODULE_NAME=core_pybind_ops
160
197
)
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 ()
169
209
170
210
# Install all libraries.
171
211
set (
@@ -183,7 +223,9 @@ function(make_torchcodec_libraries
183
223
install (
184
224
TARGETS ${all_libraries}
185
225
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
226
+ RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} # For Windows DLLs
186
227
)
228
+
187
229
endfunction ()
188
230
189
231
if (DEFINED ENV{BUILD_AGAINST_ALL_FFMPEG_FROM_S3})
0 commit comments