WCDH: Make the header -Wundef safe for the C language.

The __STDC_VERSION__ macro may be defined or not depending on the
implementation dialect of C.  Test that it is defined before testing
its value.

The CXX tests do not need such a change because they define __cplusplus
in all dialects.
This commit is contained in:
Stephen Kelly
2014-11-24 21:47:48 +01:00
parent 598a316154
commit d0af0faefb
4 changed files with 18 additions and 4 deletions

View File

@@ -63,6 +63,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL GNU
list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
endif()
if (CMAKE_C_COMPILER_ID STREQUAL GNU
OR CMAKE_C_COMPILER_ID STREQUAL Clang)
add_executable(C_undefined c_undefined.c)
set_property(TARGET C_undefined PROPERTY CXX_STANDARD 90)
target_compile_options(C_undefined PRIVATE -Werror=undef)
endif()
add_executable(WriteCompilerDetectionHeader main.cpp)
set_property(TARGET WriteCompilerDetectionHeader PROPERTY CXX_STANDARD 98)
set_defines(WriteCompilerDetectionHeader "${true_defs}" "${false_defs}")

View File

@@ -0,0 +1,7 @@
#include "test_compiler_detection.h"
int main()
{
return 0;
}