mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Pass WERROR to CMake as an explicit parameter rather than an env var.
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/16465 Differential Revision: D13853949 Pulled By: resistor fbshipit-source-id: 71ccf90a2824ad21c9f26dd753b186f30435d82a
This commit is contained in:
committed by
Facebook Github Bot
parent
99fab45733
commit
f204e3e624
@ -278,9 +278,14 @@ if(NOT MSVC)
|
||||
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND NOT APPLE)))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")
|
||||
endif()
|
||||
if ($ENV{WERROR})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
endif($ENV{WERROR})
|
||||
if (WERROR)
|
||||
check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
|
||||
if (NOT COMPILER_SUPPORT_WERROR)
|
||||
set(WERROR FALSE)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
endif()
|
||||
endif(WERROR)
|
||||
if (NOT APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
|
||||
|
@ -418,7 +418,7 @@ if(USE_ROCM)
|
||||
endif()
|
||||
|
||||
# ---[ Check if warnings should be errors.
|
||||
if ($ENV{WERROR})
|
||||
if (WERROR)
|
||||
target_compile_options(caffe2 PRIVATE -Werror)
|
||||
if(USE_CUDA)
|
||||
target_compile_options(caffe2_gpu PRIVATE -Werror)
|
||||
|
@ -57,67 +57,6 @@ set(Caffe2_HIP_TEST_SRCS ${Caffe2_HIP_TEST_SRCS}
|
||||
utils/hip/math_blas_gpu_test.cc
|
||||
)
|
||||
|
||||
# TODO Remove the CMake_xxx variables above and add them to the variables for the local library target below instead
|
||||
|
||||
set(LIB_SOURCES_CPU
|
||||
dummy.cpp
|
||||
)
|
||||
|
||||
set(LIB_SOURCES_GPU
|
||||
dummy.cpp
|
||||
)
|
||||
|
||||
set(LIB_SOURCES_HIP
|
||||
dummy.cpp
|
||||
)
|
||||
|
||||
set(TEST_SOURCES_CPU
|
||||
)
|
||||
|
||||
set(LIB_SOURCES_GPU
|
||||
dummy.cpp
|
||||
)
|
||||
|
||||
set(TEST_SOURCES_HIP
|
||||
dummy.cpp
|
||||
)
|
||||
|
||||
add_library(c10_utils_cpu OBJECT ${LIB_SOURCES_CPU})
|
||||
target_enable_style_warnings("c10_utils_cpu")
|
||||
|
||||
add_library(c10_utils_gpu OBJECT ${LIB_SOURCES_GPU})
|
||||
target_enable_style_warnings("c10_utils_gpu")
|
||||
|
||||
add_library(c10_utils_hip OBJECT ${LIB_SOURCES_HIP})
|
||||
target_enable_style_warnings("c10_utils_hip")
|
||||
|
||||
if(BUILD_TEST)
|
||||
add_executable(c10_utils_cpu_test ${TEST_SOURCES_CPU} $<TARGET_OBJECTS:c10_utils_cpu>)
|
||||
add_test(NAME c10_utils_cpu_test COMMAND $<TARGET_FILE:c10_utils_cpu_test>)
|
||||
target_enable_style_warnings(c10_utils_cpu_test)
|
||||
target_link_libraries(c10_utils_cpu_test gtest_main)
|
||||
if(INSTALL_TEST)
|
||||
install(TARGETS c10_utils_cpu_test DESTINATION test)
|
||||
endif()
|
||||
|
||||
add_executable(c10_utils_gpu_test ${TEST_SOURCES_GPU} $<TARGET_OBJECTS:c10_utils_gpu>)
|
||||
add_test(NAME c10_utils_gpu_test COMMAND $<TARGET_FILE:c10_utils_gpu_test>)
|
||||
target_enable_style_warnings(c10_utils_gpu_test)
|
||||
target_link_libraries(c10_utils_gpu_test gtest_main)
|
||||
if(INSTALL_TEST)
|
||||
install(TARGETS c10_utils_gpu_test DESTINATION test)
|
||||
endif()
|
||||
|
||||
add_executable(c10_utils_hip_test ${TEST_SOURCES_HIP} $<TARGET_OBJECTS:c10_utils_hip>)
|
||||
add_test(NAME c10_utils_hip_test COMMAND $<TARGET_FILE:c10_utils_hip_test>)
|
||||
target_enable_style_warnings(c10_utils_hip_test)
|
||||
target_link_libraries(c10_utils_hip_test gtest_main)
|
||||
if(INSTALL_TEST)
|
||||
install(TARGETS c10_utils_hip_test DESTINATION test)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# TODO Once all source files are defined inside the local c10_utils_xxx targets,
|
||||
# it should be the job of the parent CMakeLists.txt to decide what to do with the target (i.e. link it to caffe2)
|
||||
# instead of us locally adding it to Caffe2_xxx variables.
|
||||
|
@ -238,59 +238,3 @@ function(print_target_properties tgt)
|
||||
endif()
|
||||
endforeach(prop)
|
||||
endfunction(print_target_properties)
|
||||
|
||||
|
||||
###
|
||||
# Helper function to add style warning options to the given target
|
||||
# Optionally pass in the second argument ($ARGV1) which will force -Werror if
|
||||
# it evaluates to true.
|
||||
function(target_enable_style_warnings TARGET)
|
||||
if(MSVC)
|
||||
# TODO Also add some warning options that MSVC can understand
|
||||
set(WARNING_OPTIONS "")
|
||||
else()
|
||||
set(WARNING_OPTIONS
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wold-style-cast
|
||||
-Wno-missing-braces
|
||||
-Wcast-align
|
||||
-Wcast-qual
|
||||
-Wctor-dtor-privacy
|
||||
-Wdisabled-optimization
|
||||
-Wformat=2
|
||||
-Winit-self
|
||||
-Wmissing-include-dirs
|
||||
-Woverloaded-virtual
|
||||
-Wredundant-decls
|
||||
-Wno-shadow
|
||||
-Wsign-promo
|
||||
-Wno-strict-overflow
|
||||
-fdiagnostics-show-option
|
||||
-Wno-conversion
|
||||
-Wpedantic
|
||||
-Wundef
|
||||
)
|
||||
# -Wno-gnu-zero-variadic-macro-arguments is not available in GCC-4.8.5. Set
|
||||
# only when using clang.
|
||||
# Compared against https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Option-Summary.html
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
list(APPEND WARNING_OPTIONS "-Wno-gnu-zero-variadic-macro-arguments")
|
||||
endif()
|
||||
set(WERROR $ENV{WERROR})
|
||||
if (${ARGC} GREATER 1)
|
||||
# accessing ${ARGV1} is UB when ${ARGC} <= 1
|
||||
# CMake doesn't do smart AND, so we have to use a nested `if`
|
||||
if (${ARGV1})
|
||||
set(WERROR TRUE)
|
||||
endif()
|
||||
endif()
|
||||
if (WERROR)
|
||||
list(APPEND WARNING_OPTIONS "-Werror")
|
||||
endif()
|
||||
endif()
|
||||
if(APPLE)
|
||||
set(WARNING_OPTIONS -Wno-gnu-zero-variadic-macro-arguments)
|
||||
endif()
|
||||
target_compile_options(${TARGET} PRIVATE ${WARNING_OPTIONS})
|
||||
endfunction()
|
||||
|
@ -202,7 +202,7 @@ function(torch_compile_options libname)
|
||||
-Wno-unused-parameter
|
||||
-Wno-unknown-warning-option
|
||||
-Wno-unknown-pragmas)
|
||||
if ($ENV{WERROR})
|
||||
if (WERROR)
|
||||
target_compile_options(${libname} PRIVATE -Werror)
|
||||
endif()
|
||||
endfunction()
|
||||
|
@ -185,7 +185,8 @@ def run_cmake(version,
|
||||
CUDA_NVCC_EXECUTABLE=escape_path(os.getenv('CUDA_NVCC_EXECUTABLE')),
|
||||
USE_REDIS=os.getenv('USE_REDIS'),
|
||||
USE_GLOG=os.getenv('USE_GLOG'),
|
||||
USE_GFLAGS=os.getenv('USE_GFLAGS'))
|
||||
USE_GFLAGS=os.getenv('USE_GFLAGS'),
|
||||
WERROR=os.getenv('WERROR'))
|
||||
|
||||
if USE_GLOO_IBVERBS:
|
||||
cmake_defines(cmake_args, USE_IBVERBS="1", USE_GLOO_IBVERBS="1")
|
||||
|
@ -326,7 +326,7 @@ else()
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
elseif ($ENV{WERROR})
|
||||
elseif (WERROR)
|
||||
target_compile_options(torch PRIVATE -Werror -Wno-strict-overflow)
|
||||
endif()
|
||||
|
||||
|
Reference in New Issue
Block a user