| 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 |
|
| 22 |
block() |
| 23 |
# Test tolerating a flag that is not used when driving the linker. |
| 24 |
string(APPEND CMAKE_C_FLAGS " -nostdinc") |
| 25 |
check_compiler_flag(C "-x c" SHOULD_WORK_NOSTDINC) |
| 26 |
if(NOT SHOULD_WORK_NOSTDINC) |
| 27 |
message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-x c -nostdinc' check failed") |
| 28 |
endif() |
| 29 |
endblock() |
| 30 |
endif() |
| 31 |
|
| 32 |
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") # LCC C compiler silently ignore -frtti instead of failing, so skip it here. |
| 33 |
check_compiler_flag(C "-frtti" SHOULD_FAIL_RTTI) |
| 34 |
if(SHOULD_FAIL_RTTI) |
| 35 |
message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-frtti' check passed but should have failed") |
| 36 |
endif() |
| 37 |
endif() |
| 38 |
|
| 39 |
if(NOT "$ENV{LC_ALL}" STREQUAL "BAD") |
| 40 |
message(SEND_ERROR "ENV{LC_ALL} was not preserved by check_compiler_flag") |
| 41 |
endif() |
| 42 |
set(ENV{LC_ALL} ${_env_LC_ALL}) |