CheckCompilerFlagC.cmake 1.0 KB

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