Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / RunCMake / CheckCompilerFlag / CheckCompilerFlagC.cmake
1
2 enable_language (C)
3 include(CheckCompilerFlag)
4
5 set(C 1) # test that this is tolerated
6
7 # test that the check uses an isolated locale
8 set(_env_LC_ALL "${LC_ALL}")
9 set(ENV{LC_ALL} "BAD")
10
11 check_compiler_flag(C "-_this_is_not_a_flag_" SHOULD_FAIL)
12 if(SHOULD_FAIL)
13   message(SEND_ERROR "invalid C compile flag didn't fail.")
14 endif()
15
16 if(CMAKE_C_COMPILER_ID MATCHES "GNU|LCC|Clang" AND NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
17   check_compiler_flag(C "-x c" SHOULD_WORK)
18   if(NOT SHOULD_WORK)
19     message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-x c' check failed")
20   endif()
21 endif()
22
23 if(CMAKE_C_COMPILER_ID STREQUAL "GNU") # LCC C compiler silently ignore -frtti instead of failing, so skip it here.
24   check_compiler_flag(C "-frtti" SHOULD_FAIL_RTTI)
25   if(SHOULD_FAIL_RTTI)
26     message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-frtti' check passed but should have failed")
27   endif()
28 endif()
29
30 if(NOT "$ENV{LC_ALL}" STREQUAL "BAD")
31   message(SEND_ERROR "ENV{LC_ALL} was not preserved by check_compiler_flag")
32 endif()
33 set(ENV{LC_ALL} ${_env_LC_ALL})