mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 19:30:13 -06:00
Tests: Refactor warn on error tests to support multiple languages
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
1
Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake
Normal file
1
Tests/RunCMake/CompileWarningAsError/WerrorOff_C.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(WerrorOff.cmake)
|
||||
1
Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake
Normal file
1
Tests/RunCMake/CompileWarningAsError/WerrorOff_CXX.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(WerrorOff.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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
include(WerrorOnIgnore.cmake)
|
||||
@@ -0,0 +1 @@
|
||||
include(WerrorOnIgnore.cmake)
|
||||
1
Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake
Normal file
1
Tests/RunCMake/CompileWarningAsError/WerrorOn_C.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(WerrorOn.cmake)
|
||||
@@ -0,0 +1 @@
|
||||
[^0]
|
||||
1
Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake
Normal file
1
Tests/RunCMake/CompileWarningAsError/WerrorOn_CXX.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(WerrorOn.cmake)
|
||||
0
Tests/RunCMake/CompileWarningAsError/err.c
Normal file
0
Tests/RunCMake/CompileWarningAsError/err.c
Normal file
25
Tests/RunCMake/CompileWarningAsError/warn.c
Normal file
25
Tests/RunCMake/CompileWarningAsError/warn.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user