From 2e9ac1d2726c4f260efd6b455242ec5d65391e12 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 28 Jun 2022 09:49:36 -0400 Subject: Tests: Refactor warn on error tests to support multiple languages --- .../CompileWarningAsError/RunCMakeTest.cmake | 19 ++++++++++------ .../WarningAsErrorOptions.cmake | 22 +++++++++++-------- .../RunCMake/CompileWarningAsError/WerrorOff.cmake | 6 +++--- .../CompileWarningAsError/WerrorOff_C.cmake | 1 + .../CompileWarningAsError/WerrorOff_CXX.cmake | 1 + .../WerrorOn-Build-result.txt | 1 - .../RunCMake/CompileWarningAsError/WerrorOn.cmake | 10 ++++----- .../CompileWarningAsError/WerrorOnIgnore.cmake | 6 +++--- .../CompileWarningAsError/WerrorOnIgnore_C.cmake | 1 + .../CompileWarningAsError/WerrorOnIgnore_CXX.cmake | 1 + .../WerrorOn_C-Build-result.txt | 1 + .../CompileWarningAsError/WerrorOn_C.cmake | 1 + .../WerrorOn_CXX-Build-result.txt | 1 + .../CompileWarningAsError/WerrorOn_CXX.cmake | 1 + Tests/RunCMake/CompileWarningAsError/err.c | 0 Tests/RunCMake/CompileWarningAsError/warn.c | 25 ++++++++++++++++++++++ Tests/RunCMake/CompileWarningAsError/warn.cxx | 18 +--------------- 17 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake delete mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_C.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CXX.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_C-Build-result.txt create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX-Build-result.txt create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/err.c create mode 100644 Tests/RunCMake/CompileWarningAsError/warn.c diff --git a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake index a532f72..b068c18 100644 --- a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake @@ -1,13 +1,18 @@ 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) + +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() diff --git a/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake index ccc6cc5..b5b981c 100644 --- a/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake +++ b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake @@ -1,18 +1,22 @@ # 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)$") 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 "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() diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake index b05d65e..0af60f0 100644 --- a/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake @@ -1,8 +1,8 @@ -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) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake new file mode 100644 index 0000000..35c02aa --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake @@ -0,0 +1 @@ +include(WerrorOff.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake new file mode 100644 index 0000000..35c02aa --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake @@ -0,0 +1 @@ +include(WerrorOff.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt b/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt deleted file mode 100644 index d197c91..0000000 --- a/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt +++ /dev/null @@ -1 +0,0 @@ -[^0] diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake index 4310333..c3f6526 100644 --- a/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake @@ -1,13 +1,13 @@ -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() diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake index 1f7ccdb..847bd78 100644 --- a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake @@ -1,8 +1,8 @@ -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) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_C.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_C.cmake new file mode 100644 index 0000000..ebb9e0e --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_C.cmake @@ -0,0 +1 @@ +include(WerrorOnIgnore.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CXX.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CXX.cmake new file mode 100644 index 0000000..ebb9e0e --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CXX.cmake @@ -0,0 +1 @@ +include(WerrorOnIgnore.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_C-Build-result.txt b/Tests/RunCMake/CompileWarningAsError/WerrorOn_C-Build-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_C-Build-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake new file mode 100644 index 0000000..a00edb8 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake @@ -0,0 +1 @@ +include(WerrorOn.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX-Build-result.txt b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX-Build-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX-Build-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake new file mode 100644 index 0000000..a00edb8 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake @@ -0,0 +1 @@ +include(WerrorOn.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/err.c b/Tests/RunCMake/CompileWarningAsError/err.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CompileWarningAsError/warn.c b/Tests/RunCMake/CompileWarningAsError/warn.c new file mode 100644 index 0000000..cd0c2ba --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/warn.c @@ -0,0 +1,25 @@ +static void unused_function(); + +#ifdef __SUNPRO_C +KandR(x) int x; +{ + return x; +} +#endif + +#ifdef __SUNPRO_CC +struct A +{ + virtual ~A() throw(); +}; +struct B : public A +{ + virtual ~B() throw(int); +}; +#endif + +int main(int argc, char* argv[]) +{ + unsigned int unused_sign_conversion = -1; + return 1; +} diff --git a/Tests/RunCMake/CompileWarningAsError/warn.cxx b/Tests/RunCMake/CompileWarningAsError/warn.cxx index 64a245a..22b8db8 100644 --- a/Tests/RunCMake/CompileWarningAsError/warn.cxx +++ b/Tests/RunCMake/CompileWarningAsError/warn.cxx @@ -1,17 +1 @@ -static void unused_function(); - -#ifdef __SUNPRO_CC -struct A -{ - virtual ~A() throw(); -}; -struct B : public A -{ - virtual ~B() throw(int); -}; -#endif - -int main(int unused_argument, char* []) -{ - return 1; -} +#include "warn.c" -- cgit v0.12 From cd324110d2ecef8dd955f7089382d15708cad98d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 27 Jun 2022 14:42:46 -0400 Subject: CUDA: NVCC support for COMPILE_WARNING_AS_ERROR target property --- Modules/Compiler/NVIDIA-CUDA.cmake | 5 +++++ Tests/RunCMake/CMakeLists.txt | 3 ++- Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake | 4 ++++ Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake | 7 +++++++ Tests/RunCMake/CompileWarningAsError/WerrorOff_CUDA.cmake | 1 + Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CUDA.cmake | 1 + .../RunCMake/CompileWarningAsError/WerrorOn_CUDA-Build-result.txt | 1 + Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA.cmake | 1 + Tests/RunCMake/CompileWarningAsError/err.cu | 0 Tests/RunCMake/CompileWarningAsError/warn.cu | 1 + 10 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOff_CUDA.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CUDA.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA-Build-result.txt create mode 100644 Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA.cmake create mode 100644 Tests/RunCMake/CompileWarningAsError/err.cu create mode 100644 Tests/RunCMake/CompileWarningAsError/warn.cu diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index 2f12b43..2e3ae2c 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -30,6 +30,11 @@ if(CMAKE_CUDA_HOST_COMPILER AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") 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 # to get header dependency information diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 5325a3a..69def6d 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake index b068c18..392c921 100644 --- a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake @@ -10,6 +10,10 @@ endfunction() 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}) diff --git a/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake index b5b981c..590c8a4 100644 --- a/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake +++ b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake @@ -6,6 +6,13 @@ macro(get_warning_options warning_options lang) 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_${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_${lang}_COMPILER_ID STREQUAL "XL") diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOff_CUDA.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOff_CUDA.cmake new file mode 100644 index 0000000..35c02aa --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOff_CUDA.cmake @@ -0,0 +1 @@ +include(WerrorOff.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CUDA.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CUDA.cmake new file mode 100644 index 0000000..ebb9e0e --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore_CUDA.cmake @@ -0,0 +1 @@ +include(WerrorOnIgnore.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA-Build-result.txt b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA-Build-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA-Build-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA.cmake new file mode 100644 index 0000000..a00edb8 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn_CUDA.cmake @@ -0,0 +1 @@ +include(WerrorOn.cmake) diff --git a/Tests/RunCMake/CompileWarningAsError/err.cu b/Tests/RunCMake/CompileWarningAsError/err.cu new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CompileWarningAsError/warn.cu b/Tests/RunCMake/CompileWarningAsError/warn.cu new file mode 100644 index 0000000..22b8db8 --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/warn.cu @@ -0,0 +1 @@ +#include "warn.c" -- cgit v0.12