Debian Codegraph @

Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagCXX.cmake

raw
1
2 enable_language (CXX)
3 include(CheckCompilerFlag)
4
5 set(CXX 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(CXX "-_this_is_not_a_flag_" SHOULD_FAIL)
12 if(SHOULD_FAIL)
13 message(SEND_ERROR "invalid CXX compile flag didn't fail.")
14 endif()
15
16 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|LCC|Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
17 check_compiler_flag(CXX "-x c++" SHOULD_WORK)
18 if(NOT SHOULD_WORK)
19 message(SEND_ERROR "${CMAKE_CXX_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_CXX_FLAGS " -nostdinc++")
25 check_compiler_flag(CXX "-x c++" SHOULD_WORK_NOSTDINCXX)
26 if(NOT SHOULD_WORK_NOSTDINCXX)
27 message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++ -nostdinc++' check failed")
28 endif()
29 endblock()
30 endif()
31
32 if(NOT "$ENV{LC_ALL}" STREQUAL "BAD")
33 message(SEND_ERROR "ENV{LC_ALL} was not preserved by check_compiler_flag")
34 endif()
35 set(ENV{LC_ALL} ${_env_LC_ALL})