CheckCompilerFlagCXX.cmake 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. enable_language (CXX)
  2. include(CheckCompilerFlag)
  3. set(CXX 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(CXX "-_this_is_not_a_flag_" SHOULD_FAIL)
  8. if(SHOULD_FAIL)
  9. message(SEND_ERROR "invalid CXX compile flag didn't fail.")
  10. endif()
  11. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|LCC|Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
  12. check_compiler_flag(CXX "-x c++" SHOULD_WORK)
  13. if(NOT SHOULD_WORK)
  14. message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed")
  15. endif()
  16. block()
  17. # Test tolerating a flag that is not used when driving the linker.
  18. string(APPEND CMAKE_CXX_FLAGS " -nostdinc++")
  19. check_compiler_flag(CXX "-x c++" SHOULD_WORK_NOSTDINCXX)
  20. if(NOT SHOULD_WORK_NOSTDINCXX)
  21. message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++ -nostdinc++' check failed")
  22. endif()
  23. endblock()
  24. endif()
  25. if(NOT "$ENV{LC_ALL}" STREQUAL "BAD")
  26. message(SEND_ERROR "ENV{LC_ALL} was not preserved by check_compiler_flag")
  27. endif()
  28. set(ENV{LC_ALL} ${_env_LC_ALL})