diff --git a/CMakeLists.txt b/CMakeLists.txt index 343e74d2e8f..46b5dd0b69e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,7 @@ cmake_dependent_option( USE_DEPLOY "Build embedded torch::deploy interpreter. See torch/csrc/deploy/README.md for more info." OFF "BUILD_PYTHON" OFF) cmake_dependent_option(USE_CCACHE "Attempt using CCache to wrap the compilation" ON "UNIX" OFF) +option(WERROR "Build with -Werror supported by the compiler" OFF) if(USE_CCACHE) find_program(CCACHE_PROGRAM ccache) diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 212d6b26933..be30d5904d5 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -523,6 +523,9 @@ if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) append_filelist("libtorch_cmake_sources" LIBTORCH_CMAKE_SRCS) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # TODO: Delete this line once https://github.com/pytorch/pytorch/pull/55889 lands + set_source_files_properties(../torch/csrc/jit/serialization/export.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + # TODO: Delete this when https://github.com/pytorch/pytorch/issues/35026 is fixed set_source_files_properties(../torch/csrc/autograd/record_function_ops.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) endif() @@ -1743,6 +1746,11 @@ if(BUILD_PYTHON) endif() endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 in EmbeddingBag.cpp + set_source_files_properties(../aten/src/ATen/native/EmbeddingBag.cpp PROPERTIES COMPILE_FLAGS -Wno-attributes) + set_source_files_properties(${TORCH_SRC_DIR}/../caffe2/operators/box_with_nms_limit_op.cc PROPERTIES COMPILE_FLAGS -Wno-attributes) + endif() # Allow different install locations for libcaffe2 # For setuptools installs (that all build Python), install libcaffe2 into # site-packages, alongside the torch libraries. The pybind11 library needs diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 59a7be9a8be..81feda1ea41 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1461,6 +1461,10 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) caffe2_interface_library(onnx onnx_library) endif() list(APPEND Caffe2_DEPENDENCY_WHOLE_LINK_LIBS onnx_library) + # TODO: Delete this line once https://github.com/pytorch/pytorch/pull/55889 lands + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(onnx PRIVATE -Wno-deprecated-declarations) + endif() else() add_library(onnx SHARED IMPORTED) find_library(ONNX_LIBRARY onnx) diff --git a/setup.py b/setup.py index 1bfb7a749e7..d29a6c3cb96 100644 --- a/setup.py +++ b/setup.py @@ -211,7 +211,7 @@ import sysconfig from tools.build_pytorch_libs import build_caffe2 from tools.setup_helpers.env import (IS_WINDOWS, IS_DARWIN, IS_LINUX, - check_env_flag, build_type) + build_type) from tools.setup_helpers.cmake import CMake from tools.generate_torch_version import get_torch_version @@ -731,8 +731,6 @@ def configure_extension_build(): # https://bugs.llvm.org/show_bug.cgi?id=21629 '-Wno-missing-braces', ] - if check_env_flag('WERROR'): - extra_compile_args.append('-Werror') library_dirs.append(lib_path) diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index ace335b89a0..71b163b0a8d 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -255,6 +255,11 @@ if(USE_NUMPY) list(APPEND TORCH_PYTHON_COMPILE_DEFINITIONS USE_NUMPY) endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 in EmbeddingBag.cpp + set_source_files_properties(${TORCH_SRC_DIR}/csrc/utils/throughput_benchmark.cpp PROPERTIES COMPILE_FLAGS -Wno-attributes) +endif() + if(USE_DISTRIBUTED) list(APPEND TORCH_PYTHON_COMPILE_DEFINITIONS USE_DISTRIBUTED) if(WIN32) diff --git a/torch/lib/c10d/CMakeLists.txt b/torch/lib/c10d/CMakeLists.txt index 4e8fc426fa9..3c11526f0c3 100644 --- a/torch/lib/c10d/CMakeLists.txt +++ b/torch/lib/c10d/CMakeLists.txt @@ -67,6 +67,9 @@ endif() if(USE_C10D_MPI) list(APPEND C10D_SRCS ProcessGroupMPI.cpp) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_source_files_properties(ProcessGroupMPI.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + endif() list(APPEND C10D_LIBS ${MPI_LIBRARIES}) endif()