Skip to content

Commit ed13ac5

Browse files
Add TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR environment variable to disable -Werror compilation option (#656)
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
1 parent 0673a4a commit ed13ac5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

setup.py

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def _build_all_extensions_with_cmake(self):
112112
torch_dir = Path(torch.utils.cmake_prefix_path) / "Torch"
113113
cmake_build_type = os.environ.get("CMAKE_BUILD_TYPE", "Release")
114114
enable_cuda = os.environ.get("ENABLE_CUDA", "")
115+
torchcodec_disable_compile_warning_as_error = os.environ.get(
116+
"TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR", "OFF"
117+
)
115118
python_version = sys.version_info
116119
cmake_args = [
117120
f"-DCMAKE_INSTALL_PREFIX={self._install_prefix}",
@@ -120,6 +123,7 @@ def _build_all_extensions_with_cmake(self):
120123
f"-DCMAKE_BUILD_TYPE={cmake_build_type}",
121124
f"-DPYTHON_VERSION={python_version.major}.{python_version.minor}",
122125
f"-DENABLE_CUDA={enable_cuda}",
126+
f"-DTORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR={torchcodec_disable_compile_warning_as_error}",
123127
]
124128

125129
Path(self.build_temp).mkdir(parents=True, exist_ok=True)

src/torchcodec/_core/CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ find_package(pybind11 REQUIRED)
88
find_package(Torch REQUIRED)
99
find_package(Python3 ${PYTHON_VERSION} EXACT COMPONENTS Development)
1010

11-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror ${TORCH_CXX_FLAGS}")
11+
if(DEFINED TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR AND TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR)
12+
set(TORCHCODEC_WERROR_OPTION "")
13+
else()
14+
set(TORCHCODEC_WERROR_OPTION "-Werror")
15+
endif()
16+
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic ${TORCHCODEC_WERROR_OPTION} ${TORCH_CXX_FLAGS}")
1218

1319
function(make_torchcodec_sublibrary
1420
library_name

0 commit comments

Comments
 (0)