Commit cd7ce080 authored by Brad King's avatar Brad King 💬 Committed by Kitware Robot
Browse files

Stage topic 'nvhpc-Werror'

Topic-id: 7415
Topic-url: cmake/cmake!7415
parents 305a6c6f 35ec676a
Pipeline #288099 failed with stages
in 79 minutes and 47 seconds
......@@ -13,5 +13,5 @@ include(Compiler/PGI)
macro(__compiler_nvhpc lang)
# Logic specific to NVHPC.
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "--Werror all-warnings")
set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror all-warnings")
endmacro()
......@@ -29,6 +29,11 @@ if(CMAKE_CUDA_HOST_COMPILER AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
string(APPEND _CMAKE_CUDA_EXTRA_FLAGS " -ccbin=<CMAKE_CUDA_HOST_COMPILER>")
endif()
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89)
# Starting in 10.2, nvcc supported treating all warnings as errors
set(CMAKE_CUDA_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror all-warnings")
endif()
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89)
# The -MD flag was only added to nvcc in 10.2 so
# before that we had to invoke the compiler twice
......
......@@ -372,7 +372,8 @@ add_RunCMake_test(TargetProperties)
add_RunCMake_test(ToolchainFile)
add_RunCMake_test(find_dependency)
add_RunCMake_test(CompileDefinitions)
add_RunCMake_test(CompileWarningAsError)
add_RunCMake_test(CompileWarningAsError -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
set_property(TEST RunCMake.CompileWarningAsError APPEND PROPERTY LABELS "CUDA")
add_RunCMake_test(CompileFeatures -DCMake_NO_C_STANDARD=${CMake_NO_C_STANDARD} -DCMake_NO_CXX_STANDARD=${CMake_NO_CXX_STANDARD})
add_RunCMake_test(Policy)
add_RunCMake_test(PolicyScope)
......
include(RunCMake)
function(run_compile_warn test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
function(run_compile_warn test lang extension)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}_${lang}-build)
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_with_options(${test} ${ARGN})
run_cmake_with_options(${test}_${lang} "-DLANGUAGE=${lang}" "-DEXTENSION=${extension}" ${ARGN})
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${test}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
run_cmake_command(${test}_${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction()
run_compile_warn(WerrorOn)
run_compile_warn(WerrorOff)
run_compile_warn(WerrorOnIgnore "--compile-no-warning-as-error")
set(langs C CXX)
set(exts c cxx)
if(CMake_TEST_CUDA)
list(APPEND langs CUDA)
list(APPEND exts cu)
endif()
foreach(lang ext IN ZIP_LISTS langs exts)
run_compile_warn(WerrorOn ${lang} ${ext})
run_compile_warn(WerrorOff ${lang} ${ext})
run_compile_warn(WerrorOnIgnore ${lang} ${ext} "--compile-no-warning-as-error")
endforeach()
# add compile options to warning_options to ensure unused-function throws a warning
# if warning_options is NOT DEFINED, assume compiler doesn't support warning as error
macro(get_warning_options warning_options)
if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|XLClang|IBMClang|LCC|NVCC|IntelLLVM)$")
macro(get_warning_options warning_options lang)
if (CMAKE_${lang}_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|XLClang|IBMClang|LCC|IntelLLVM|NVHPC)$")
set(${warning_options} "-Wall")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC"))
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "MSVC"
OR (CMAKE_${lang}_COMPILER_ID STREQUAL "Intel" AND CMAKE_${lang}_SIMULATE_ID MATCHES "MSVC"))
set(${warning_options} "-W4")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA"
AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89)
if(CMAKE_${lang}_SIMULATE_ID MATCHES "MSVC")
set(${warning_options} "-Xcompiler=-W4")
else()
set(${warning_options} "-Xcompiler=-Wall")
endif()
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "Intel")
set(${warning_options} "-w3")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "XL")
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "XL")
set(${warning_options} "-qinfo=all")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
set(${warning_options} "+w;+w2")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Fujitsu")
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "SunPro")
if(lang STREQUAL CXX)
set(${warning_options} "+w;+w2")
else()
set(${warning_options} "")
endif()
elseif (CMAKE_${lang}_COMPILER_ID STREQUAL "Fujitsu")
set(${warning_options} "SHELL:-w 8")
endif()
endmacro()
enable_language(CXX)
enable_language(${LANGUAGE})
include(WarningAsErrorOptions.cmake)
get_warning_options(warning_options)
get_warning_options(warning_options ${LANGUAGE})
add_executable(WerrorOff warn.cxx)
add_executable(WerrorOff warn.${EXTENSION})
target_compile_options(WerrorOff PUBLIC "${warning_options}")
set_target_properties(WerrorOff PROPERTIES COMPILE_WARNING_AS_ERROR OFF)
enable_language(CXX)
enable_language(${LANGUAGE})
include(WarningAsErrorOptions.cmake)
get_warning_options(warning_options)
get_warning_options(warning_options ${LANGUAGE})
if (DEFINED warning_options)
add_executable(WerrorOn warn.cxx)
add_executable(WerrorOn warn.${EXTENSION})
target_compile_options(WerrorOn PUBLIC "${warning_options}")
set_target_properties(WerrorOn PROPERTIES COMPILE_WARNING_AS_ERROR ON)
else()
# if no werror option is set for the environment, use err.cxx so that build fails as expected
add_executable(WerrorOn err.cxx)
# if no werror option is set for the environment, use err so that build fails as expected
add_executable(WerrorOn err.${EXTENSION})
endif()
enable_language(CXX)
enable_language(${LANGUAGE})
include(WarningAsErrorOptions.cmake)
get_warning_options(warning_options)
get_warning_options(warning_options ${LANGUAGE})
add_executable(WerrorOn warn.cxx)
add_executable(WerrorOn warn.${EXTENSION})
target_compile_options(WerrorOn PUBLIC "${warning_options}")
set_target_properties(WerrorOn PROPERTIES COMPILE_WARNING_AS_ERROR ON)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment